initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / net / sk98lin / skge.c
blob6cb5342a40acdc6a0463338c4bd6b85b8d3036d1
1 /******************************************************************************
3 * Name: skge.c
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.45 $
6 * Date: $Date: 2004/02/12 14:41:02 $
7 * Purpose: The main driver source module
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
14 * (C)Copyright 2002-2003 Marvell.
16 * Driver for Marvell Yukon chipset and SysKonnect Gigabit Ethernet
17 * Server Adapters.
19 * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
20 * SysKonnects GEnesis Solaris driver
21 * Author: Christoph Goos (cgoos@syskonnect.de)
22 * Mirko Lindner (mlindner@syskonnect.de)
24 * Address all question to: linux@syskonnect.de
26 * The technical manual for the adapters is available from SysKonnect's
27 * web pages: www.syskonnect.com
28 * Goto "Support" and search Knowledge Base for "manual".
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
35 * The information in this file is provided "AS IS" without warranty.
37 ******************************************************************************/
39 /******************************************************************************
41 * Possible compiler options (#define xxx / -Dxxx):
43 * debugging can be enable by changing SK_DEBUG_CHKMOD and
44 * SK_DEBUG_CHKCAT in makefile (described there).
46 ******************************************************************************/
48 /******************************************************************************
50 * Description:
52 * This is the main module of the Linux GE driver.
54 * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
55 * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
56 * Those are used for drivers on multiple OS', so some thing may seem
57 * unnecessary complicated on Linux. Please do not try to 'clean up'
58 * them without VERY good reasons, because this will make it more
59 * difficult to keep the Linux driver in synchronisation with the
60 * other versions.
62 * Include file hierarchy:
64 * <linux/module.h>
66 * "h/skdrv1st.h"
67 * <linux/types.h>
68 * <linux/kernel.h>
69 * <linux/string.h>
70 * <linux/errno.h>
71 * <linux/ioport.h>
72 * <linux/slab.h>
73 * <linux/interrupt.h>
74 * <linux/pci.h>
75 * <asm/byteorder.h>
76 * <asm/bitops.h>
77 * <asm/io.h>
78 * <linux/netdevice.h>
79 * <linux/etherdevice.h>
80 * <linux/skbuff.h>
81 * those three depending on kernel version used:
82 * <linux/bios32.h>
83 * <linux/init.h>
84 * <asm/uaccess.h>
85 * <net/checksum.h>
87 * "h/skerror.h"
88 * "h/skdebug.h"
89 * "h/sktypes.h"
90 * "h/lm80.h"
91 * "h/xmac_ii.h"
93 * "h/skdrv2nd.h"
94 * "h/skqueue.h"
95 * "h/skgehwt.h"
96 * "h/sktimer.h"
97 * "h/ski2c.h"
98 * "h/skgepnmi.h"
99 * "h/skvpd.h"
100 * "h/skgehw.h"
101 * "h/skgeinit.h"
102 * "h/skaddr.h"
103 * "h/skgesirq.h"
104 * "h/skcsum.h"
105 * "h/skrlmt.h"
107 ******************************************************************************/
109 #include "h/skversion.h"
111 #include <linux/module.h>
112 #include <linux/init.h>
113 #include <linux/proc_fs.h>
115 #include "h/skdrv1st.h"
116 #include "h/skdrv2nd.h"
118 /*******************************************************************************
120 * Defines
122 ******************************************************************************/
124 /* for debuging on x86 only */
125 /* #define BREAKPOINT() asm(" int $3"); */
127 /* use the transmit hw checksum driver functionality */
128 #define USE_SK_TX_CHECKSUM
130 /* use the receive hw checksum driver functionality */
131 #define USE_SK_RX_CHECKSUM
133 /* use the scatter-gather functionality with sendfile() */
134 #define SK_ZEROCOPY
136 /* use of a transmit complete interrupt */
137 #define USE_TX_COMPLETE
140 * threshold for copying small receive frames
141 * set to 0 to avoid copying, set to 9001 to copy all frames
143 #define SK_COPY_THRESHOLD 50
145 /* number of adapters that can be configured via command line params */
146 #define SK_MAX_CARD_PARAM 16
151 * use those defines for a compile-in version of the driver instead
152 * of command line parameters
154 // #define LINK_SPEED_A {"Auto", }
155 // #define LINK_SPEED_B {"Auto", }
156 // #define AUTO_NEG_A {"Sense", }
157 // #define AUTO_NEG_B {"Sense", }
158 // #define DUP_CAP_A {"Both", }
159 // #define DUP_CAP_B {"Both", }
160 // #define FLOW_CTRL_A {"SymOrRem", }
161 // #define FLOW_CTRL_B {"SymOrRem", }
162 // #define ROLE_A {"Auto", }
163 // #define ROLE_B {"Auto", }
164 // #define PREF_PORT {"A", }
165 // #define CON_TYPE {"Auto", }
166 // #define RLMT_MODE {"CheckLinkState", }
168 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
169 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
170 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
173 /* Set blink mode*/
174 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
175 SK_DUP_LED_NORMAL | \
176 SK_LED_LINK100_ON)
179 /* Isr return value */
180 #define SkIsrRetVar irqreturn_t
181 #define SkIsrRetNone IRQ_NONE
182 #define SkIsrRetHandled IRQ_HANDLED
185 /*******************************************************************************
187 * Local Function Prototypes
189 ******************************************************************************/
191 static void FreeResources(struct SK_NET_DEVICE *dev);
192 static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
193 static SK_BOOL BoardAllocMem(SK_AC *pAC);
194 static void BoardFreeMem(SK_AC *pAC);
195 static void BoardInitMem(SK_AC *pAC);
196 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
197 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
198 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
199 static int SkGeOpen(struct SK_NET_DEVICE *dev);
200 static int SkGeClose(struct SK_NET_DEVICE *dev);
201 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
202 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
203 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
204 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
205 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
206 static void GetConfiguration(SK_AC*);
207 static void ProductStr(SK_AC*);
208 static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
209 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
210 static void FillRxRing(SK_AC*, RX_PORT*);
211 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
212 static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
213 static void ClearAndStartRx(SK_AC*, int);
214 static void ClearTxIrq(SK_AC*, int, int);
215 static void ClearRxRing(SK_AC*, RX_PORT*);
216 static void ClearTxRing(SK_AC*, TX_PORT*);
217 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
218 static void PortReInitBmu(SK_AC*, int);
219 static int SkGeIocMib(DEV_NET*, unsigned int, int);
220 static int SkGeInitPCI(SK_AC *pAC);
221 static void StartDrvCleanupTimer(SK_AC *pAC);
222 static void StopDrvCleanupTimer(SK_AC *pAC);
223 static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
225 #ifdef SK_DIAG_SUPPORT
226 static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
227 static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
228 static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
229 #endif
231 /*******************************************************************************
233 * Extern Function Prototypes
235 ******************************************************************************/
237 #ifdef CONFIG_PROC_FS
238 static const char SK_Root_Dir_entry[] = "sk98lin";
239 static struct proc_dir_entry *pSkRootDir;
240 extern struct file_operations sk_proc_fops;
241 #endif
243 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
244 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
245 extern void SkDimStartModerationTimer(SK_AC *pAC);
246 extern void SkDimModerate(SK_AC *pAC);
248 #ifdef DEBUG
249 static void DumpMsg(struct sk_buff*, char*);
250 static void DumpData(char*, int);
251 static void DumpLong(char*, int);
252 #endif
254 /* global variables *********************************************************/
255 struct SK_NET_DEVICE *SkGeRootDev = NULL;
256 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
258 /* local variables **********************************************************/
259 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
260 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
262 /*****************************************************************************
264 * SkGeInitPCI - Init the PCI resources
266 * Description:
267 * This function initialize the PCI resources and IO
269 * Returns: N/A
272 int SkGeInitPCI(SK_AC *pAC)
274 struct SK_NET_DEVICE *dev = pAC->dev[0];
275 struct pci_dev *pdev = pAC->PciDev;
276 int retval;
278 if (pci_enable_device(pdev) != 0) {
279 return 1;
282 dev->mem_start = pci_resource_start (pdev, 0);
283 pci_set_master(pdev);
285 if (pci_request_regions(pdev, pAC->Name) != 0) {
286 retval = 2;
287 goto out_disable;
290 #ifdef SK_BIG_ENDIAN
292 * On big endian machines, we use the adapter's aibility of
293 * reading the descriptors as big endian.
296 SK_U32 our2;
297 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
298 our2 |= PCI_REV_DESC;
299 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
301 #endif
304 * Remap the regs into kernel space.
306 pAC->IoBase = (char*)ioremap_nocache(dev->mem_start, 0x4000);
308 if (!pAC->IoBase){
309 retval = 3;
310 goto out_release;
313 return 0;
315 out_release:
316 pci_release_regions(pdev);
317 out_disable:
318 pci_disable_device(pdev);
319 return retval;
323 /*****************************************************************************
325 * FreeResources - release resources allocated for adapter
327 * Description:
328 * This function releases the IRQ, unmaps the IO and
329 * frees the desriptor ring.
331 * Returns: N/A
334 static void FreeResources(struct SK_NET_DEVICE *dev)
336 SK_U32 AllocFlag;
337 DEV_NET *pNet;
338 SK_AC *pAC;
340 if (dev->priv) {
341 pNet = (DEV_NET*) dev->priv;
342 pAC = pNet->pAC;
343 AllocFlag = pAC->AllocFlag;
344 if (pAC->PciDev) {
345 pci_release_regions(pAC->PciDev);
347 if (AllocFlag & SK_ALLOC_IRQ) {
348 free_irq(dev->irq, dev);
350 if (pAC->IoBase) {
351 iounmap(pAC->IoBase);
353 if (pAC->pDescrMem) {
354 BoardFreeMem(pAC);
358 } /* FreeResources */
360 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
361 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
362 MODULE_LICENSE("GPL");
363 MODULE_PARM(Speed_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
364 MODULE_PARM(Speed_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
365 MODULE_PARM(AutoNeg_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
366 MODULE_PARM(AutoNeg_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
367 MODULE_PARM(DupCap_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
368 MODULE_PARM(DupCap_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
369 MODULE_PARM(FlowCtrl_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
370 MODULE_PARM(FlowCtrl_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
371 MODULE_PARM(Role_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
372 MODULE_PARM(Role_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
373 MODULE_PARM(ConType, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
374 MODULE_PARM(PrefPort, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
375 MODULE_PARM(RlmtMode, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
376 /* used for interrupt moderation */
377 MODULE_PARM(IntsPerSec, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
378 MODULE_PARM(Moderation, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
379 MODULE_PARM(Stats, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
380 MODULE_PARM(ModerationMask, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
381 MODULE_PARM(AutoSizing, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
384 #ifdef LINK_SPEED_A
385 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
386 #else
387 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
388 #endif
390 #ifdef LINK_SPEED_B
391 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
392 #else
393 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
394 #endif
396 #ifdef AUTO_NEG_A
397 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
398 #else
399 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
400 #endif
402 #ifdef DUP_CAP_A
403 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
404 #else
405 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
406 #endif
408 #ifdef FLOW_CTRL_A
409 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
410 #else
411 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
412 #endif
414 #ifdef ROLE_A
415 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
416 #else
417 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
418 #endif
420 #ifdef AUTO_NEG_B
421 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
422 #else
423 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
424 #endif
426 #ifdef DUP_CAP_B
427 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
428 #else
429 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
430 #endif
432 #ifdef FLOW_CTRL_B
433 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
434 #else
435 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
436 #endif
438 #ifdef ROLE_B
439 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
440 #else
441 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
442 #endif
444 #ifdef CON_TYPE
445 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
446 #else
447 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
448 #endif
450 #ifdef PREF_PORT
451 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
452 #else
453 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
454 #endif
456 #ifdef RLMT_MODE
457 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
458 #else
459 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
460 #endif
462 static int IntsPerSec[SK_MAX_CARD_PARAM];
463 static char *Moderation[SK_MAX_CARD_PARAM];
464 static char *ModerationMask[SK_MAX_CARD_PARAM];
465 static char *AutoSizing[SK_MAX_CARD_PARAM];
466 static char *Stats[SK_MAX_CARD_PARAM];
468 /*****************************************************************************
470 * SkGeBoardInit - do level 0 and 1 initialization
472 * Description:
473 * This function prepares the board hardware for running. The desriptor
474 * ring is set up, the IRQ is allocated and the configuration settings
475 * are examined.
477 * Returns:
478 * 0, if everything is ok
479 * !=0, on error
481 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
483 short i;
484 unsigned long Flags;
485 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
486 char *VerStr = VER_STRING;
487 int Ret; /* return code of request_irq */
488 SK_BOOL DualNet;
490 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
491 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
492 for (i=0; i<SK_MAX_MACS; i++) {
493 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
494 pAC->TxPort[i][0].PortIndex = i;
495 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
496 pAC->RxPort[i].PortIndex = i;
499 /* Initialize the mutexes */
500 for (i=0; i<SK_MAX_MACS; i++) {
501 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
502 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
504 spin_lock_init(&pAC->SlowPathLock);
506 /* level 0 init common modules here */
508 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
509 /* Does a RESET on board ...*/
510 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
511 printk("HWInit (0) failed.\n");
512 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
513 return(-EAGAIN);
515 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
516 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
517 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
518 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
519 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
520 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
522 pAC->BoardLevel = SK_INIT_DATA;
523 pAC->RxBufSize = ETH_BUF_SIZE;
525 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
526 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
528 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
530 /* level 1 init common modules here (HW init) */
531 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
532 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
533 printk("sk98lin: HWInit (1) failed.\n");
534 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
535 return(-EAGAIN);
537 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
538 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
539 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
540 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
541 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
542 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
544 /* Set chipset type support */
545 pAC->ChipsetType = 0;
546 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
547 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
548 pAC->ChipsetType = 1;
551 GetConfiguration(pAC);
552 if (pAC->RlmtNets == 2) {
553 pAC->GIni.GIPortUsage = SK_MUL_LINK;
556 pAC->BoardLevel = SK_INIT_IO;
557 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
559 if (pAC->GIni.GIMacsFound == 2) {
560 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
561 } else if (pAC->GIni.GIMacsFound == 1) {
562 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
563 pAC->Name, dev);
564 } else {
565 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
566 pAC->GIni.GIMacsFound);
567 return -EAGAIN;
570 if (Ret) {
571 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
572 dev->irq);
573 return -EAGAIN;
575 pAC->AllocFlag |= SK_ALLOC_IRQ;
577 /* Alloc memory for this board (Mem for RxD/TxD) : */
578 if(!BoardAllocMem(pAC)) {
579 printk("No memory for descriptor rings.\n");
580 return(-EAGAIN);
583 SkCsSetReceiveFlags(pAC,
584 SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
585 &pAC->CsOfs1, &pAC->CsOfs2, 0);
586 pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
588 BoardInitMem(pAC);
589 /* tschilling: New common function with minimum size check. */
590 DualNet = SK_FALSE;
591 if (pAC->RlmtNets == 2) {
592 DualNet = SK_TRUE;
595 if (SkGeInitAssignRamToQueues(
596 pAC,
597 pAC->ActivePort,
598 DualNet)) {
599 BoardFreeMem(pAC);
600 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
601 return(-EAGAIN);
605 * Register the device here
607 pAC->Next = SkGeRootDev;
608 SkGeRootDev = dev;
610 return (0);
611 } /* SkGeBoardInit */
614 /*****************************************************************************
616 * BoardAllocMem - allocate the memory for the descriptor rings
618 * Description:
619 * This function allocates the memory for all descriptor rings.
620 * Each ring is aligned for the desriptor alignment and no ring
621 * has a 4 GByte boundary in it (because the upper 32 bit must
622 * be constant for all descriptiors in one rings).
624 * Returns:
625 * SK_TRUE, if all memory could be allocated
626 * SK_FALSE, if not
628 static SK_BOOL BoardAllocMem(
629 SK_AC *pAC)
631 caddr_t pDescrMem; /* pointer to descriptor memory area */
632 size_t AllocLength; /* length of complete descriptor area */
633 int i; /* loop counter */
634 unsigned long BusAddr;
637 /* rings plus one for alignment (do not cross 4 GB boundary) */
638 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
639 #if (BITS_PER_LONG == 32)
640 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
641 #else
642 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
643 + RX_RING_SIZE + 8;
644 #endif
646 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
647 &pAC->pDescrMemDMA);
649 if (pDescrMem == NULL) {
650 return (SK_FALSE);
652 pAC->pDescrMem = pDescrMem;
653 BusAddr = (unsigned long) pAC->pDescrMemDMA;
655 /* Descriptors need 8 byte alignment, and this is ensured
656 * by pci_alloc_consistent.
658 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
659 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
660 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
661 i, (unsigned long) pDescrMem,
662 BusAddr));
663 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
664 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
665 pDescrMem += TX_RING_SIZE;
666 BusAddr += TX_RING_SIZE;
668 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
669 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
670 i, (unsigned long) pDescrMem,
671 (unsigned long)BusAddr));
672 pAC->RxPort[i].pRxDescrRing = pDescrMem;
673 pAC->RxPort[i].VRxDescrRing = BusAddr;
674 pDescrMem += RX_RING_SIZE;
675 BusAddr += RX_RING_SIZE;
676 } /* for */
678 return (SK_TRUE);
679 } /* BoardAllocMem */
682 /****************************************************************************
684 * BoardFreeMem - reverse of BoardAllocMem
686 * Description:
687 * Free all memory allocated in BoardAllocMem: adapter context,
688 * descriptor rings, locks.
690 * Returns: N/A
692 static void BoardFreeMem(
693 SK_AC *pAC)
695 size_t AllocLength; /* length of complete descriptor area */
697 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
698 ("BoardFreeMem\n"));
699 #if (BITS_PER_LONG == 32)
700 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
701 #else
702 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
703 + RX_RING_SIZE + 8;
704 #endif
706 pci_free_consistent(pAC->PciDev, AllocLength,
707 pAC->pDescrMem, pAC->pDescrMemDMA);
708 pAC->pDescrMem = NULL;
709 } /* BoardFreeMem */
712 /*****************************************************************************
714 * BoardInitMem - initiate the descriptor rings
716 * Description:
717 * This function sets the descriptor rings up in memory.
718 * The adapter is initialized with the descriptor start addresses.
720 * Returns: N/A
722 static void BoardInitMem(
723 SK_AC *pAC) /* pointer to adapter context */
725 int i; /* loop counter */
726 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
727 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
729 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
730 ("BoardInitMem\n"));
732 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
733 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
734 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
735 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
737 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
738 SetupRing(
739 pAC,
740 pAC->TxPort[i][0].pTxDescrRing,
741 pAC->TxPort[i][0].VTxDescrRing,
742 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
743 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
744 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
745 &pAC->TxPort[i][0].TxdRingFree,
746 SK_TRUE);
747 SetupRing(
748 pAC,
749 pAC->RxPort[i].pRxDescrRing,
750 pAC->RxPort[i].VRxDescrRing,
751 &pAC->RxPort[i].pRxdRingHead,
752 &pAC->RxPort[i].pRxdRingTail,
753 &pAC->RxPort[i].pRxdRingPrev,
754 &pAC->RxPort[i].RxdRingFree,
755 SK_FALSE);
757 } /* BoardInitMem */
760 /*****************************************************************************
762 * SetupRing - create one descriptor ring
764 * Description:
765 * This function creates one descriptor ring in the given memory area.
766 * The head, tail and number of free descriptors in the ring are set.
768 * Returns:
769 * none
771 static void SetupRing(
772 SK_AC *pAC,
773 void *pMemArea, /* a pointer to the memory area for the ring */
774 uintptr_t VMemArea, /* the virtual bus address of the memory area */
775 RXD **ppRingHead, /* address where the head should be written */
776 RXD **ppRingTail, /* address where the tail should be written */
777 RXD **ppRingPrev, /* address where the tail should be written */
778 int *pRingFree, /* address where the # of free descr. goes */
779 SK_BOOL IsTx) /* flag: is this a tx ring */
781 int i; /* loop counter */
782 int DescrSize; /* the size of a descriptor rounded up to alignment*/
783 int DescrNum; /* number of descriptors per ring */
784 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
785 RXD *pNextDescr; /* pointer to the next descriptor */
786 RXD *pPrevDescr; /* pointer to the previous descriptor */
787 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
789 if (IsTx == SK_TRUE) {
790 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
791 DESCR_ALIGN;
792 DescrNum = TX_RING_SIZE / DescrSize;
793 } else {
794 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
795 DESCR_ALIGN;
796 DescrNum = RX_RING_SIZE / DescrSize;
799 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
800 ("Descriptor size: %d Descriptor Number: %d\n",
801 DescrSize,DescrNum));
803 pDescr = (RXD*) pMemArea;
804 pPrevDescr = NULL;
805 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
806 VNextDescr = VMemArea + DescrSize;
807 for(i=0; i<DescrNum; i++) {
808 /* set the pointers right */
809 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
810 pDescr->pNextRxd = pNextDescr;
811 pDescr->TcpSumStarts = pAC->CsOfs;
813 /* advance one step */
814 pPrevDescr = pDescr;
815 pDescr = pNextDescr;
816 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
817 VNextDescr += DescrSize;
819 pPrevDescr->pNextRxd = (RXD*) pMemArea;
820 pPrevDescr->VNextRxd = VMemArea;
821 pDescr = (RXD*) pMemArea;
822 *ppRingHead = (RXD*) pMemArea;
823 *ppRingTail = *ppRingHead;
824 *ppRingPrev = pPrevDescr;
825 *pRingFree = DescrNum;
826 } /* SetupRing */
829 /*****************************************************************************
831 * PortReInitBmu - re-initiate the descriptor rings for one port
833 * Description:
834 * This function reinitializes the descriptor rings of one port
835 * in memory. The port must be stopped before.
836 * The HW is initialized with the descriptor start addresses.
838 * Returns:
839 * none
841 static void PortReInitBmu(
842 SK_AC *pAC, /* pointer to adapter context */
843 int PortIndex) /* index of the port for which to re-init */
845 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
846 ("PortReInitBmu "));
848 /* set address of first descriptor of ring in BMU */
849 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
850 (uint32_t)(((caddr_t)
851 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
852 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
853 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
854 0xFFFFFFFF));
855 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
856 (uint32_t)(((caddr_t)
857 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
858 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
859 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
860 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
861 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
862 pAC->RxPort[PortIndex].pRxDescrRing +
863 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
864 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
865 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
866 pAC->RxPort[PortIndex].pRxDescrRing +
867 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
868 } /* PortReInitBmu */
871 /****************************************************************************
873 * SkGeIsr - handle adapter interrupts
875 * Description:
876 * The interrupt routine is called when the network adapter
877 * generates an interrupt. It may also be called if another device
878 * shares this interrupt vector with the driver.
880 * Returns: N/A
883 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
885 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
886 DEV_NET *pNet;
887 SK_AC *pAC;
888 SK_U32 IntSrc; /* interrupts source register contents */
890 pNet = (DEV_NET*) dev->priv;
891 pAC = pNet->pAC;
894 * Check and process if its our interrupt
896 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
897 if (IntSrc == 0) {
898 return SkIsrRetNone;
901 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
902 #if 0 /* software irq currently not used */
903 if (IntSrc & IS_IRQ_SW) {
904 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
905 SK_DBGCAT_DRV_INT_SRC,
906 ("Software IRQ\n"));
908 #endif
909 if (IntSrc & IS_R1_F) {
910 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
911 SK_DBGCAT_DRV_INT_SRC,
912 ("EOF RX1 IRQ\n"));
913 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
914 SK_PNMI_CNT_RX_INTR(pAC, 0);
916 if (IntSrc & IS_R2_F) {
917 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
918 SK_DBGCAT_DRV_INT_SRC,
919 ("EOF RX2 IRQ\n"));
920 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
921 SK_PNMI_CNT_RX_INTR(pAC, 1);
923 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
924 if (IntSrc & IS_XA1_F) {
925 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
926 SK_DBGCAT_DRV_INT_SRC,
927 ("EOF AS TX1 IRQ\n"));
928 SK_PNMI_CNT_TX_INTR(pAC, 0);
929 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
930 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
931 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
933 if (IntSrc & IS_XA2_F) {
934 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
935 SK_DBGCAT_DRV_INT_SRC,
936 ("EOF AS TX2 IRQ\n"));
937 SK_PNMI_CNT_TX_INTR(pAC, 1);
938 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
939 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
940 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
942 #if 0 /* only if sync. queues used */
943 if (IntSrc & IS_XS1_F) {
944 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
945 SK_DBGCAT_DRV_INT_SRC,
946 ("EOF SY TX1 IRQ\n"));
947 SK_PNMI_CNT_TX_INTR(pAC, 1);
948 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
949 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
950 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
951 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
953 if (IntSrc & IS_XS2_F) {
954 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
955 SK_DBGCAT_DRV_INT_SRC,
956 ("EOF SY TX2 IRQ\n"));
957 SK_PNMI_CNT_TX_INTR(pAC, 1);
958 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
959 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
960 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
961 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
963 #endif
964 #endif
966 /* do all IO at once */
967 if (IntSrc & IS_R1_F)
968 ClearAndStartRx(pAC, 0);
969 if (IntSrc & IS_R2_F)
970 ClearAndStartRx(pAC, 1);
971 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
972 if (IntSrc & IS_XA1_F)
973 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
974 if (IntSrc & IS_XA2_F)
975 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
976 #endif
977 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
978 } /* while (IntSrc & IRQ_MASK != 0) */
980 IntSrc &= pAC->GIni.GIValIrqMask;
981 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
982 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
983 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
984 pAC->CheckQueue = SK_FALSE;
985 spin_lock(&pAC->SlowPathLock);
986 if (IntSrc & SPECIAL_IRQS)
987 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
989 SkEventDispatcher(pAC, pAC->IoBase);
990 spin_unlock(&pAC->SlowPathLock);
993 * do it all again is case we cleared an interrupt that
994 * came in after handling the ring (OUTs may be delayed
995 * in hardware buffers, but are through after IN)
997 * rroesler: has been commented out and shifted to
998 * SkGeDrvEvent(), because it is timer
999 * guarded now
1001 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1002 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1005 if (pAC->CheckQueue) {
1006 pAC->CheckQueue = SK_FALSE;
1007 spin_lock(&pAC->SlowPathLock);
1008 SkEventDispatcher(pAC, pAC->IoBase);
1009 spin_unlock(&pAC->SlowPathLock);
1012 /* IRQ is processed - Enable IRQs again*/
1013 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1015 return SkIsrRetHandled;
1016 } /* SkGeIsr */
1019 /****************************************************************************
1021 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1023 * Description:
1024 * The interrupt routine is called when the network adapter
1025 * generates an interrupt. It may also be called if another device
1026 * shares this interrupt vector with the driver.
1027 * This is the same as above, but handles only one port.
1029 * Returns: N/A
1032 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1034 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1035 DEV_NET *pNet;
1036 SK_AC *pAC;
1037 SK_U32 IntSrc; /* interrupts source register contents */
1039 pNet = (DEV_NET*) dev->priv;
1040 pAC = pNet->pAC;
1043 * Check and process if its our interrupt
1045 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1046 if (IntSrc == 0) {
1047 return SkIsrRetNone;
1050 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1051 #if 0 /* software irq currently not used */
1052 if (IntSrc & IS_IRQ_SW) {
1053 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1054 SK_DBGCAT_DRV_INT_SRC,
1055 ("Software IRQ\n"));
1057 #endif
1058 if (IntSrc & IS_R1_F) {
1059 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1060 SK_DBGCAT_DRV_INT_SRC,
1061 ("EOF RX1 IRQ\n"));
1062 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1063 SK_PNMI_CNT_RX_INTR(pAC, 0);
1065 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1066 if (IntSrc & IS_XA1_F) {
1067 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1068 SK_DBGCAT_DRV_INT_SRC,
1069 ("EOF AS TX1 IRQ\n"));
1070 SK_PNMI_CNT_TX_INTR(pAC, 0);
1071 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1072 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1073 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1075 #if 0 /* only if sync. queues used */
1076 if (IntSrc & IS_XS1_F) {
1077 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1078 SK_DBGCAT_DRV_INT_SRC,
1079 ("EOF SY TX1 IRQ\n"));
1080 SK_PNMI_CNT_TX_INTR(pAC, 0);
1081 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1082 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1083 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1084 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1086 #endif
1087 #endif
1089 /* do all IO at once */
1090 if (IntSrc & IS_R1_F)
1091 ClearAndStartRx(pAC, 0);
1092 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1093 if (IntSrc & IS_XA1_F)
1094 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1095 #endif
1096 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1097 } /* while (IntSrc & IRQ_MASK != 0) */
1099 IntSrc &= pAC->GIni.GIValIrqMask;
1100 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1101 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1102 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1103 pAC->CheckQueue = SK_FALSE;
1104 spin_lock(&pAC->SlowPathLock);
1105 if (IntSrc & SPECIAL_IRQS)
1106 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1108 SkEventDispatcher(pAC, pAC->IoBase);
1109 spin_unlock(&pAC->SlowPathLock);
1112 * do it all again is case we cleared an interrupt that
1113 * came in after handling the ring (OUTs may be delayed
1114 * in hardware buffers, but are through after IN)
1116 * rroesler: has been commented out and shifted to
1117 * SkGeDrvEvent(), because it is timer
1118 * guarded now
1120 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1123 /* IRQ is processed - Enable IRQs again*/
1124 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1126 return SkIsrRetHandled;
1127 } /* SkGeIsrOnePort */
1130 /****************************************************************************
1132 * SkGeOpen - handle start of initialized adapter
1134 * Description:
1135 * This function starts the initialized adapter.
1136 * The board level variable is set and the adapter is
1137 * brought to full functionality.
1138 * The device flags are set for operation.
1139 * Do all necessary level 2 initialization, enable interrupts and
1140 * give start command to RLMT.
1142 * Returns:
1143 * 0 on success
1144 * != 0 on error
1146 static int SkGeOpen(
1147 struct SK_NET_DEVICE *dev)
1149 DEV_NET *pNet;
1150 SK_AC *pAC;
1151 unsigned long Flags; /* for spin lock */
1152 int i;
1153 SK_EVPARA EvPara; /* an event parameter union */
1155 pNet = (DEV_NET*) dev->priv;
1156 pAC = pNet->pAC;
1158 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1159 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1161 #ifdef SK_DIAG_SUPPORT
1162 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1163 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1164 return (-1); /* still in use by diag; deny actions */
1167 #endif
1169 if (!try_module_get(THIS_MODULE)) {
1170 return (-1); /* increase of usage count not possible */
1173 /* Set blink mode */
1174 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1175 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1177 if (pAC->BoardLevel == SK_INIT_DATA) {
1178 /* level 1 init common modules here */
1179 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1180 module_put(THIS_MODULE); /* decrease usage count */
1181 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1182 return (-1);
1184 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1185 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1186 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1187 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1188 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1189 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1190 pAC->BoardLevel = SK_INIT_IO;
1193 if (pAC->BoardLevel != SK_INIT_RUN) {
1194 /* tschilling: Level 2 init modules here, check return value. */
1195 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1196 module_put(THIS_MODULE); /* decrease usage count */
1197 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1198 return (-1);
1200 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1201 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1202 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1203 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1204 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1205 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1206 pAC->BoardLevel = SK_INIT_RUN;
1209 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1210 /* Enable transmit descriptor polling. */
1211 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1212 FillRxRing(pAC, &pAC->RxPort[i]);
1214 SkGeYellowLED(pAC, pAC->IoBase, 1);
1216 StartDrvCleanupTimer(pAC);
1217 SkDimEnableModerationIfNeeded(pAC);
1218 SkDimDisplayModerationSettings(pAC);
1220 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1222 /* enable Interrupts */
1223 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1224 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1226 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1228 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1229 EvPara.Para32[0] = pAC->RlmtNets;
1230 EvPara.Para32[1] = -1;
1231 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1232 EvPara);
1233 EvPara.Para32[0] = pAC->RlmtMode;
1234 EvPara.Para32[1] = 0;
1235 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1236 EvPara);
1239 EvPara.Para32[0] = pNet->NetNr;
1240 EvPara.Para32[1] = -1;
1241 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1242 SkEventDispatcher(pAC, pAC->IoBase);
1243 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1245 pAC->MaxPorts++;
1246 pNet->Up = 1;
1249 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1250 ("SkGeOpen suceeded\n"));
1252 return (0);
1253 } /* SkGeOpen */
1256 /****************************************************************************
1258 * SkGeClose - Stop initialized adapter
1260 * Description:
1261 * Close initialized adapter.
1263 * Returns:
1264 * 0 - on success
1265 * error code - on error
1267 static int SkGeClose(
1268 struct SK_NET_DEVICE *dev)
1270 DEV_NET *pNet;
1271 DEV_NET *newPtrNet;
1272 SK_AC *pAC;
1274 unsigned long Flags; /* for spin lock */
1275 int i;
1276 int PortIdx;
1277 SK_EVPARA EvPara;
1279 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1280 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1282 pNet = (DEV_NET*) dev->priv;
1283 pAC = pNet->pAC;
1285 #ifdef SK_DIAG_SUPPORT
1286 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1287 if (pAC->DiagFlowCtrl == SK_FALSE) {
1288 module_put(THIS_MODULE);
1290 ** notify that the interface which has been closed
1291 ** by operator interaction must not be started up
1292 ** again when the DIAG has finished.
1294 newPtrNet = (DEV_NET *) pAC->dev[0]->priv;
1295 if (newPtrNet == pNet) {
1296 pAC->WasIfUp[0] = SK_FALSE;
1297 } else {
1298 pAC->WasIfUp[1] = SK_FALSE;
1300 return 0; /* return to system everything is fine... */
1301 } else {
1302 pAC->DiagFlowCtrl = SK_FALSE;
1305 #endif
1307 netif_stop_queue(dev);
1309 if (pAC->RlmtNets == 1)
1310 PortIdx = pAC->ActivePort;
1311 else
1312 PortIdx = pNet->NetNr;
1314 StopDrvCleanupTimer(pAC);
1317 * Clear multicast table, promiscuous mode ....
1319 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1320 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1321 SK_PROM_MODE_NONE);
1323 if (pAC->MaxPorts == 1) {
1324 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1325 /* disable interrupts */
1326 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1327 EvPara.Para32[0] = pNet->NetNr;
1328 EvPara.Para32[1] = -1;
1329 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1330 SkEventDispatcher(pAC, pAC->IoBase);
1331 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1332 /* stop the hardware */
1333 SkGeDeInit(pAC, pAC->IoBase);
1334 pAC->BoardLevel = SK_INIT_DATA;
1335 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1336 } else {
1338 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1339 EvPara.Para32[0] = pNet->NetNr;
1340 EvPara.Para32[1] = -1;
1341 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1342 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1343 SkEventDispatcher(pAC, pAC->IoBase);
1344 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1346 /* Stop port */
1347 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1348 [TX_PRIO_LOW].TxDesRingLock, Flags);
1349 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1350 SK_STOP_ALL, SK_HARD_RST);
1351 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1352 [TX_PRIO_LOW].TxDesRingLock, Flags);
1355 if (pAC->RlmtNets == 1) {
1356 /* clear all descriptor rings */
1357 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1358 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1359 ClearRxRing(pAC, &pAC->RxPort[i]);
1360 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1362 } else {
1363 /* clear port descriptor rings */
1364 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1365 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1366 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1369 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1370 ("SkGeClose: done "));
1372 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1373 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1374 sizeof(SK_PNMI_STRUCT_DATA));
1376 pAC->MaxPorts--;
1377 pNet->Up = 0;
1379 module_put(THIS_MODULE);
1380 return (0);
1381 } /* SkGeClose */
1384 /*****************************************************************************
1386 * SkGeXmit - Linux frame transmit function
1388 * Description:
1389 * The system calls this function to send frames onto the wire.
1390 * It puts the frame in the tx descriptor ring. If the ring is
1391 * full then, the 'tbusy' flag is set.
1393 * Returns:
1394 * 0, if everything is ok
1395 * !=0, on error
1396 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1397 * allocated skb's) !!!
1399 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1401 DEV_NET *pNet;
1402 SK_AC *pAC;
1403 int Rc; /* return code of XmitFrame */
1405 pNet = (DEV_NET*) dev->priv;
1406 pAC = pNet->pAC;
1408 if ((!skb_shinfo(skb)->nr_frags) ||
1409 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1410 /* Don't activate scatter-gather and hardware checksum */
1412 if (pAC->RlmtNets == 2)
1413 Rc = XmitFrame(
1414 pAC,
1415 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1416 skb);
1417 else
1418 Rc = XmitFrame(
1419 pAC,
1420 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1421 skb);
1422 } else {
1423 /* scatter-gather and hardware TCP checksumming anabled*/
1424 if (pAC->RlmtNets == 2)
1425 Rc = XmitFrameSG(
1426 pAC,
1427 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1428 skb);
1429 else
1430 Rc = XmitFrameSG(
1431 pAC,
1432 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1433 skb);
1436 /* Transmitter out of resources? */
1437 if (Rc <= 0) {
1438 netif_stop_queue(dev);
1441 /* If not taken, give buffer ownership back to the
1442 * queueing layer.
1444 if (Rc < 0)
1445 return (1);
1447 dev->trans_start = jiffies;
1448 return (0);
1449 } /* SkGeXmit */
1452 /*****************************************************************************
1454 * XmitFrame - fill one socket buffer into the transmit ring
1456 * Description:
1457 * This function puts a message into the transmit descriptor ring
1458 * if there is a descriptors left.
1459 * Linux skb's consist of only one continuous buffer.
1460 * The first step locks the ring. It is held locked
1461 * all time to avoid problems with SWITCH_../PORT_RESET.
1462 * Then the descriptoris allocated.
1463 * The second part is linking the buffer to the descriptor.
1464 * At the very last, the Control field of the descriptor
1465 * is made valid for the BMU and a start TX command is given
1466 * if necessary.
1468 * Returns:
1469 * > 0 - on succes: the number of bytes in the message
1470 * = 0 - on resource shortage: this frame sent or dropped, now
1471 * the ring is full ( -> set tbusy)
1472 * < 0 - on failure: other problems ( -> return failure to upper layers)
1474 static int XmitFrame(
1475 SK_AC *pAC, /* pointer to adapter context */
1476 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1477 struct sk_buff *pMessage) /* pointer to send-message */
1479 TXD *pTxd; /* the rxd to fill */
1480 TXD *pOldTxd;
1481 unsigned long Flags;
1482 SK_U64 PhysAddr;
1483 int Protocol;
1484 int IpHeaderLength;
1485 int BytesSend = pMessage->len;
1487 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1489 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1490 #ifndef USE_TX_COMPLETE
1491 FreeTxDescriptors(pAC, pTxPort);
1492 #endif
1493 if (pTxPort->TxdRingFree == 0) {
1495 ** no enough free descriptors in ring at the moment.
1496 ** Maybe free'ing some old one help?
1498 FreeTxDescriptors(pAC, pTxPort);
1499 if (pTxPort->TxdRingFree == 0) {
1500 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1501 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1502 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1503 SK_DBGCAT_DRV_TX_PROGRESS,
1504 ("XmitFrame failed\n"));
1506 ** the desired message can not be sent
1507 ** Because tbusy seems to be set, the message
1508 ** should not be freed here. It will be used
1509 ** by the scheduler of the ethernet handler
1511 return (-1);
1516 ** If the passed socket buffer is of smaller MTU-size than 60,
1517 ** copy everything into new buffer and fill all bytes between
1518 ** the original packet end and the new packet end of 60 with 0x00.
1519 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1521 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1522 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1523 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1524 return 0;
1526 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1530 ** advance head counter behind descriptor needed for this frame,
1531 ** so that needed descriptor is reserved from that on. The next
1532 ** action will be to add the passed buffer to the TX-descriptor
1534 pTxd = pTxPort->pTxdRingHead;
1535 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1536 pTxPort->TxdRingFree--;
1538 #ifdef SK_DUMP_TX
1539 DumpMsg(pMessage, "XmitFrame");
1540 #endif
1543 ** First step is to map the data to be sent via the adapter onto
1544 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1545 ** and 2.6 need to use pci_map_page() for that mapping.
1547 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1548 virt_to_page(pMessage->data),
1549 ((unsigned long) pMessage->data & ~PAGE_MASK),
1550 pMessage->len,
1551 PCI_DMA_TODEVICE);
1552 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1553 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1554 pTxd->pMBuf = pMessage;
1556 if (pMessage->ip_summed == CHECKSUM_HW) {
1557 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1558 if ((Protocol == C_PROTO_ID_UDP) &&
1559 (pAC->GIni.GIChipRev == 0) &&
1560 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1561 pTxd->TBControl = BMU_TCP_CHECK;
1562 } else {
1563 pTxd->TBControl = BMU_UDP_CHECK;
1566 IpHeaderLength = (SK_U8)pMessage->data[C_OFFSET_IPHEADER];
1567 IpHeaderLength = (IpHeaderLength & 0xf) * 4;
1568 pTxd->TcpSumOfs = 0; /* PH-Checksum already calculated */
1569 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1570 (Protocol == C_PROTO_ID_UDP ?
1571 C_OFFSET_UDPHEADER_UDPCS :
1572 C_OFFSET_TCPHEADER_TCPCS);
1573 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1575 pTxd->TBControl |= BMU_OWN | BMU_STF |
1576 BMU_SW | BMU_EOF |
1577 #ifdef USE_TX_COMPLETE
1578 BMU_IRQ_EOF |
1579 #endif
1580 pMessage->len;
1581 } else {
1582 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1583 BMU_SW | BMU_EOF |
1584 #ifdef USE_TX_COMPLETE
1585 BMU_IRQ_EOF |
1586 #endif
1587 pMessage->len;
1591 ** If previous descriptor already done, give TX start cmd
1593 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1594 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1595 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1599 ** after releasing the lock, the skb may immediately be free'd
1601 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1602 if (pTxPort->TxdRingFree != 0) {
1603 return (BytesSend);
1604 } else {
1605 return (0);
1608 } /* XmitFrame */
1610 /*****************************************************************************
1612 * XmitFrameSG - fill one socket buffer into the transmit ring
1613 * (use SG and TCP/UDP hardware checksumming)
1615 * Description:
1616 * This function puts a message into the transmit descriptor ring
1617 * if there is a descriptors left.
1619 * Returns:
1620 * > 0 - on succes: the number of bytes in the message
1621 * = 0 - on resource shortage: this frame sent or dropped, now
1622 * the ring is full ( -> set tbusy)
1623 * < 0 - on failure: other problems ( -> return failure to upper layers)
1625 static int XmitFrameSG(
1626 SK_AC *pAC, /* pointer to adapter context */
1627 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1628 struct sk_buff *pMessage) /* pointer to send-message */
1631 TXD *pTxd;
1632 TXD *pTxdFst;
1633 TXD *pTxdLst;
1634 int CurrFrag;
1635 int BytesSend;
1636 int IpHeaderLength;
1637 int Protocol;
1638 skb_frag_t *sk_frag;
1639 SK_U64 PhysAddr;
1640 unsigned long Flags;
1642 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1643 #ifndef USE_TX_COMPLETE
1644 FreeTxDescriptors(pAC, pTxPort);
1645 #endif
1646 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1647 FreeTxDescriptors(pAC, pTxPort);
1648 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1649 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1650 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1651 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1652 SK_DBGCAT_DRV_TX_PROGRESS,
1653 ("XmitFrameSG failed - Ring full\n"));
1654 /* this message can not be sent now */
1655 return(-1);
1659 pTxd = pTxPort->pTxdRingHead;
1660 pTxdFst = pTxd;
1661 pTxdLst = pTxd;
1662 BytesSend = 0;
1663 Protocol = 0;
1666 ** Map the first fragment (header) into the DMA-space
1668 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1669 virt_to_page(pMessage->data),
1670 ((unsigned long) pMessage->data & ~PAGE_MASK),
1671 skb_headlen(pMessage),
1672 PCI_DMA_TODEVICE);
1674 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1675 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1678 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1680 if (pMessage->ip_summed == CHECKSUM_HW) {
1681 pTxd->TBControl = BMU_STF | BMU_STFWD | skb_headlen(pMessage);
1683 ** We have to use the opcode for tcp here, because the
1684 ** opcode for udp is not working in the hardware yet
1685 ** (Revision 2.0)
1687 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1688 if ((Protocol == C_PROTO_ID_UDP) &&
1689 (pAC->GIni.GIChipRev == 0) &&
1690 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1691 pTxd->TBControl |= BMU_TCP_CHECK;
1692 } else {
1693 pTxd->TBControl |= BMU_UDP_CHECK;
1696 IpHeaderLength = ((SK_U8)pMessage->data[C_OFFSET_IPHEADER] & 0xf)*4;
1697 pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
1698 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1699 (Protocol == C_PROTO_ID_UDP ?
1700 C_OFFSET_UDPHEADER_UDPCS :
1701 C_OFFSET_TCPHEADER_TCPCS);
1702 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1703 } else {
1704 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_STF |
1705 skb_headlen(pMessage);
1708 pTxd = pTxd->pNextTxd;
1709 pTxPort->TxdRingFree--;
1710 BytesSend += skb_headlen(pMessage);
1713 ** Browse over all SG fragments and map each of them into the DMA space
1715 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1716 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1718 ** we already have the proper value in entry
1720 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1721 sk_frag->page,
1722 sk_frag->page_offset,
1723 sk_frag->size,
1724 PCI_DMA_TODEVICE);
1726 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1727 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1728 pTxd->pMBuf = pMessage;
1731 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1733 if (pMessage->ip_summed == CHECKSUM_HW) {
1734 pTxd->TBControl = BMU_OWN | BMU_SW | BMU_STFWD;
1736 ** We have to use the opcode for tcp here because the
1737 ** opcode for udp is not working in the hardware yet
1738 ** (revision 2.0)
1740 if ((Protocol == C_PROTO_ID_UDP) &&
1741 (pAC->GIni.GIChipRev == 0) &&
1742 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1743 pTxd->TBControl |= BMU_TCP_CHECK;
1744 } else {
1745 pTxd->TBControl |= BMU_UDP_CHECK;
1747 } else {
1748 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_OWN;
1752 ** Do we have the last fragment?
1754 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1755 #ifdef USE_TX_COMPLETE
1756 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF | sk_frag->size;
1757 #else
1758 pTxd->TBControl |= BMU_EOF | sk_frag->size;
1759 #endif
1760 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1762 } else {
1763 pTxd->TBControl |= sk_frag->size;
1765 pTxdLst = pTxd;
1766 pTxd = pTxd->pNextTxd;
1767 pTxPort->TxdRingFree--;
1768 BytesSend += sk_frag->size;
1772 ** If previous descriptor already done, give TX start cmd
1774 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1775 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1778 pTxPort->pTxdRingPrev = pTxdLst;
1779 pTxPort->pTxdRingHead = pTxd;
1781 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1783 if (pTxPort->TxdRingFree > 0) {
1784 return (BytesSend);
1785 } else {
1786 return (0);
1790 /*****************************************************************************
1792 * FreeTxDescriptors - release descriptors from the descriptor ring
1794 * Description:
1795 * This function releases descriptors from a transmit ring if they
1796 * have been sent by the BMU.
1797 * If a descriptors is sent, it can be freed and the message can
1798 * be freed, too.
1799 * The SOFTWARE controllable bit is used to prevent running around a
1800 * completely free ring for ever. If this bit is no set in the
1801 * frame (by XmitFrame), this frame has never been sent or is
1802 * already freed.
1803 * The Tx descriptor ring lock must be held while calling this function !!!
1805 * Returns:
1806 * none
1808 static void FreeTxDescriptors(
1809 SK_AC *pAC, /* pointer to the adapter context */
1810 TX_PORT *pTxPort) /* pointer to destination port structure */
1812 TXD *pTxd; /* pointer to the checked descriptor */
1813 TXD *pNewTail; /* pointer to 'end' of the ring */
1814 SK_U32 Control; /* TBControl field of descriptor */
1815 SK_U64 PhysAddr; /* address of DMA mapping */
1817 pNewTail = pTxPort->pTxdRingTail;
1818 pTxd = pNewTail;
1820 ** loop forever; exits if BMU_SW bit not set in start frame
1821 ** or BMU_OWN bit set in any frame
1823 while (1) {
1824 Control = pTxd->TBControl;
1825 if ((Control & BMU_SW) == 0) {
1827 ** software controllable bit is set in first
1828 ** fragment when given to BMU. Not set means that
1829 ** this fragment was never sent or is already
1830 ** freed ( -> ring completely free now).
1832 pTxPort->pTxdRingTail = pTxd;
1833 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1834 return;
1836 if (Control & BMU_OWN) {
1837 pTxPort->pTxdRingTail = pTxd;
1838 if (pTxPort->TxdRingFree > 0) {
1839 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1841 return;
1845 ** release the DMA mapping, because until not unmapped
1846 ** this buffer is considered being under control of the
1847 ** adapter card!
1849 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1850 PhysAddr |= (SK_U64) pTxd->VDataLow;
1851 pci_unmap_page(pAC->PciDev, PhysAddr,
1852 pTxd->pMBuf->len,
1853 PCI_DMA_TODEVICE);
1855 if (Control & BMU_EOF)
1856 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1858 pTxPort->TxdRingFree++;
1859 pTxd->TBControl &= ~BMU_SW;
1860 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1861 } /* while(forever) */
1862 } /* FreeTxDescriptors */
1864 /*****************************************************************************
1866 * FillRxRing - fill the receive ring with valid descriptors
1868 * Description:
1869 * This function fills the receive ring descriptors with data
1870 * segments and makes them valid for the BMU.
1871 * The active ring is filled completely, if possible.
1872 * The non-active ring is filled only partial to save memory.
1874 * Description of rx ring structure:
1875 * head - points to the descriptor which will be used next by the BMU
1876 * tail - points to the next descriptor to give to the BMU
1878 * Returns: N/A
1880 static void FillRxRing(
1881 SK_AC *pAC, /* pointer to the adapter context */
1882 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1883 should be filled */
1885 unsigned long Flags;
1887 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1888 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1889 if(!FillRxDescriptor(pAC, pRxPort))
1890 break;
1892 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1893 } /* FillRxRing */
1896 /*****************************************************************************
1898 * FillRxDescriptor - fill one buffer into the receive ring
1900 * Description:
1901 * The function allocates a new receive buffer and
1902 * puts it into the next descriptor.
1904 * Returns:
1905 * SK_TRUE - a buffer was added to the ring
1906 * SK_FALSE - a buffer could not be added
1908 static SK_BOOL FillRxDescriptor(
1909 SK_AC *pAC, /* pointer to the adapter context struct */
1910 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1912 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1913 RXD *pRxd; /* the rxd to fill */
1914 SK_U16 Length; /* data fragment length */
1915 SK_U64 PhysAddr; /* physical address of a rx buffer */
1917 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1918 if (pMsgBlock == NULL) {
1919 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1920 SK_DBGCAT_DRV_ENTRY,
1921 ("%s: Allocation of rx buffer failed !\n",
1922 pAC->dev[pRxPort->PortIndex]->name));
1923 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1924 return(SK_FALSE);
1926 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1927 /* skb allocated ok, so add buffer */
1928 pRxd = pRxPort->pRxdRingTail;
1929 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1930 pRxPort->RxdRingFree--;
1931 Length = pAC->RxBufSize;
1932 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1933 virt_to_page(pMsgBlock->data),
1934 ((unsigned long) pMsgBlock->data &
1935 ~PAGE_MASK),
1936 pAC->RxBufSize - 2,
1937 PCI_DMA_FROMDEVICE);
1939 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1940 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1941 pRxd->pMBuf = pMsgBlock;
1942 pRxd->RBControl = BMU_OWN |
1943 BMU_STF |
1944 BMU_IRQ_EOF |
1945 BMU_TCP_CHECK |
1946 Length;
1947 return (SK_TRUE);
1949 } /* FillRxDescriptor */
1952 /*****************************************************************************
1954 * ReQueueRxBuffer - fill one buffer back into the receive ring
1956 * Description:
1957 * Fill a given buffer back into the rx ring. The buffer
1958 * has been previously allocated and aligned, and its phys.
1959 * address calculated, so this is no more necessary.
1961 * Returns: N/A
1963 static void ReQueueRxBuffer(
1964 SK_AC *pAC, /* pointer to the adapter context struct */
1965 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1966 struct sk_buff *pMsg, /* pointer to the buffer */
1967 SK_U32 PhysHigh, /* phys address high dword */
1968 SK_U32 PhysLow) /* phys address low dword */
1970 RXD *pRxd; /* the rxd to fill */
1971 SK_U16 Length; /* data fragment length */
1973 pRxd = pRxPort->pRxdRingTail;
1974 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1975 pRxPort->RxdRingFree--;
1976 Length = pAC->RxBufSize;
1978 pRxd->VDataLow = PhysLow;
1979 pRxd->VDataHigh = PhysHigh;
1980 pRxd->pMBuf = pMsg;
1981 pRxd->RBControl = BMU_OWN |
1982 BMU_STF |
1983 BMU_IRQ_EOF |
1984 BMU_TCP_CHECK |
1985 Length;
1986 return;
1987 } /* ReQueueRxBuffer */
1989 /*****************************************************************************
1991 * ReceiveIrq - handle a receive IRQ
1993 * Description:
1994 * This function is called when a receive IRQ is set.
1995 * It walks the receive descriptor ring and sends up all
1996 * frames that are complete.
1998 * Returns: N/A
2000 static void ReceiveIrq(
2001 SK_AC *pAC, /* pointer to adapter context */
2002 RX_PORT *pRxPort, /* pointer to receive port struct */
2003 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
2005 RXD *pRxd; /* pointer to receive descriptors */
2006 SK_U32 Control; /* control field of descriptor */
2007 struct sk_buff *pMsg; /* pointer to message holding frame */
2008 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
2009 int FrameLength; /* total length of received frame */
2010 int IpFrameLength;
2011 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2012 SK_EVPARA EvPara; /* an event parameter union */
2013 unsigned long Flags; /* for spin lock */
2014 int PortIndex = pRxPort->PortIndex;
2015 unsigned int Offset;
2016 unsigned int NumBytes;
2017 unsigned int ForRlmt;
2018 SK_BOOL IsBc;
2019 SK_BOOL IsMc;
2020 SK_BOOL IsBadFrame; /* Bad frame */
2022 SK_U32 FrameStat;
2023 unsigned short Csum1;
2024 unsigned short Csum2;
2025 unsigned short Type;
2026 int Result;
2027 SK_U64 PhysAddr;
2029 rx_start:
2030 /* do forever; exit if BMU_OWN found */
2031 for ( pRxd = pRxPort->pRxdRingHead ;
2032 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2033 pRxd = pRxd->pNextRxd,
2034 pRxPort->pRxdRingHead = pRxd,
2035 pRxPort->RxdRingFree ++) {
2038 * For a better understanding of this loop
2039 * Go through every descriptor beginning at the head
2040 * Please note: the ring might be completely received so the OWN bit
2041 * set is not a good crirteria to leave that loop.
2042 * Therefore the RingFree counter is used.
2043 * On entry of this loop pRxd is a pointer to the Rxd that needs
2044 * to be checked next.
2047 Control = pRxd->RBControl;
2049 /* check if this descriptor is ready */
2050 if ((Control & BMU_OWN) != 0) {
2051 /* this descriptor is not yet ready */
2052 /* This is the usual end of the loop */
2053 /* We don't need to start the ring again */
2054 FillRxRing(pAC, pRxPort);
2055 return;
2057 pAC->DynIrqModInfo.NbrProcessedDescr++;
2059 /* get length of frame and check it */
2060 FrameLength = Control & BMU_BBC;
2061 if (FrameLength > pAC->RxBufSize) {
2062 goto rx_failed;
2065 /* check for STF and EOF */
2066 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2067 goto rx_failed;
2070 /* here we have a complete frame in the ring */
2071 pMsg = pRxd->pMBuf;
2073 FrameStat = pRxd->FrameStat;
2075 /* check for frame length mismatch */
2076 #define XMR_FS_LEN_SHIFT 18
2077 #define GMR_FS_LEN_SHIFT 16
2078 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2079 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2080 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2081 SK_DBGCAT_DRV_RX_PROGRESS,
2082 ("skge: Frame length mismatch (%u/%u).\n",
2083 FrameLength,
2084 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2085 goto rx_failed;
2088 else {
2089 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2090 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2091 SK_DBGCAT_DRV_RX_PROGRESS,
2092 ("skge: Frame length mismatch (%u/%u).\n",
2093 FrameLength,
2094 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2095 goto rx_failed;
2099 /* Set Rx Status */
2100 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2101 IsBc = (FrameStat & XMR_FS_BC) != 0;
2102 IsMc = (FrameStat & XMR_FS_MC) != 0;
2103 IsBadFrame = (FrameStat &
2104 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2105 } else {
2106 IsBc = (FrameStat & GMR_FS_BC) != 0;
2107 IsMc = (FrameStat & GMR_FS_MC) != 0;
2108 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2109 ((FrameStat & GMR_FS_RX_OK) == 0));
2112 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2113 ("Received frame of length %d on port %d\n",
2114 FrameLength, PortIndex));
2115 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2116 ("Number of free rx descriptors: %d\n",
2117 pRxPort->RxdRingFree));
2118 /* DumpMsg(pMsg, "Rx"); */
2120 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2121 #if 0
2122 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2123 #endif
2124 /* there is a receive error in this frame */
2125 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2126 SK_DBGCAT_DRV_RX_PROGRESS,
2127 ("skge: Error in received frame, dropped!\n"
2128 "Control: %x\nRxStat: %x\n",
2129 Control, FrameStat));
2131 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2132 pRxd->VDataHigh, pRxd->VDataLow);
2134 continue;
2138 * if short frame then copy data to reduce memory waste
2140 if ((FrameLength < SK_COPY_THRESHOLD) &&
2141 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2143 * Short frame detected and allocation successfull
2145 /* use new skb and copy data */
2146 skb_reserve(pNewMsg, 2);
2147 skb_put(pNewMsg, FrameLength);
2148 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2149 PhysAddr |= (SK_U64) pRxd->VDataLow;
2151 pci_dma_sync_single_for_cpu(pAC->PciDev,
2152 (dma_addr_t) PhysAddr,
2153 FrameLength,
2154 PCI_DMA_FROMDEVICE);
2155 eth_copy_and_sum(pNewMsg, pMsg->data,
2156 FrameLength, 0);
2157 pci_dma_sync_single_for_device(pAC->PciDev,
2158 (dma_addr_t) PhysAddr,
2159 FrameLength,
2160 PCI_DMA_FROMDEVICE);
2161 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2162 pRxd->VDataHigh, pRxd->VDataLow);
2164 pMsg = pNewMsg;
2167 else {
2169 * if large frame, or SKB allocation failed, pass
2170 * the SKB directly to the networking
2173 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2174 PhysAddr |= (SK_U64) pRxd->VDataLow;
2176 /* release the DMA mapping */
2177 pci_unmap_single(pAC->PciDev,
2178 PhysAddr,
2179 pAC->RxBufSize - 2,
2180 PCI_DMA_FROMDEVICE);
2182 /* set length in message */
2183 skb_put(pMsg, FrameLength);
2184 /* hardware checksum */
2185 Type = ntohs(*((short*)&pMsg->data[12]));
2187 #ifdef USE_SK_RX_CHECKSUM
2188 if (Type == 0x800) {
2189 Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
2190 Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
2191 IpFrameLength = (int) ntohs((unsigned short)
2192 ((unsigned short *) pMsg->data)[8]);
2195 * Test: If frame is padded, a check is not possible!
2196 * Frame not padded? Length difference must be 14 (0xe)!
2198 if ((FrameLength - IpFrameLength) != 0xe) {
2199 /* Frame padded => TCP offload not possible! */
2200 pMsg->ip_summed = CHECKSUM_NONE;
2201 } else {
2202 /* Frame not padded => TCP offload! */
2203 if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
2204 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
2205 (pAC->ChipsetType)) {
2206 Result = SkCsGetReceiveInfo(pAC,
2207 &pMsg->data[14],
2208 Csum1, Csum2, pRxPort->PortIndex);
2209 if (Result ==
2210 SKCS_STATUS_IP_FRAGMENT ||
2211 Result ==
2212 SKCS_STATUS_IP_CSUM_OK ||
2213 Result ==
2214 SKCS_STATUS_TCP_CSUM_OK ||
2215 Result ==
2216 SKCS_STATUS_UDP_CSUM_OK) {
2217 pMsg->ip_summed =
2218 CHECKSUM_UNNECESSARY;
2220 else if (Result ==
2221 SKCS_STATUS_TCP_CSUM_ERROR ||
2222 Result ==
2223 SKCS_STATUS_UDP_CSUM_ERROR ||
2224 Result ==
2225 SKCS_STATUS_IP_CSUM_ERROR_UDP ||
2226 Result ==
2227 SKCS_STATUS_IP_CSUM_ERROR_TCP ||
2228 Result ==
2229 SKCS_STATUS_IP_CSUM_ERROR ) {
2230 /* HW Checksum error */
2231 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2232 SK_DBGCAT_DRV_RX_PROGRESS,
2233 ("skge: CRC error. Frame dropped!\n"));
2234 goto rx_failed;
2235 } else {
2236 pMsg->ip_summed =
2237 CHECKSUM_NONE;
2239 }/* checksumControl calculation valid */
2240 } /* Frame length check */
2241 } /* IP frame */
2242 #else
2243 pMsg->ip_summed = CHECKSUM_NONE;
2244 #endif
2245 } /* frame > SK_COPY_TRESHOLD */
2247 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2248 ForRlmt = SK_RLMT_RX_PROTOCOL;
2249 #if 0
2250 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2251 #endif
2252 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2253 IsBc, &Offset, &NumBytes);
2254 if (NumBytes != 0) {
2255 #if 0
2256 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2257 #endif
2258 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2259 &pMsg->data[Offset],
2260 IsBc, IsMc, &ForRlmt);
2262 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2263 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2264 /* send up only frames from active port */
2265 if ((PortIndex == pAC->ActivePort) ||
2266 (pAC->RlmtNets == 2)) {
2267 /* frame for upper layer */
2268 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2269 #ifdef xDEBUG
2270 DumpMsg(pMsg, "Rx");
2271 #endif
2272 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2273 FrameLength, pRxPort->PortIndex);
2275 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2276 pMsg->protocol = eth_type_trans(pMsg,
2277 pAC->dev[pRxPort->PortIndex]);
2278 netif_rx(pMsg);
2279 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2281 else {
2282 /* drop frame */
2283 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2284 SK_DBGCAT_DRV_RX_PROGRESS,
2285 ("D"));
2286 DEV_KFREE_SKB(pMsg);
2289 } /* if not for rlmt */
2290 else {
2291 /* packet for rlmt */
2292 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2293 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2294 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2295 pAC->IoBase, FrameLength);
2296 if (pRlmtMbuf != NULL) {
2297 pRlmtMbuf->pNext = NULL;
2298 pRlmtMbuf->Length = FrameLength;
2299 pRlmtMbuf->PortIdx = PortIndex;
2300 EvPara.pParaPtr = pRlmtMbuf;
2301 memcpy((char*)(pRlmtMbuf->pData),
2302 (char*)(pMsg->data),
2303 FrameLength);
2305 /* SlowPathLock needed? */
2306 if (SlowPathLock == SK_TRUE) {
2307 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2308 SkEventQueue(pAC, SKGE_RLMT,
2309 SK_RLMT_PACKET_RECEIVED,
2310 EvPara);
2311 pAC->CheckQueue = SK_TRUE;
2312 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2313 } else {
2314 SkEventQueue(pAC, SKGE_RLMT,
2315 SK_RLMT_PACKET_RECEIVED,
2316 EvPara);
2317 pAC->CheckQueue = SK_TRUE;
2320 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2321 SK_DBGCAT_DRV_RX_PROGRESS,
2322 ("Q"));
2324 if ((pAC->dev[pRxPort->PortIndex]->flags &
2325 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2326 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2327 SK_RLMT_RX_PROTOCOL) {
2328 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2329 pMsg->protocol = eth_type_trans(pMsg,
2330 pAC->dev[pRxPort->PortIndex]);
2331 netif_rx(pMsg);
2332 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2334 else {
2335 DEV_KFREE_SKB(pMsg);
2338 } /* if packet for rlmt */
2339 } /* for ... scanning the RXD ring */
2341 /* RXD ring is empty -> fill and restart */
2342 FillRxRing(pAC, pRxPort);
2343 /* do not start if called from Close */
2344 if (pAC->BoardLevel > SK_INIT_DATA) {
2345 ClearAndStartRx(pAC, PortIndex);
2347 return;
2349 rx_failed:
2350 /* remove error frame */
2351 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2352 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2354 /* release the DMA mapping */
2356 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2357 PhysAddr |= (SK_U64) pRxd->VDataLow;
2358 pci_unmap_page(pAC->PciDev,
2359 PhysAddr,
2360 pAC->RxBufSize - 2,
2361 PCI_DMA_FROMDEVICE);
2362 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2363 pRxd->pMBuf = NULL;
2364 pRxPort->RxdRingFree++;
2365 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2366 goto rx_start;
2368 } /* ReceiveIrq */
2371 /*****************************************************************************
2373 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2375 * Description:
2376 * This function sends a start command and a clear interrupt
2377 * command for one receive queue to the BMU.
2379 * Returns: N/A
2380 * none
2382 static void ClearAndStartRx(
2383 SK_AC *pAC, /* pointer to the adapter context */
2384 int PortIndex) /* index of the receive port (XMAC) */
2386 SK_OUT8(pAC->IoBase,
2387 RxQueueAddr[PortIndex]+Q_CSR,
2388 CSR_START | CSR_IRQ_CL_F);
2389 } /* ClearAndStartRx */
2392 /*****************************************************************************
2394 * ClearTxIrq - give a clear transmit IRQ command to BMU
2396 * Description:
2397 * This function sends a clear tx IRQ command for one
2398 * transmit queue to the BMU.
2400 * Returns: N/A
2402 static void ClearTxIrq(
2403 SK_AC *pAC, /* pointer to the adapter context */
2404 int PortIndex, /* index of the transmit port (XMAC) */
2405 int Prio) /* priority or normal queue */
2407 SK_OUT8(pAC->IoBase,
2408 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2409 CSR_IRQ_CL_F);
2410 } /* ClearTxIrq */
2413 /*****************************************************************************
2415 * ClearRxRing - remove all buffers from the receive ring
2417 * Description:
2418 * This function removes all receive buffers from the ring.
2419 * The receive BMU must be stopped before calling this function.
2421 * Returns: N/A
2423 static void ClearRxRing(
2424 SK_AC *pAC, /* pointer to adapter context */
2425 RX_PORT *pRxPort) /* pointer to rx port struct */
2427 RXD *pRxd; /* pointer to the current descriptor */
2428 unsigned long Flags;
2429 SK_U64 PhysAddr;
2431 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2432 return;
2434 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2435 pRxd = pRxPort->pRxdRingHead;
2436 do {
2437 if (pRxd->pMBuf != NULL) {
2439 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2440 PhysAddr |= (SK_U64) pRxd->VDataLow;
2441 pci_unmap_page(pAC->PciDev,
2442 PhysAddr,
2443 pAC->RxBufSize - 2,
2444 PCI_DMA_FROMDEVICE);
2445 DEV_KFREE_SKB(pRxd->pMBuf);
2446 pRxd->pMBuf = NULL;
2448 pRxd->RBControl &= BMU_OWN;
2449 pRxd = pRxd->pNextRxd;
2450 pRxPort->RxdRingFree++;
2451 } while (pRxd != pRxPort->pRxdRingTail);
2452 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2453 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2454 } /* ClearRxRing */
2456 /*****************************************************************************
2458 * ClearTxRing - remove all buffers from the transmit ring
2460 * Description:
2461 * This function removes all transmit buffers from the ring.
2462 * The transmit BMU must be stopped before calling this function
2463 * and transmitting at the upper level must be disabled.
2464 * The BMU own bit of all descriptors is cleared, the rest is
2465 * done by calling FreeTxDescriptors.
2467 * Returns: N/A
2469 static void ClearTxRing(
2470 SK_AC *pAC, /* pointer to adapter context */
2471 TX_PORT *pTxPort) /* pointer to tx prt struct */
2473 TXD *pTxd; /* pointer to the current descriptor */
2474 int i;
2475 unsigned long Flags;
2477 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2478 pTxd = pTxPort->pTxdRingHead;
2479 for (i=0; i<pAC->TxDescrPerRing; i++) {
2480 pTxd->TBControl &= ~BMU_OWN;
2481 pTxd = pTxd->pNextTxd;
2483 FreeTxDescriptors(pAC, pTxPort);
2484 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2485 } /* ClearTxRing */
2487 /*****************************************************************************
2489 * SkGeSetMacAddr - Set the hardware MAC address
2491 * Description:
2492 * This function sets the MAC address used by the adapter.
2494 * Returns:
2495 * 0, if everything is ok
2496 * !=0, on error
2498 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2501 DEV_NET *pNet = (DEV_NET*) dev->priv;
2502 SK_AC *pAC = pNet->pAC;
2504 struct sockaddr *addr = p;
2505 unsigned long Flags;
2507 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2508 ("SkGeSetMacAddr starts now...\n"));
2509 if(netif_running(dev))
2510 return -EBUSY;
2512 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2514 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2516 if (pAC->RlmtNets == 2)
2517 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2518 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2519 else
2520 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2521 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2525 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2526 return 0;
2527 } /* SkGeSetMacAddr */
2530 /*****************************************************************************
2532 * SkGeSetRxMode - set receive mode
2534 * Description:
2535 * This function sets the receive mode of an adapter. The adapter
2536 * supports promiscuous mode, allmulticast mode and a number of
2537 * multicast addresses. If more multicast addresses the available
2538 * are selected, a hash function in the hardware is used.
2540 * Returns:
2541 * 0, if everything is ok
2542 * !=0, on error
2544 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2547 DEV_NET *pNet;
2548 SK_AC *pAC;
2550 struct dev_mc_list *pMcList;
2551 int i;
2552 int PortIdx;
2553 unsigned long Flags;
2555 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2556 ("SkGeSetRxMode starts now... "));
2558 pNet = (DEV_NET*) dev->priv;
2559 pAC = pNet->pAC;
2560 if (pAC->RlmtNets == 1)
2561 PortIdx = pAC->ActivePort;
2562 else
2563 PortIdx = pNet->NetNr;
2565 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2566 if (dev->flags & IFF_PROMISC) {
2567 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2568 ("PROMISCUOUS mode\n"));
2569 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2570 SK_PROM_MODE_LLC);
2571 } else if (dev->flags & IFF_ALLMULTI) {
2572 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2573 ("ALLMULTI mode\n"));
2574 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2575 SK_PROM_MODE_ALL_MC);
2576 } else {
2577 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2578 SK_PROM_MODE_NONE);
2579 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2581 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2582 ("Number of MC entries: %d ", dev->mc_count));
2584 pMcList = dev->mc_list;
2585 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2586 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2587 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2588 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2589 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2590 pMcList->dmi_addr[0],
2591 pMcList->dmi_addr[1],
2592 pMcList->dmi_addr[2],
2593 pMcList->dmi_addr[3],
2594 pMcList->dmi_addr[4],
2595 pMcList->dmi_addr[5]));
2597 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2599 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2601 return;
2602 } /* SkGeSetRxMode */
2605 /*****************************************************************************
2607 * SkGeChangeMtu - set the MTU to another value
2609 * Description:
2610 * This function sets is called whenever the MTU size is changed
2611 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2612 * ethernet MTU size, long frame support is activated.
2614 * Returns:
2615 * 0, if everything is ok
2616 * !=0, on error
2618 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2620 DEV_NET *pNet;
2621 DEV_NET *pOtherNet;
2622 SK_AC *pAC;
2623 unsigned long Flags;
2624 int i;
2625 SK_EVPARA EvPara;
2627 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2628 ("SkGeChangeMtu starts now...\n"));
2630 pNet = (DEV_NET*) dev->priv;
2631 pAC = pNet->pAC;
2633 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2634 return -EINVAL;
2637 if(pAC->BoardLevel != SK_INIT_RUN) {
2638 return -EINVAL;
2641 #ifdef SK_DIAG_SUPPORT
2642 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2643 if (pAC->DiagFlowCtrl == SK_FALSE) {
2644 return -1; /* still in use, deny any actions of MTU */
2645 } else {
2646 pAC->DiagFlowCtrl = SK_FALSE;
2649 #endif
2651 pNet->Mtu = NewMtu;
2652 pOtherNet = (DEV_NET*)pAC->dev[1 - pNet->NetNr]->priv;
2653 if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
2654 return(0);
2657 pAC->RxBufSize = NewMtu + 32;
2658 dev->mtu = NewMtu;
2660 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2661 ("New MTU: %d\n", NewMtu));
2664 ** Prevent any reconfiguration while changing the MTU
2665 ** by disabling any interrupts
2667 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2668 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2671 ** Notify RLMT that any ports are to be stopped
2673 EvPara.Para32[0] = 0;
2674 EvPara.Para32[1] = -1;
2675 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2676 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2677 EvPara.Para32[0] = 1;
2678 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2679 } else {
2680 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2684 ** After calling the SkEventDispatcher(), RLMT is aware about
2685 ** the stopped ports -> configuration can take place!
2687 SkEventDispatcher(pAC, pAC->IoBase);
2689 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2690 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2691 netif_stop_queue(pAC->dev[i]);
2696 ** Depending on the desired MTU size change, a different number of
2697 ** RX buffers need to be allocated
2699 if (NewMtu > 1500) {
2701 ** Use less rx buffers
2703 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2704 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2705 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2706 (pAC->RxDescrPerRing / 4);
2707 } else {
2708 if (i == pAC->ActivePort) {
2709 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2710 (pAC->RxDescrPerRing / 4);
2711 } else {
2712 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2713 (pAC->RxDescrPerRing / 10);
2717 } else {
2719 ** Use the normal amount of rx buffers
2721 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2722 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2723 pAC->RxPort[i].RxFillLimit = 1;
2724 } else {
2725 if (i == pAC->ActivePort) {
2726 pAC->RxPort[i].RxFillLimit = 1;
2727 } else {
2728 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2729 (pAC->RxDescrPerRing / 4);
2735 SkGeDeInit(pAC, pAC->IoBase);
2738 ** enable/disable hardware support for long frames
2740 if (NewMtu > 1500) {
2741 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2742 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2743 } else {
2744 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2745 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2746 } else {
2747 pAC->GIni.GIPortUsage = SK_RED_LINK;
2751 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2752 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2753 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2754 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2755 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2756 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2757 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2760 ** tschilling:
2761 ** Speed and others are set back to default in level 1 init!
2763 GetConfiguration(pAC);
2765 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2766 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2767 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2768 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2769 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2770 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2771 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2774 ** clear and reinit the rx rings here
2776 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2777 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2778 ClearRxRing(pAC, &pAC->RxPort[i]);
2779 FillRxRing(pAC, &pAC->RxPort[i]);
2782 ** Enable transmit descriptor polling
2784 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2785 FillRxRing(pAC, &pAC->RxPort[i]);
2788 SkGeYellowLED(pAC, pAC->IoBase, 1);
2789 SkDimEnableModerationIfNeeded(pAC);
2790 SkDimDisplayModerationSettings(pAC);
2792 netif_start_queue(pAC->dev[pNet->PortNr]);
2793 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2794 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2798 ** Enable Interrupts again
2800 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2801 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2803 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2804 SkEventDispatcher(pAC, pAC->IoBase);
2807 ** Notify RLMT about the changing and restarting one (or more) ports
2809 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2810 EvPara.Para32[0] = pAC->RlmtNets;
2811 EvPara.Para32[1] = -1;
2812 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2813 EvPara.Para32[0] = pNet->PortNr;
2814 EvPara.Para32[1] = -1;
2815 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2817 if (pOtherNet->Up) {
2818 EvPara.Para32[0] = pOtherNet->PortNr;
2819 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2821 } else {
2822 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2825 SkEventDispatcher(pAC, pAC->IoBase);
2826 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2829 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2830 ** seems as if upper layers have a problem to handle a successful
2831 ** return value of '0'. If such a zero is returned, the complete
2832 ** system hangs for several minutes (!), which is in acceptable.
2834 ** Currently it is not clear, what the exact reason for this problem
2835 ** is. The implemented workaround for 2.5 is to return the desired
2836 ** new MTU size if all needed changes for the new MTU size where
2837 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2838 ** which indicates the successful change of the mtu-size.
2840 return NewMtu;
2842 } /* SkGeChangeMtu */
2845 /*****************************************************************************
2847 * SkGeStats - return ethernet device statistics
2849 * Description:
2850 * This function return statistic data about the ethernet device
2851 * to the operating system.
2853 * Returns:
2854 * pointer to the statistic structure.
2856 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2858 DEV_NET *pNet = (DEV_NET*) dev->priv;
2859 SK_AC *pAC = pNet->pAC;
2860 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2861 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2862 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2863 unsigned int Size; /* size of pnmi struct */
2864 unsigned long Flags; /* for spin lock */
2866 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2867 ("SkGeStats starts now...\n"));
2868 pPnmiStruct = &pAC->PnmiStruct;
2870 #ifdef SK_DIAG_SUPPORT
2871 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2872 (pAC->BoardLevel == SK_INIT_RUN)) {
2873 #endif
2874 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2875 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2876 Size = SK_PNMI_STRUCT_SIZE;
2877 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2878 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2879 #ifdef SK_DIAG_SUPPORT
2881 #endif
2883 pPnmiStat = &pPnmiStruct->Stat[0];
2884 pPnmiConf = &pPnmiStruct->Conf[0];
2886 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2887 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2888 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2889 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2891 if (pNet->Mtu <= 1500) {
2892 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2893 } else {
2894 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2895 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2899 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2900 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2902 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2903 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2904 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2905 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2906 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2908 /* detailed rx_errors: */
2909 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2910 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2911 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2912 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2913 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2914 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2916 /* detailed tx_errors */
2917 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2918 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2919 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2920 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2921 pAC->stats.tx_window_errors = (SK_U32) 0;
2923 return(&pAC->stats);
2924 } /* SkGeStats */
2927 /*****************************************************************************
2929 * SkGeIoctl - IO-control function
2931 * Description:
2932 * This function is called if an ioctl is issued on the device.
2933 * There are three subfunction for reading, writing and test-writing
2934 * the private MIB data structure (usefull for SysKonnect-internal tools).
2936 * Returns:
2937 * 0, if everything is ok
2938 * !=0, on error
2940 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2942 DEV_NET *pNet;
2943 SK_AC *pAC;
2944 void *pMemBuf;
2945 struct pci_dev *pdev = NULL;
2946 SK_GE_IOCTL Ioctl;
2947 unsigned int Err = 0;
2948 int Size = 0;
2949 int Ret = 0;
2950 unsigned int Length = 0;
2951 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2953 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2954 ("SkGeIoctl starts now...\n"));
2956 pNet = (DEV_NET*) dev->priv;
2957 pAC = pNet->pAC;
2959 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2960 return -EFAULT;
2963 switch(cmd) {
2964 case SK_IOCTL_SETMIB:
2965 case SK_IOCTL_PRESETMIB:
2966 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2967 case SK_IOCTL_GETMIB:
2968 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2969 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2970 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2971 return -EFAULT;
2973 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2974 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2975 Ioctl.Len<Size? Ioctl.Len : Size)) {
2976 return -EFAULT;
2978 Ioctl.Len = Size;
2979 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2980 return -EFAULT;
2982 break;
2983 case SK_IOCTL_GEN:
2984 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2985 Length = Ioctl.Len;
2986 } else {
2987 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2989 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2990 return -ENOMEM;
2992 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2993 Err = -EFAULT;
2994 goto fault_gen;
2996 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2997 Err = -EFAULT;
2998 goto fault_gen;
3000 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3001 Err = -EFAULT;
3002 goto fault_gen;
3004 Ioctl.Len = Length;
3005 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3006 Err = -EFAULT;
3007 goto fault_gen;
3009 fault_gen:
3010 kfree(pMemBuf); /* cleanup everything */
3011 break;
3012 #ifdef SK_DIAG_SUPPORT
3013 case SK_IOCTL_DIAG:
3014 if (!capable(CAP_NET_ADMIN)) return -EPERM;
3015 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3016 Length = Ioctl.Len;
3017 } else {
3018 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3020 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3021 return -ENOMEM;
3023 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3024 Err = -EFAULT;
3025 goto fault_diag;
3027 pdev = pAC->PciDev;
3028 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
3030 ** While coding this new IOCTL interface, only a few lines of code
3031 ** are to to be added. Therefore no dedicated function has been
3032 ** added. If more functionality is added, a separate function
3033 ** should be used...
3035 * ((SK_U32 *)pMemBuf) = 0;
3036 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
3037 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pdev->slot_name);
3038 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3039 Err = -EFAULT;
3040 goto fault_diag;
3042 Ioctl.Len = Length;
3043 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3044 Err = -EFAULT;
3045 goto fault_diag;
3047 fault_diag:
3048 kfree(pMemBuf); /* cleanup everything */
3049 break;
3050 #endif
3051 default:
3052 Err = -EOPNOTSUPP;
3055 return(Err);
3057 } /* SkGeIoctl */
3060 /*****************************************************************************
3062 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3064 * Description:
3065 * This function reads/writes the MIB data using PNMI (Private Network
3066 * Management Interface).
3067 * The destination for the data must be provided with the
3068 * ioctl call and is given to the driver in the form of
3069 * a user space address.
3070 * Copying from the user-provided data area into kernel messages
3071 * and back is done by copy_from_user and copy_to_user calls in
3072 * SkGeIoctl.
3074 * Returns:
3075 * returned size from PNMI call
3077 static int SkGeIocMib(
3078 DEV_NET *pNet, /* pointer to the adapter context */
3079 unsigned int Size, /* length of ioctl data */
3080 int mode) /* flag for set/preset */
3082 unsigned long Flags; /* for spin lock */
3083 SK_AC *pAC;
3085 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3086 ("SkGeIocMib starts now...\n"));
3087 pAC = pNet->pAC;
3088 /* access MIB */
3089 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3090 switch(mode) {
3091 case SK_IOCTL_GETMIB:
3092 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3093 pNet->NetNr);
3094 break;
3095 case SK_IOCTL_PRESETMIB:
3096 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3097 pNet->NetNr);
3098 break;
3099 case SK_IOCTL_SETMIB:
3100 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3101 pNet->NetNr);
3102 break;
3103 default:
3104 break;
3106 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3107 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3108 ("MIB data access succeeded\n"));
3109 return (Size);
3110 } /* SkGeIocMib */
3113 /*****************************************************************************
3115 * GetConfiguration - read configuration information
3117 * Description:
3118 * This function reads per-adapter configuration information from
3119 * the options provided on the command line.
3121 * Returns:
3122 * none
3124 static void GetConfiguration(
3125 SK_AC *pAC) /* pointer to the adapter context structure */
3127 SK_I32 Port; /* preferred port */
3128 SK_BOOL AutoSet;
3129 SK_BOOL DupSet;
3130 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3131 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3132 int DuplexCap = 0; /* 0=both,1=full,2=half */
3133 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3134 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3136 SK_BOOL IsConTypeDefined = SK_TRUE;
3137 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3138 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3139 SK_BOOL IsRoleDefined = SK_TRUE;
3140 SK_BOOL IsModeDefined = SK_TRUE;
3142 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3143 * parameter. The mapping is described by this table:
3144 * DuplexCap -> | both | full | half |
3145 * AutoNeg | | | |
3146 * -----------------------------------------------------------------
3147 * Off | illegal | Full | Half |
3148 * -----------------------------------------------------------------
3149 * On | AutoBoth | AutoFull | AutoHalf |
3150 * -----------------------------------------------------------------
3151 * Sense | AutoSense | AutoSense | AutoSense |
3153 int Capabilities[3][3] =
3154 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3155 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3156 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3158 #define DC_BOTH 0
3159 #define DC_FULL 1
3160 #define DC_HALF 2
3161 #define AN_OFF 0
3162 #define AN_ON 1
3163 #define AN_SENS 2
3164 #define M_CurrPort pAC->GIni.GP[Port]
3168 ** Set the default values first for both ports!
3170 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3171 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3172 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3173 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3174 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3178 ** Check merged parameter ConType. If it has not been used,
3179 ** verify any other parameter (e.g. AutoNeg) and use default values.
3181 ** Stating both ConType and other lowlevel link parameters is also
3182 ** possible. If this is the case, the passed ConType-parameter is
3183 ** overwritten by the lowlevel link parameter.
3185 ** The following settings are used for a merged ConType-parameter:
3187 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3188 ** ------- ------ ------- -------- ---------- -----
3189 ** Auto Both On SymOrRem Auto Auto
3190 ** 100FD Full Off None <ignored> 100
3191 ** 100HD Half Off None <ignored> 100
3192 ** 10FD Full Off None <ignored> 10
3193 ** 10HD Half Off None <ignored> 10
3195 ** This ConType parameter is used for all ports of the adapter!
3197 if ( (ConType != NULL) &&
3198 (pAC->Index < SK_MAX_CARD_PARAM) &&
3199 (ConType[pAC->Index] != NULL) ) {
3201 /* Check chipset family */
3202 if ((!pAC->ChipsetType) &&
3203 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3204 (strcmp(ConType[pAC->Index],"")!=0)) {
3205 /* Set the speed parameter back */
3206 printk("sk98lin: Illegal value \"%s\" "
3207 "for ConType."
3208 " Using Auto.\n",
3209 ConType[pAC->Index]);
3211 sprintf(ConType[pAC->Index], "Auto");
3214 if (strcmp(ConType[pAC->Index],"")==0) {
3215 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3216 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3217 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3218 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3219 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3220 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3221 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3223 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3224 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3225 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3226 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3227 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3228 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3230 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3231 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3232 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3233 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3234 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3235 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3237 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3238 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3239 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3240 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3241 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3242 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3244 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3245 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3246 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3247 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3248 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3249 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3251 } else {
3252 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3253 ConType[pAC->Index]);
3254 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3256 } else {
3257 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3261 ** Parse any parameter settings for port A:
3262 ** a) any LinkSpeed stated?
3264 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3265 Speed_A[pAC->Index] != NULL) {
3266 if (strcmp(Speed_A[pAC->Index],"")==0) {
3267 IsLinkSpeedDefined = SK_FALSE;
3268 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3269 LinkSpeed = SK_LSPEED_AUTO;
3270 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3271 LinkSpeed = SK_LSPEED_10MBPS;
3272 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3273 LinkSpeed = SK_LSPEED_100MBPS;
3274 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3275 LinkSpeed = SK_LSPEED_1000MBPS;
3276 } else {
3277 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3278 Speed_A[pAC->Index]);
3279 IsLinkSpeedDefined = SK_FALSE;
3281 } else {
3282 IsLinkSpeedDefined = SK_FALSE;
3286 ** Check speed parameter:
3287 ** Only copper type adapter and GE V2 cards
3289 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3290 ((LinkSpeed != SK_LSPEED_AUTO) &&
3291 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3292 printk("sk98lin: Illegal value for Speed_A. "
3293 "Not a copper card or GE V2 card\n Using "
3294 "speed 1000\n");
3295 LinkSpeed = SK_LSPEED_1000MBPS;
3299 ** Decide whether to set new config value if somethig valid has
3300 ** been received.
3302 if (IsLinkSpeedDefined) {
3303 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3307 ** b) Any Autonegotiation and DuplexCapabilities set?
3308 ** Please note that both belong together...
3310 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3311 AutoSet = SK_FALSE;
3312 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3313 AutoNeg_A[pAC->Index] != NULL) {
3314 AutoSet = SK_TRUE;
3315 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3316 AutoSet = SK_FALSE;
3317 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3318 AutoNeg = AN_ON;
3319 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3320 AutoNeg = AN_OFF;
3321 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3322 AutoNeg = AN_SENS;
3323 } else {
3324 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3325 AutoNeg_A[pAC->Index]);
3329 DuplexCap = DC_BOTH;
3330 DupSet = SK_FALSE;
3331 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3332 DupCap_A[pAC->Index] != NULL) {
3333 DupSet = SK_TRUE;
3334 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3335 DupSet = SK_FALSE;
3336 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3337 DuplexCap = DC_BOTH;
3338 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3339 DuplexCap = DC_FULL;
3340 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3341 DuplexCap = DC_HALF;
3342 } else {
3343 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3344 DupCap_A[pAC->Index]);
3349 ** Check for illegal combinations
3351 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3352 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3353 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3354 (pAC->ChipsetType)) {
3355 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3356 " Using Full Duplex.\n");
3357 DuplexCap = DC_FULL;
3360 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3361 printk("sk98lin, Port A: DuplexCapabilities"
3362 " ignored using Sense mode\n");
3365 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3366 printk("sk98lin: Port A: Illegal combination"
3367 " of values AutoNeg. and DuplexCap.\n Using "
3368 "Full Duplex\n");
3369 DuplexCap = DC_FULL;
3372 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3373 DuplexCap = DC_FULL;
3376 if (!AutoSet && DupSet) {
3377 printk("sk98lin: Port A: Duplex setting not"
3378 " possible in\n default AutoNegotiation mode"
3379 " (Sense).\n Using AutoNegotiation On\n");
3380 AutoNeg = AN_ON;
3384 ** set the desired mode
3386 if (AutoSet || DupSet) {
3387 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3391 ** c) Any Flowcontrol-parameter set?
3393 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3394 FlowCtrl_A[pAC->Index] != NULL) {
3395 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3396 IsFlowCtrlDefined = SK_FALSE;
3397 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3398 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3399 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3400 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3401 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3402 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3403 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3404 FlowCtrl = SK_FLOW_MODE_NONE;
3405 } else {
3406 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3407 FlowCtrl_A[pAC->Index]);
3408 IsFlowCtrlDefined = SK_FALSE;
3410 } else {
3411 IsFlowCtrlDefined = SK_FALSE;
3414 if (IsFlowCtrlDefined) {
3415 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3416 printk("sk98lin: Port A: FlowControl"
3417 " impossible without AutoNegotiation,"
3418 " disabled\n");
3419 FlowCtrl = SK_FLOW_MODE_NONE;
3421 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3425 ** d) What is with the RoleParameter?
3427 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3428 Role_A[pAC->Index] != NULL) {
3429 if (strcmp(Role_A[pAC->Index],"")==0) {
3430 IsRoleDefined = SK_FALSE;
3431 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3432 MSMode = SK_MS_MODE_AUTO;
3433 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3434 MSMode = SK_MS_MODE_MASTER;
3435 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3436 MSMode = SK_MS_MODE_SLAVE;
3437 } else {
3438 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3439 Role_A[pAC->Index]);
3440 IsRoleDefined = SK_FALSE;
3442 } else {
3443 IsRoleDefined = SK_FALSE;
3446 if (IsRoleDefined == SK_TRUE) {
3447 pAC->GIni.GP[0].PMSMode = MSMode;
3453 ** Parse any parameter settings for port B:
3454 ** a) any LinkSpeed stated?
3456 IsConTypeDefined = SK_TRUE;
3457 IsLinkSpeedDefined = SK_TRUE;
3458 IsFlowCtrlDefined = SK_TRUE;
3459 IsModeDefined = SK_TRUE;
3461 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3462 Speed_B[pAC->Index] != NULL) {
3463 if (strcmp(Speed_B[pAC->Index],"")==0) {
3464 IsLinkSpeedDefined = SK_FALSE;
3465 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3466 LinkSpeed = SK_LSPEED_AUTO;
3467 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3468 LinkSpeed = SK_LSPEED_10MBPS;
3469 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3470 LinkSpeed = SK_LSPEED_100MBPS;
3471 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3472 LinkSpeed = SK_LSPEED_1000MBPS;
3473 } else {
3474 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3475 Speed_B[pAC->Index]);
3476 IsLinkSpeedDefined = SK_FALSE;
3478 } else {
3479 IsLinkSpeedDefined = SK_FALSE;
3483 ** Check speed parameter:
3484 ** Only copper type adapter and GE V2 cards
3486 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3487 ((LinkSpeed != SK_LSPEED_AUTO) &&
3488 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3489 printk("sk98lin: Illegal value for Speed_B. "
3490 "Not a copper card or GE V2 card\n Using "
3491 "speed 1000\n");
3492 LinkSpeed = SK_LSPEED_1000MBPS;
3496 ** Decide whether to set new config value if somethig valid has
3497 ** been received.
3499 if (IsLinkSpeedDefined) {
3500 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3504 ** b) Any Autonegotiation and DuplexCapabilities set?
3505 ** Please note that both belong together...
3507 AutoNeg = AN_SENS; /* default: do auto Sense */
3508 AutoSet = SK_FALSE;
3509 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3510 AutoNeg_B[pAC->Index] != NULL) {
3511 AutoSet = SK_TRUE;
3512 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3513 AutoSet = SK_FALSE;
3514 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3515 AutoNeg = AN_ON;
3516 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3517 AutoNeg = AN_OFF;
3518 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3519 AutoNeg = AN_SENS;
3520 } else {
3521 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3522 AutoNeg_B[pAC->Index]);
3526 DuplexCap = DC_BOTH;
3527 DupSet = SK_FALSE;
3528 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3529 DupCap_B[pAC->Index] != NULL) {
3530 DupSet = SK_TRUE;
3531 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3532 DupSet = SK_FALSE;
3533 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3534 DuplexCap = DC_BOTH;
3535 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3536 DuplexCap = DC_FULL;
3537 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3538 DuplexCap = DC_HALF;
3539 } else {
3540 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3541 DupCap_B[pAC->Index]);
3547 ** Check for illegal combinations
3549 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3550 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3551 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3552 (pAC->ChipsetType)) {
3553 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3554 " Using Full Duplex.\n");
3555 DuplexCap = DC_FULL;
3558 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3559 printk("sk98lin, Port B: DuplexCapabilities"
3560 " ignored using Sense mode\n");
3563 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3564 printk("sk98lin: Port B: Illegal combination"
3565 " of values AutoNeg. and DuplexCap.\n Using "
3566 "Full Duplex\n");
3567 DuplexCap = DC_FULL;
3570 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3571 DuplexCap = DC_FULL;
3574 if (!AutoSet && DupSet) {
3575 printk("sk98lin: Port B: Duplex setting not"
3576 " possible in\n default AutoNegotiation mode"
3577 " (Sense).\n Using AutoNegotiation On\n");
3578 AutoNeg = AN_ON;
3582 ** set the desired mode
3584 if (AutoSet || DupSet) {
3585 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3589 ** c) Any FlowCtrl parameter set?
3591 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3592 FlowCtrl_B[pAC->Index] != NULL) {
3593 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3594 IsFlowCtrlDefined = SK_FALSE;
3595 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3596 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3597 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3598 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3599 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3600 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3601 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3602 FlowCtrl = SK_FLOW_MODE_NONE;
3603 } else {
3604 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3605 FlowCtrl_B[pAC->Index]);
3606 IsFlowCtrlDefined = SK_FALSE;
3608 } else {
3609 IsFlowCtrlDefined = SK_FALSE;
3612 if (IsFlowCtrlDefined) {
3613 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3614 printk("sk98lin: Port B: FlowControl"
3615 " impossible without AutoNegotiation,"
3616 " disabled\n");
3617 FlowCtrl = SK_FLOW_MODE_NONE;
3619 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3623 ** d) What is the RoleParameter?
3625 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3626 Role_B[pAC->Index] != NULL) {
3627 if (strcmp(Role_B[pAC->Index],"")==0) {
3628 IsRoleDefined = SK_FALSE;
3629 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3630 MSMode = SK_MS_MODE_AUTO;
3631 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3632 MSMode = SK_MS_MODE_MASTER;
3633 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3634 MSMode = SK_MS_MODE_SLAVE;
3635 } else {
3636 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3637 Role_B[pAC->Index]);
3638 IsRoleDefined = SK_FALSE;
3640 } else {
3641 IsRoleDefined = SK_FALSE;
3644 if (IsRoleDefined) {
3645 pAC->GIni.GP[1].PMSMode = MSMode;
3649 ** Evaluate settings for both ports
3651 pAC->ActivePort = 0;
3652 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3653 PrefPort[pAC->Index] != NULL) {
3654 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3655 pAC->ActivePort = 0;
3656 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3657 pAC->Rlmt.Net[0].PrefPort = 0;
3658 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3660 ** do not set ActivePort here, thus a port
3661 ** switch is issued after net up.
3663 Port = 0;
3664 pAC->Rlmt.Net[0].Preference = Port;
3665 pAC->Rlmt.Net[0].PrefPort = Port;
3666 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3668 ** do not set ActivePort here, thus a port
3669 ** switch is issued after net up.
3671 if (pAC->GIni.GIMacsFound == 1) {
3672 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3673 " Port B not available on single port adapters.\n");
3675 pAC->ActivePort = 0;
3676 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3677 pAC->Rlmt.Net[0].PrefPort = 0;
3678 } else {
3679 Port = 1;
3680 pAC->Rlmt.Net[0].Preference = Port;
3681 pAC->Rlmt.Net[0].PrefPort = Port;
3683 } else {
3684 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3685 PrefPort[pAC->Index]);
3689 pAC->RlmtNets = 1;
3691 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3692 RlmtMode[pAC->Index] != NULL) {
3693 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3694 pAC->RlmtMode = 0;
3695 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3696 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3697 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3698 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3699 SK_RLMT_CHECK_LOC_LINK;
3700 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3701 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3702 SK_RLMT_CHECK_LOC_LINK |
3703 SK_RLMT_CHECK_SEG;
3704 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3705 (pAC->GIni.GIMacsFound == 2)) {
3706 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3707 pAC->RlmtNets = 2;
3708 } else {
3709 printk("sk98lin: Illegal value \"%s\" for"
3710 " RlmtMode, using default\n",
3711 RlmtMode[pAC->Index]);
3712 pAC->RlmtMode = 0;
3714 } else {
3715 pAC->RlmtMode = 0;
3719 ** Check the interrupt moderation parameters
3721 if (Moderation[pAC->Index] != NULL) {
3722 if (strcmp(Moderation[pAC->Index], "") == 0) {
3723 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3724 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3725 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3726 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3727 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3728 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3729 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3730 } else {
3731 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3732 " Disable interrupt moderation.\n",
3733 Moderation[pAC->Index]);
3734 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3736 } else {
3737 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3740 if (Stats[pAC->Index] != NULL) {
3741 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3742 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3743 } else {
3744 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3746 } else {
3747 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3750 if (ModerationMask[pAC->Index] != NULL) {
3751 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3752 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3753 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3754 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3755 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3756 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3757 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3758 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3759 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3760 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3761 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3762 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3763 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3764 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3765 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3766 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3767 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3768 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3769 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3770 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3771 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3772 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3773 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3774 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3775 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3776 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3777 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3778 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3779 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3780 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3781 } else { /* some rubbish */
3782 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3784 } else { /* operator has stated nothing */
3785 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3788 if (AutoSizing[pAC->Index] != NULL) {
3789 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3790 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3791 } else {
3792 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3794 } else { /* operator has stated nothing */
3795 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3798 if (IntsPerSec[pAC->Index] != 0) {
3799 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3800 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3801 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3802 " Using default value of %i.\n",
3803 IntsPerSec[pAC->Index],
3804 C_INT_MOD_IPS_LOWER_RANGE,
3805 C_INT_MOD_IPS_UPPER_RANGE,
3806 C_INTS_PER_SEC_DEFAULT);
3807 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3808 } else {
3809 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3811 } else {
3812 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3816 ** Evaluate upper and lower moderation threshold
3818 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3819 pAC->DynIrqModInfo.MaxModIntsPerSec +
3820 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3822 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3823 pAC->DynIrqModInfo.MaxModIntsPerSec -
3824 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3826 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3829 } /* GetConfiguration */
3832 /*****************************************************************************
3834 * ProductStr - return a adapter identification string from vpd
3836 * Description:
3837 * This function reads the product name string from the vpd area
3838 * and puts it the field pAC->DeviceString.
3840 * Returns: N/A
3842 static void ProductStr(
3843 SK_AC *pAC /* pointer to adapter context */
3846 int StrLen = 80; /* length of the string, defined in SK_AC */
3847 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3848 int ReturnCode; /* return code from vpd_read */
3849 unsigned long Flags;
3851 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3852 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3853 &StrLen);
3854 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3855 if (ReturnCode != 0) {
3856 /* there was an error reading the vpd data */
3857 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3858 ("Error reading VPD data: %d\n", ReturnCode));
3859 pAC->DeviceStr[0] = '\0';
3861 } /* ProductStr */
3863 /*****************************************************************************
3865 * StartDrvCleanupTimer - Start timer to check for descriptors which
3866 * might be placed in descriptor ring, but
3867 * havent been handled up to now
3869 * Description:
3870 * This function requests a HW-timer fo the Yukon card. The actions to
3871 * perform when this timer expires, are located in the SkDrvEvent().
3873 * Returns: N/A
3875 static void
3876 StartDrvCleanupTimer(SK_AC *pAC) {
3877 SK_EVPARA EventParam; /* Event struct for timer event */
3879 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3880 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3881 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3882 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3883 SKGE_DRV, SK_DRV_TIMER, EventParam);
3886 /*****************************************************************************
3888 * StopDrvCleanupTimer - Stop timer to check for descriptors
3890 * Description:
3891 * This function requests a HW-timer fo the Yukon card. The actions to
3892 * perform when this timer expires, are located in the SkDrvEvent().
3894 * Returns: N/A
3896 static void
3897 StopDrvCleanupTimer(SK_AC *pAC) {
3898 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3899 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3902 /****************************************************************************/
3903 /* functions for common modules *********************************************/
3904 /****************************************************************************/
3907 /*****************************************************************************
3909 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3911 * Description:
3912 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3913 * is embedded into a socket buff data area.
3915 * Context:
3916 * runtime
3918 * Returns:
3919 * NULL or pointer to Mbuf.
3921 SK_MBUF *SkDrvAllocRlmtMbuf(
3922 SK_AC *pAC, /* pointer to adapter context */
3923 SK_IOC IoC, /* the IO-context */
3924 unsigned BufferSize) /* size of the requested buffer */
3926 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3927 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3929 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3930 if (pMsgBlock == NULL) {
3931 return (NULL);
3933 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3934 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3935 pRlmtMbuf->pNext = NULL;
3936 pRlmtMbuf->pOs = pMsgBlock;
3937 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3938 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3939 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3940 return (pRlmtMbuf);
3942 } /* SkDrvAllocRlmtMbuf */
3945 /*****************************************************************************
3947 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3949 * Description:
3950 * This routine frees one or more RLMT mbuf(s).
3952 * Context:
3953 * runtime
3955 * Returns:
3956 * Nothing
3958 void SkDrvFreeRlmtMbuf(
3959 SK_AC *pAC, /* pointer to adapter context */
3960 SK_IOC IoC, /* the IO-context */
3961 SK_MBUF *pMbuf) /* size of the requested buffer */
3963 SK_MBUF *pFreeMbuf;
3964 SK_MBUF *pNextMbuf;
3966 pFreeMbuf = pMbuf;
3967 do {
3968 pNextMbuf = pFreeMbuf->pNext;
3969 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3970 pFreeMbuf = pNextMbuf;
3971 } while ( pFreeMbuf != NULL );
3972 } /* SkDrvFreeRlmtMbuf */
3975 /*****************************************************************************
3977 * SkOsGetTime - provide a time value
3979 * Description:
3980 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3981 * It is not used for absolute time, but only for time differences.
3984 * Returns:
3985 * Time value
3987 SK_U64 SkOsGetTime(SK_AC *pAC)
3989 SK_U64 PrivateJiffies;
3990 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3991 return PrivateJiffies;
3992 } /* SkOsGetTime */
3995 /*****************************************************************************
3997 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3999 * Description:
4000 * This routine reads a 32 bit value from the pci configuration
4001 * space.
4003 * Returns:
4004 * 0 - indicate everything worked ok.
4005 * != 0 - error indication
4007 int SkPciReadCfgDWord(
4008 SK_AC *pAC, /* Adapter Control structure pointer */
4009 int PciAddr, /* PCI register address */
4010 SK_U32 *pVal) /* pointer to store the read value */
4012 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
4013 return(0);
4014 } /* SkPciReadCfgDWord */
4017 /*****************************************************************************
4019 * SkPciReadCfgWord - read a 16 bit value from pci config space
4021 * Description:
4022 * This routine reads a 16 bit value from the pci configuration
4023 * space.
4025 * Returns:
4026 * 0 - indicate everything worked ok.
4027 * != 0 - error indication
4029 int SkPciReadCfgWord(
4030 SK_AC *pAC, /* Adapter Control structure pointer */
4031 int PciAddr, /* PCI register address */
4032 SK_U16 *pVal) /* pointer to store the read value */
4034 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
4035 return(0);
4036 } /* SkPciReadCfgWord */
4039 /*****************************************************************************
4041 * SkPciReadCfgByte - read a 8 bit value from pci config space
4043 * Description:
4044 * This routine reads a 8 bit value from the pci configuration
4045 * space.
4047 * Returns:
4048 * 0 - indicate everything worked ok.
4049 * != 0 - error indication
4051 int SkPciReadCfgByte(
4052 SK_AC *pAC, /* Adapter Control structure pointer */
4053 int PciAddr, /* PCI register address */
4054 SK_U8 *pVal) /* pointer to store the read value */
4056 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4057 return(0);
4058 } /* SkPciReadCfgByte */
4061 /*****************************************************************************
4063 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
4065 * Description:
4066 * This routine writes a 32 bit value to the pci configuration
4067 * space.
4069 * Returns:
4070 * 0 - indicate everything worked ok.
4071 * != 0 - error indication
4073 int SkPciWriteCfgDWord(
4074 SK_AC *pAC, /* Adapter Control structure pointer */
4075 int PciAddr, /* PCI register address */
4076 SK_U32 Val) /* pointer to store the read value */
4078 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
4079 return(0);
4080 } /* SkPciWriteCfgDWord */
4083 /*****************************************************************************
4085 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4087 * Description:
4088 * This routine writes a 16 bit value to the pci configuration
4089 * space. The flag PciConfigUp indicates whether the config space
4090 * is accesible or must be set up first.
4092 * Returns:
4093 * 0 - indicate everything worked ok.
4094 * != 0 - error indication
4096 int SkPciWriteCfgWord(
4097 SK_AC *pAC, /* Adapter Control structure pointer */
4098 int PciAddr, /* PCI register address */
4099 SK_U16 Val) /* pointer to store the read value */
4101 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4102 return(0);
4103 } /* SkPciWriteCfgWord */
4106 /*****************************************************************************
4108 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4110 * Description:
4111 * This routine writes a 8 bit value to the pci configuration
4112 * space. The flag PciConfigUp indicates whether the config space
4113 * is accesible or must be set up first.
4115 * Returns:
4116 * 0 - indicate everything worked ok.
4117 * != 0 - error indication
4119 int SkPciWriteCfgByte(
4120 SK_AC *pAC, /* Adapter Control structure pointer */
4121 int PciAddr, /* PCI register address */
4122 SK_U8 Val) /* pointer to store the read value */
4124 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4125 return(0);
4126 } /* SkPciWriteCfgByte */
4129 /*****************************************************************************
4131 * SkDrvEvent - handle driver events
4133 * Description:
4134 * This function handles events from all modules directed to the driver
4136 * Context:
4137 * Is called under protection of slow path lock.
4139 * Returns:
4140 * 0 if everything ok
4141 * < 0 on error
4144 int SkDrvEvent(
4145 SK_AC *pAC, /* pointer to adapter context */
4146 SK_IOC IoC, /* io-context */
4147 SK_U32 Event, /* event-id */
4148 SK_EVPARA Param) /* event-parameter */
4150 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4151 struct sk_buff *pMsg; /* pointer to a message block */
4152 int FromPort; /* the port from which we switch away */
4153 int ToPort; /* the port we switch to */
4154 SK_EVPARA NewPara; /* parameter for further events */
4155 int Stat;
4156 unsigned long Flags;
4157 SK_BOOL DualNet;
4159 switch (Event) {
4160 case SK_DRV_ADAP_FAIL:
4161 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4162 ("ADAPTER FAIL EVENT\n"));
4163 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4164 /* disable interrupts */
4165 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4166 /* cgoos */
4167 break;
4168 case SK_DRV_PORT_FAIL:
4169 FromPort = Param.Para32[0];
4170 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4171 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4172 if (FromPort == 0) {
4173 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4174 } else {
4175 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4177 /* cgoos */
4178 break;
4179 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4180 /* action list 4 */
4181 FromPort = Param.Para32[0];
4182 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4183 ("PORT RESET EVENT, Port: %d ", FromPort));
4184 NewPara.Para64 = FromPort;
4185 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4186 spin_lock_irqsave(
4187 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4188 Flags);
4190 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4191 pAC->dev[Param.Para32[0]]->flags &= ~IFF_RUNNING;
4192 spin_unlock_irqrestore(
4193 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4194 Flags);
4196 /* clear rx ring from received frames */
4197 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4199 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4200 spin_lock_irqsave(
4201 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4202 Flags);
4204 /* tschilling: Handling of return value inserted. */
4205 if (SkGeInitPort(pAC, IoC, FromPort)) {
4206 if (FromPort == 0) {
4207 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4208 } else {
4209 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4212 SkAddrMcUpdate(pAC,IoC, FromPort);
4213 PortReInitBmu(pAC, FromPort);
4214 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4215 ClearAndStartRx(pAC, FromPort);
4216 spin_unlock_irqrestore(
4217 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4218 Flags);
4219 break;
4220 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4221 /* action list 5 */
4222 FromPort = Param.Para32[0];
4223 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4224 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4225 /* Mac update */
4226 SkAddrMcUpdate(pAC,IoC, FromPort);
4228 if (DoPrintInterfaceChange) {
4229 printk("%s: network connection up using"
4230 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4232 /* tschilling: Values changed according to LinkSpeedUsed. */
4233 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4234 if (Stat == SK_LSPEED_STAT_10MBPS) {
4235 printk(" speed: 10\n");
4236 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4237 printk(" speed: 100\n");
4238 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4239 printk(" speed: 1000\n");
4240 } else {
4241 printk(" speed: unknown\n");
4245 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4246 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4247 Stat == SK_LMODE_STAT_AUTOFULL) {
4248 printk(" autonegotiation: yes\n");
4250 else {
4251 printk(" autonegotiation: no\n");
4253 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4254 Stat == SK_LMODE_STAT_HALF) {
4255 printk(" duplex mode: half\n");
4257 else {
4258 printk(" duplex mode: full\n");
4260 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4261 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4262 printk(" flowctrl: remote send\n");
4264 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4265 printk(" flowctrl: local send\n");
4267 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4268 printk(" flowctrl: symmetric\n");
4270 else {
4271 printk(" flowctrl: none\n");
4274 /* tschilling: Check against CopperType now. */
4275 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4276 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4277 SK_LSPEED_STAT_1000MBPS)) {
4278 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4279 if (Stat == SK_MS_STAT_MASTER ) {
4280 printk(" role: master\n");
4282 else if (Stat == SK_MS_STAT_SLAVE ) {
4283 printk(" role: slave\n");
4285 else {
4286 printk(" role: ???\n");
4291 Display dim (dynamic interrupt moderation)
4292 informations
4294 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4295 printk(" irq moderation: static (%d ints/sec)\n",
4296 pAC->DynIrqModInfo.MaxModIntsPerSec);
4297 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4298 printk(" irq moderation: dynamic (%d ints/sec)\n",
4299 pAC->DynIrqModInfo.MaxModIntsPerSec);
4300 else
4301 printk(" irq moderation: disabled\n");
4304 #ifdef SK_ZEROCOPY
4305 if (pAC->ChipsetType)
4306 #ifdef USE_SK_TX_CHECKSUM
4307 printk(" scatter-gather: enabled\n");
4308 #else
4309 printk(" tx-checksum: disabled\n");
4310 #endif
4311 else
4312 printk(" scatter-gather: disabled\n");
4313 #else
4314 printk(" scatter-gather: disabled\n");
4315 #endif
4317 #ifndef USE_SK_RX_CHECKSUM
4318 printk(" rx-checksum: disabled\n");
4319 #endif
4321 } else {
4322 DoPrintInterfaceChange = SK_TRUE;
4325 if ((Param.Para32[0] != pAC->ActivePort) &&
4326 (pAC->RlmtNets == 1)) {
4327 NewPara.Para32[0] = pAC->ActivePort;
4328 NewPara.Para32[1] = Param.Para32[0];
4329 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4330 NewPara);
4333 /* Inform the world that link protocol is up. */
4334 pAC->dev[Param.Para32[0]]->flags |= IFF_RUNNING;
4336 break;
4337 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4338 /* action list 7 */
4339 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4340 ("NET DOWN EVENT "));
4341 if (DoPrintInterfaceChange) {
4342 printk("%s: network connection down\n",
4343 pAC->dev[Param.Para32[1]]->name);
4344 } else {
4345 DoPrintInterfaceChange = SK_TRUE;
4347 pAC->dev[Param.Para32[1]]->flags &= ~IFF_RUNNING;
4348 break;
4349 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4350 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4351 ("PORT SWITCH HARD "));
4352 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4353 /* action list 6 */
4354 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4355 'A'+Param.Para32[1]);
4356 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4357 FromPort = Param.Para32[0];
4358 ToPort = Param.Para32[1];
4359 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4360 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4361 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4362 NewPara.Para64 = FromPort;
4363 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4364 NewPara.Para64 = ToPort;
4365 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4366 spin_lock_irqsave(
4367 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4368 Flags);
4369 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4370 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4371 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4372 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4373 spin_unlock_irqrestore(
4374 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4375 Flags);
4377 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4378 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4380 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4381 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4382 spin_lock_irqsave(
4383 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4384 Flags);
4385 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4386 pAC->ActivePort = ToPort;
4387 #if 0
4388 SetQueueSizes(pAC);
4389 #else
4390 /* tschilling: New common function with minimum size check. */
4391 DualNet = SK_FALSE;
4392 if (pAC->RlmtNets == 2) {
4393 DualNet = SK_TRUE;
4396 if (SkGeInitAssignRamToQueues(
4397 pAC,
4398 pAC->ActivePort,
4399 DualNet)) {
4400 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4401 spin_unlock_irqrestore(
4402 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4403 Flags);
4404 printk("SkGeInitAssignRamToQueues failed.\n");
4405 break;
4407 #endif
4408 /* tschilling: Handling of return values inserted. */
4409 if (SkGeInitPort(pAC, IoC, FromPort) ||
4410 SkGeInitPort(pAC, IoC, ToPort)) {
4411 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4413 if (Event == SK_DRV_SWITCH_SOFT) {
4414 SkMacRxTxEnable(pAC, IoC, FromPort);
4416 SkMacRxTxEnable(pAC, IoC, ToPort);
4417 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4418 SkAddrMcUpdate(pAC, IoC, FromPort);
4419 SkAddrMcUpdate(pAC, IoC, ToPort);
4420 PortReInitBmu(pAC, FromPort);
4421 PortReInitBmu(pAC, ToPort);
4422 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4423 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4424 ClearAndStartRx(pAC, FromPort);
4425 ClearAndStartRx(pAC, ToPort);
4426 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4427 spin_unlock_irqrestore(
4428 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4429 Flags);
4430 break;
4431 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4432 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4433 ("RLS "));
4434 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4435 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4436 skb_put(pMsg, pRlmtMbuf->Length);
4437 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4438 pMsg) < 0)
4440 DEV_KFREE_SKB_ANY(pMsg);
4441 break;
4442 case SK_DRV_TIMER:
4443 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4445 ** expiration of the moderation timer implies that
4446 ** dynamic moderation is to be applied
4448 SkDimStartModerationTimer(pAC);
4449 SkDimModerate(pAC);
4450 if (pAC->DynIrqModInfo.DisplayStats) {
4451 SkDimDisplayModerationSettings(pAC);
4453 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4455 ** check if we need to check for descriptors which
4456 ** haven't been handled the last millisecs
4458 StartDrvCleanupTimer(pAC);
4459 if (pAC->GIni.GIMacsFound == 2) {
4460 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4462 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4463 } else {
4464 printk("Expiration of unknown timer\n");
4466 break;
4467 default:
4468 break;
4470 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4471 ("END EVENT "));
4473 return (0);
4474 } /* SkDrvEvent */
4477 /*****************************************************************************
4479 * SkErrorLog - log errors
4481 * Description:
4482 * This function logs errors to the system buffer and to the console
4484 * Returns:
4485 * 0 if everything ok
4486 * < 0 on error
4489 void SkErrorLog(
4490 SK_AC *pAC,
4491 int ErrClass,
4492 int ErrNum,
4493 char *pErrorMsg)
4495 char ClassStr[80];
4497 switch (ErrClass) {
4498 case SK_ERRCL_OTHER:
4499 strcpy(ClassStr, "Other error");
4500 break;
4501 case SK_ERRCL_CONFIG:
4502 strcpy(ClassStr, "Configuration error");
4503 break;
4504 case SK_ERRCL_INIT:
4505 strcpy(ClassStr, "Initialization error");
4506 break;
4507 case SK_ERRCL_NORES:
4508 strcpy(ClassStr, "Out of resources error");
4509 break;
4510 case SK_ERRCL_SW:
4511 strcpy(ClassStr, "internal Software error");
4512 break;
4513 case SK_ERRCL_HW:
4514 strcpy(ClassStr, "Hardware failure");
4515 break;
4516 case SK_ERRCL_COMM:
4517 strcpy(ClassStr, "Communication error");
4518 break;
4520 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4521 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4522 ClassStr, ErrNum, pErrorMsg);
4524 } /* SkErrorLog */
4526 #ifdef SK_DIAG_SUPPORT
4528 /*****************************************************************************
4530 * SkDrvEnterDiagMode - handles DIAG attach request
4532 * Description:
4533 * Notify the kernel to NOT access the card any longer due to DIAG
4534 * Deinitialize the Card
4536 * Returns:
4537 * int
4539 int SkDrvEnterDiagMode(
4540 SK_AC *pAc) /* pointer to adapter context */
4542 SK_AC *pAC = NULL;
4543 DEV_NET *pNet = NULL;
4545 pNet = (DEV_NET *) pAc->dev[0]->priv;
4546 pAC = pNet->pAC;
4548 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4549 sizeof(SK_PNMI_STRUCT_DATA));
4551 pAC->DiagModeActive = DIAG_ACTIVE;
4552 if (pAC->BoardLevel > SK_INIT_DATA) {
4553 if (pNet->Up) {
4554 pAC->WasIfUp[0] = SK_TRUE;
4555 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4556 DoPrintInterfaceChange = SK_FALSE;
4557 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4558 } else {
4559 pAC->WasIfUp[0] = SK_FALSE;
4561 if (pNet != (DEV_NET *) pAc->dev[1]->priv) {
4562 pNet = (DEV_NET *) pAc->dev[1]->priv;
4563 if (pNet->Up) {
4564 pAC->WasIfUp[1] = SK_TRUE;
4565 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4566 DoPrintInterfaceChange = SK_FALSE;
4567 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4568 } else {
4569 pAC->WasIfUp[1] = SK_FALSE;
4572 pAC->BoardLevel = SK_INIT_DATA;
4574 return(0);
4577 /*****************************************************************************
4579 * SkDrvLeaveDiagMode - handles DIAG detach request
4581 * Description:
4582 * Notify the kernel to may access the card again after use by DIAG
4583 * Initialize the Card
4585 * Returns:
4586 * int
4588 int SkDrvLeaveDiagMode(
4589 SK_AC *pAc) /* pointer to adapter control context */
4591 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4592 sizeof(SK_PNMI_STRUCT_DATA));
4593 pAc->DiagModeActive = DIAG_NOTACTIVE;
4594 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4595 if (pAc->WasIfUp[0] == SK_TRUE) {
4596 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4597 DoPrintInterfaceChange = SK_FALSE;
4598 SkDrvInitAdapter(pAc, 0); /* first device */
4600 if (pAc->WasIfUp[1] == SK_TRUE) {
4601 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4602 DoPrintInterfaceChange = SK_FALSE;
4603 SkDrvInitAdapter(pAc, 1); /* second device */
4605 return(0);
4608 /*****************************************************************************
4610 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4612 * Description:
4613 * This function parses the PCI slot name information string and will
4614 * retrieve the devcie number out of it. The slot_name maintianed by
4615 * linux is in the form of '02:0a.0', whereas the first two characters
4616 * represent the bus number in hex (in the sample above this is
4617 * pci bus 0x02) and the next two characters the device number (0x0a).
4619 * Returns:
4620 * SK_U32: The device number from the PCI slot name
4623 static SK_U32 ParseDeviceNbrFromSlotName(
4624 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4626 char *CurrCharPos = (char *) SlotName;
4627 int FirstNibble = -1;
4628 int SecondNibble = -1;
4629 SK_U32 Result = 0;
4631 while (*CurrCharPos != '\0') {
4632 if (*CurrCharPos == ':') {
4633 while (*CurrCharPos != '.') {
4634 CurrCharPos++;
4635 if ( (*CurrCharPos >= '0') &&
4636 (*CurrCharPos <= '9')) {
4637 if (FirstNibble == -1) {
4638 /* dec. value for '0' */
4639 FirstNibble = *CurrCharPos - 48;
4640 } else {
4641 SecondNibble = *CurrCharPos - 48;
4643 } else if ( (*CurrCharPos >= 'a') &&
4644 (*CurrCharPos <= 'f') ) {
4645 if (FirstNibble == -1) {
4646 FirstNibble = *CurrCharPos - 87;
4647 } else {
4648 SecondNibble = *CurrCharPos - 87;
4650 } else {
4651 Result = 0;
4655 Result = FirstNibble;
4656 Result = Result << 4; /* first nibble is higher one */
4657 Result = Result | SecondNibble;
4659 CurrCharPos++; /* next character */
4661 return (Result);
4664 /****************************************************************************
4666 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4667 * called if Diag attaches to that card)
4669 * Description:
4670 * Close initialized adapter.
4672 * Returns:
4673 * 0 - on success
4674 * error code - on error
4676 static int SkDrvDeInitAdapter(
4677 SK_AC *pAC, /* pointer to adapter context */
4678 int devNbr) /* what device is to be handled */
4680 struct SK_NET_DEVICE *dev;
4682 dev = pAC->dev[devNbr];
4685 ** Function SkGeClose() uses MOD_DEC_USE_COUNT (2.2/2.4)
4686 ** or module_put() (2.6) to decrease the number of users for
4687 ** a device, but if a device is to be put under control of
4688 ** the DIAG, that count is OK already and does not need to
4689 ** be adapted! Hence the opposite MOD_INC_USE_COUNT or
4690 ** try_module_get() needs to be used again to correct that.
4692 if (!try_module_get(THIS_MODULE)) {
4693 return (-1);
4696 if (SkGeClose(dev) != 0) {
4697 module_put(THIS_MODULE);
4698 return (-1);
4700 return (0);
4702 } /* SkDrvDeInitAdapter() */
4704 /****************************************************************************
4706 * SkDrvInitAdapter - Initialize adapter (this function is only
4707 * called if Diag deattaches from that card)
4709 * Description:
4710 * Close initialized adapter.
4712 * Returns:
4713 * 0 - on success
4714 * error code - on error
4716 static int SkDrvInitAdapter(
4717 SK_AC *pAC, /* pointer to adapter context */
4718 int devNbr) /* what device is to be handled */
4720 struct SK_NET_DEVICE *dev;
4722 dev = pAC->dev[devNbr];
4724 if (SkGeOpen(dev) != 0) {
4725 return (-1);
4726 } else {
4728 ** Function SkGeOpen() uses MOD_INC_USE_COUNT (2.2/2.4)
4729 ** or try_module_get() (2.6) to increase the number of
4730 ** users for a device, but if a device was just under
4731 ** control of the DIAG, that count is OK already and
4732 ** does not need to be adapted! Hence the opposite
4733 ** MOD_DEC_USE_COUNT or module_put() needs to be used
4734 ** again to correct that.
4736 module_put(THIS_MODULE);
4740 ** Use correct MTU size and indicate to kernel TX queue can be started
4742 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4743 return (-1);
4745 return (0);
4747 } /* SkDrvInitAdapter */
4749 #endif
4751 #ifdef DEBUG
4752 /****************************************************************************/
4753 /* "debug only" section *****************************************************/
4754 /****************************************************************************/
4757 /*****************************************************************************
4759 * DumpMsg - print a frame
4761 * Description:
4762 * This function prints frames to the system logfile/to the console.
4764 * Returns: N/A
4767 static void DumpMsg(struct sk_buff *skb, char *str)
4769 int msglen;
4771 if (skb == NULL) {
4772 printk("DumpMsg(): NULL-Message\n");
4773 return;
4776 if (skb->data == NULL) {
4777 printk("DumpMsg(): Message empty\n");
4778 return;
4781 msglen = skb->len;
4782 if (msglen > 64)
4783 msglen = 64;
4785 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4787 DumpData((char *)skb->data, msglen);
4789 printk("------- End of message ---------\n");
4790 } /* DumpMsg */
4794 /*****************************************************************************
4796 * DumpData - print a data area
4798 * Description:
4799 * This function prints a area of data to the system logfile/to the
4800 * console.
4802 * Returns: N/A
4805 static void DumpData(char *p, int size)
4807 register int i;
4808 int haddr, addr;
4809 char hex_buffer[180];
4810 char asc_buffer[180];
4811 char HEXCHAR[] = "0123456789ABCDEF";
4813 addr = 0;
4814 haddr = 0;
4815 hex_buffer[0] = 0;
4816 asc_buffer[0] = 0;
4817 for (i=0; i < size; ) {
4818 if (*p >= '0' && *p <='z')
4819 asc_buffer[addr] = *p;
4820 else
4821 asc_buffer[addr] = '.';
4822 addr++;
4823 asc_buffer[addr] = 0;
4824 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4825 haddr++;
4826 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4827 haddr++;
4828 hex_buffer[haddr] = ' ';
4829 haddr++;
4830 hex_buffer[haddr] = 0;
4831 p++;
4832 i++;
4833 if (i%16 == 0) {
4834 printk("%s %s\n", hex_buffer, asc_buffer);
4835 addr = 0;
4836 haddr = 0;
4839 } /* DumpData */
4842 /*****************************************************************************
4844 * DumpLong - print a data area as long values
4846 * Description:
4847 * This function prints a area of data to the system logfile/to the
4848 * console.
4850 * Returns: N/A
4853 static void DumpLong(char *pc, int size)
4855 register int i;
4856 int haddr, addr;
4857 char hex_buffer[180];
4858 char asc_buffer[180];
4859 char HEXCHAR[] = "0123456789ABCDEF";
4860 long *p;
4861 int l;
4863 addr = 0;
4864 haddr = 0;
4865 hex_buffer[0] = 0;
4866 asc_buffer[0] = 0;
4867 p = (long*) pc;
4868 for (i=0; i < size; ) {
4869 l = (long) *p;
4870 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4871 haddr++;
4872 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4873 haddr++;
4874 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4875 haddr++;
4876 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4877 haddr++;
4878 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4879 haddr++;
4880 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4881 haddr++;
4882 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4883 haddr++;
4884 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4885 haddr++;
4886 hex_buffer[haddr] = ' ';
4887 haddr++;
4888 hex_buffer[haddr] = 0;
4889 p++;
4890 i++;
4891 if (i%8 == 0) {
4892 printk("%4x %s\n", (i-8)*4, hex_buffer);
4893 haddr = 0;
4896 printk("------------------------\n");
4897 } /* DumpLong */
4899 #endif
4901 static int __devinit skge_probe_one(struct pci_dev *pdev,
4902 const struct pci_device_id *ent)
4904 SK_AC *pAC;
4905 DEV_NET *pNet = NULL;
4906 struct net_device *dev = NULL;
4907 #ifdef CONFIG_PROC_FS
4908 struct proc_dir_entry *pProcFile;
4909 #endif
4910 static int boards_found = 0;
4911 int error = -ENODEV;
4913 if (pci_enable_device(pdev))
4914 goto out;
4916 /* Configure DMA attributes. */
4917 if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL) &&
4918 pci_set_dma_mask(pdev, (u64) 0xffffffff))
4919 goto out_disable_device;
4922 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4923 printk(KERN_ERR "Unable to allocate etherdev "
4924 "structure!\n");
4925 goto out_disable_device;
4928 pNet = dev->priv;
4929 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4930 if (!pNet->pAC) {
4931 printk(KERN_ERR "Unable to allocate adapter "
4932 "structure!\n");
4933 goto out_free_netdev;
4936 memset(pNet->pAC, 0, sizeof(SK_AC));
4937 pAC = pNet->pAC;
4938 pAC->PciDev = pdev;
4939 pAC->PciDevId = pdev->device;
4940 pAC->dev[0] = dev;
4941 pAC->dev[1] = dev;
4942 sprintf(pAC->Name, "SysKonnect SK-98xx");
4943 pAC->CheckQueue = SK_FALSE;
4945 pNet->Mtu = 1500;
4946 pNet->Up = 0;
4947 dev->irq = pdev->irq;
4948 error = SkGeInitPCI(pAC);
4949 if (error) {
4950 printk("SKGE: PCI setup failed: %i\n", error);
4951 goto out_free_netdev;
4954 SET_MODULE_OWNER(dev);
4955 dev->open = &SkGeOpen;
4956 dev->stop = &SkGeClose;
4957 dev->hard_start_xmit = &SkGeXmit;
4958 dev->get_stats = &SkGeStats;
4959 dev->set_multicast_list = &SkGeSetRxMode;
4960 dev->set_mac_address = &SkGeSetMacAddr;
4961 dev->do_ioctl = &SkGeIoctl;
4962 dev->change_mtu = &SkGeChangeMtu;
4963 dev->flags &= ~IFF_RUNNING;
4964 SET_NETDEV_DEV(dev, &pdev->dev);
4966 #ifdef SK_ZEROCOPY
4967 #ifdef USE_SK_TX_CHECKSUM
4968 if (pAC->ChipsetType) {
4969 /* Use only if yukon hardware */
4970 /* SK and ZEROCOPY - fly baby... */
4971 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
4973 #endif
4974 #endif
4976 pAC->Index = boards_found++;
4978 if (SkGeBoardInit(dev, pAC))
4979 goto out_free_netdev;
4981 /* Register net device */
4982 if (register_netdev(dev)) {
4983 printk(KERN_ERR "SKGE: Could not register device.\n");
4984 goto out_free_resources;
4987 /* Print adapter specific string from vpd */
4988 ProductStr(pAC);
4989 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4991 /* Print configuration settings */
4992 printk(" PrefPort:%c RlmtMode:%s\n",
4993 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4994 (pAC->RlmtMode==0) ? "Check Link State" :
4995 ((pAC->RlmtMode==1) ? "Check Link State" :
4996 ((pAC->RlmtMode==3) ? "Check Local Port" :
4997 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4998 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
5000 SkGeYellowLED(pAC, pAC->IoBase, 1);
5003 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
5005 #ifdef CONFIG_PROC_FS
5006 pProcFile = create_proc_entry(dev->name, S_IRUGO, pSkRootDir);
5007 if (pProcFile) {
5008 pProcFile->proc_fops = &sk_proc_fops;
5009 pProcFile->data = dev;
5010 pProcFile->owner = THIS_MODULE;
5012 #endif
5014 pNet->PortNr = 0;
5015 pNet->NetNr = 0;
5017 boards_found++;
5019 /* More then one port found */
5020 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
5021 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
5022 printk(KERN_ERR "Unable to allocate etherdev "
5023 "structure!\n");
5024 goto out;
5027 pAC->dev[1] = dev;
5028 pNet = dev->priv;
5029 pNet->PortNr = 1;
5030 pNet->NetNr = 1;
5031 pNet->pAC = pAC;
5032 pNet->Mtu = 1500;
5033 pNet->Up = 0;
5035 dev->open = &SkGeOpen;
5036 dev->stop = &SkGeClose;
5037 dev->hard_start_xmit = &SkGeXmit;
5038 dev->get_stats = &SkGeStats;
5039 dev->set_multicast_list = &SkGeSetRxMode;
5040 dev->set_mac_address = &SkGeSetMacAddr;
5041 dev->do_ioctl = &SkGeIoctl;
5042 dev->change_mtu = &SkGeChangeMtu;
5043 dev->flags &= ~IFF_RUNNING;
5045 #ifdef SK_ZEROCOPY
5046 #ifdef USE_SK_TX_CHECKSUM
5047 if (pAC->ChipsetType) {
5048 /* SG and ZEROCOPY - fly baby... */
5049 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
5051 #endif
5052 #endif
5054 if (register_netdev(dev)) {
5055 printk(KERN_ERR "SKGE: Could not register device.\n");
5056 free_netdev(dev);
5057 pAC->dev[1] = pAC->dev[0];
5058 } else {
5059 #ifdef CONFIG_PROC_FS
5060 pProcFile = create_proc_entry(dev->name, S_IRUGO,
5061 pSkRootDir);
5062 if (pProcFile) {
5063 pProcFile->proc_fops = &sk_proc_fops;
5064 pProcFile->data = dev;
5065 pProcFile->owner = THIS_MODULE;
5067 #endif
5069 memcpy(&dev->dev_addr,
5070 &pAC->Addr.Net[1].CurrentMacAddress, 6);
5072 printk("%s: %s\n", dev->name, pAC->DeviceStr);
5073 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
5077 /* Save the hardware revision */
5078 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
5079 (pAC->GIni.GIPciHwRev & 0x0F);
5081 /* Set driver globals */
5082 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
5083 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
5085 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
5086 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
5088 pci_set_drvdata(pdev, dev);
5089 return 0;
5091 out_free_resources:
5092 FreeResources(dev);
5093 out_free_netdev:
5094 free_netdev(dev);
5095 out_disable_device:
5096 pci_disable_device(pdev);
5097 out:
5098 return error;
5101 static void __devexit skge_remove_one(struct pci_dev *pdev)
5103 struct net_device *dev = pci_get_drvdata(pdev);
5104 DEV_NET *pNet = (DEV_NET *) dev->priv;
5105 SK_AC *pAC = pNet->pAC;
5106 int have_second_mac = 0;
5108 if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 2)
5109 have_second_mac = 1;
5111 remove_proc_entry(dev->name, pSkRootDir);
5112 unregister_netdev(dev);
5113 if (have_second_mac) {
5114 remove_proc_entry(pAC->dev[1]->name, pSkRootDir);
5115 unregister_netdev(pAC->dev[1]);
5118 SkGeYellowLED(pAC, pAC->IoBase, 0);
5120 if (pAC->BoardLevel == SK_INIT_RUN) {
5121 SK_EVPARA EvPara;
5122 unsigned long Flags;
5124 /* board is still alive */
5125 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5126 EvPara.Para32[0] = 0;
5127 EvPara.Para32[1] = -1;
5128 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5129 EvPara.Para32[0] = 1;
5130 EvPara.Para32[1] = -1;
5131 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5132 SkEventDispatcher(pAC, pAC->IoBase);
5133 /* disable interrupts */
5134 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5135 SkGeDeInit(pAC, pAC->IoBase);
5136 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5137 pAC->BoardLevel = SK_INIT_DATA;
5138 /* We do NOT check here, if IRQ was pending, of course*/
5141 if (pAC->BoardLevel == SK_INIT_IO) {
5142 /* board is still alive */
5143 SkGeDeInit(pAC, pAC->IoBase);
5144 pAC->BoardLevel = SK_INIT_DATA;
5147 FreeResources(dev);
5148 free_netdev(dev);
5149 if (have_second_mac)
5150 free_netdev(pAC->dev[1]);
5151 kfree(pAC);
5154 static struct pci_device_id skge_pci_tbl[] = {
5155 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5156 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5157 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5158 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5159 { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5160 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5161 #if 0 /* don't handle Yukon2 cards at the moment -- mlindner@syskonnect.de */
5162 { PCI_VENDOR_ID_MARVELL, 0x4360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5163 { PCI_VENDOR_ID_MARVELL, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5164 #endif
5165 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5166 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5167 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5168 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5169 { 0, }
5172 static struct pci_driver skge_driver = {
5173 .name = "skge",
5174 .id_table = skge_pci_tbl,
5175 .probe = skge_probe_one,
5176 .remove = __devexit_p(skge_remove_one),
5179 static int __init skge_init(void)
5181 int error;
5183 #ifdef CONFIG_PROC_FS
5184 memcpy(&SK_Root_Dir_entry, BOOT_STRING, sizeof(SK_Root_Dir_entry) - 1);
5186 pSkRootDir = proc_mkdir(SK_Root_Dir_entry, proc_net);
5187 if (!pSkRootDir) {
5188 printk(KERN_WARNING "Unable to create /proc/net/%s",
5189 SK_Root_Dir_entry);
5190 return -ENOMEM;
5192 pSkRootDir->owner = THIS_MODULE;
5193 #endif
5195 error = pci_module_init(&skge_driver);
5196 if (error) {
5197 #ifdef CONFIG_PROC_FS
5198 remove_proc_entry(pSkRootDir->name, proc_net);
5199 #endif
5202 return error;
5205 static void __exit skge_exit(void)
5207 pci_unregister_driver(&skge_driver);
5208 #ifdef CONFIG_PROC_FS
5209 remove_proc_entry(pSkRootDir->name, proc_net);
5210 #endif
5213 module_init(skge_init);
5214 module_exit(skge_exit);