aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sk98lin/skge.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/sk98lin/skge.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/net/sk98lin/skge.c')
-rw-r--r--drivers/net/sk98lin/skge.c5186
1 files changed, 5186 insertions, 0 deletions
diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c
new file mode 100644
index 000000000000..05b827f79f54
--- /dev/null
+++ b/drivers/net/sk98lin/skge.c
@@ -0,0 +1,5186 @@
1/******************************************************************************
2 *
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
8 *
9 ******************************************************************************/
10
11/******************************************************************************
12 *
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
14 * (C)Copyright 2002-2003 Marvell.
15 *
16 * Driver for Marvell Yukon chipset and SysKonnect Gigabit Ethernet
17 * Server Adapters.
18 *
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)
23 *
24 * Address all question to: linux@syskonnect.de
25 *
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".
29 *
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.
34 *
35 * The information in this file is provided "AS IS" without warranty.
36 *
37 ******************************************************************************/
38
39/******************************************************************************
40 *
41 * Possible compiler options (#define xxx / -Dxxx):
42 *
43 * debugging can be enable by changing SK_DEBUG_CHKMOD and
44 * SK_DEBUG_CHKCAT in makefile (described there).
45 *
46 ******************************************************************************/
47
48/******************************************************************************
49 *
50 * Description:
51 *
52 * This is the main module of the Linux GE driver.
53 *
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.
61 *
62 * Include file hierarchy:
63 *
64 * <linux/module.h>
65 *
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 * <linux/bitops.h>
76 * <asm/byteorder.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>
86 *
87 * "h/skerror.h"
88 * "h/skdebug.h"
89 * "h/sktypes.h"
90 * "h/lm80.h"
91 * "h/xmac_ii.h"
92 *
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"
106 *
107 ******************************************************************************/
108
109#include "h/skversion.h"
110
111#include <linux/module.h>
112#include <linux/moduleparam.h>
113#include <linux/init.h>
114#include <linux/proc_fs.h>
115
116#include "h/skdrv1st.h"
117#include "h/skdrv2nd.h"
118
119/*******************************************************************************
120 *
121 * Defines
122 *
123 ******************************************************************************/
124
125/* for debuging on x86 only */
126/* #define BREAKPOINT() asm(" int $3"); */
127
128/* use the transmit hw checksum driver functionality */
129#define USE_SK_TX_CHECKSUM
130
131/* use the receive hw checksum driver functionality */
132#define USE_SK_RX_CHECKSUM
133
134/* use the scatter-gather functionality with sendfile() */
135#define SK_ZEROCOPY
136
137/* use of a transmit complete interrupt */
138#define USE_TX_COMPLETE
139
140/*
141 * threshold for copying small receive frames
142 * set to 0 to avoid copying, set to 9001 to copy all frames
143 */
144#define SK_COPY_THRESHOLD 50
145
146/* number of adapters that can be configured via command line params */
147#define SK_MAX_CARD_PARAM 16
148
149
150
151/*
152 * use those defines for a compile-in version of the driver instead
153 * of command line parameters
154 */
155// #define LINK_SPEED_A {"Auto", }
156// #define LINK_SPEED_B {"Auto", }
157// #define AUTO_NEG_A {"Sense", }
158// #define AUTO_NEG_B {"Sense", }
159// #define DUP_CAP_A {"Both", }
160// #define DUP_CAP_B {"Both", }
161// #define FLOW_CTRL_A {"SymOrRem", }
162// #define FLOW_CTRL_B {"SymOrRem", }
163// #define ROLE_A {"Auto", }
164// #define ROLE_B {"Auto", }
165// #define PREF_PORT {"A", }
166// #define CON_TYPE {"Auto", }
167// #define RLMT_MODE {"CheckLinkState", }
168
169#define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
170#define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
171#define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
172
173
174/* Set blink mode*/
175#define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
176 SK_DUP_LED_NORMAL | \
177 SK_LED_LINK100_ON)
178
179
180/* Isr return value */
181#define SkIsrRetVar irqreturn_t
182#define SkIsrRetNone IRQ_NONE
183#define SkIsrRetHandled IRQ_HANDLED
184
185
186/*******************************************************************************
187 *
188 * Local Function Prototypes
189 *
190 ******************************************************************************/
191
192static void FreeResources(struct SK_NET_DEVICE *dev);
193static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
194static SK_BOOL BoardAllocMem(SK_AC *pAC);
195static void BoardFreeMem(SK_AC *pAC);
196static void BoardInitMem(SK_AC *pAC);
197static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
198static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
199static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
200static int SkGeOpen(struct SK_NET_DEVICE *dev);
201static int SkGeClose(struct SK_NET_DEVICE *dev);
202static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
203static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
204static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
205static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
206static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
207static void GetConfiguration(SK_AC*);
208static void ProductStr(SK_AC*);
209static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
210static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
211static void FillRxRing(SK_AC*, RX_PORT*);
212static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
213static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
214static void ClearAndStartRx(SK_AC*, int);
215static void ClearTxIrq(SK_AC*, int, int);
216static void ClearRxRing(SK_AC*, RX_PORT*);
217static void ClearTxRing(SK_AC*, TX_PORT*);
218static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
219static void PortReInitBmu(SK_AC*, int);
220static int SkGeIocMib(DEV_NET*, unsigned int, int);
221static int SkGeInitPCI(SK_AC *pAC);
222static void StartDrvCleanupTimer(SK_AC *pAC);
223static void StopDrvCleanupTimer(SK_AC *pAC);
224static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
225
226#ifdef SK_DIAG_SUPPORT
227static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
228static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
229static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
230#endif
231
232/*******************************************************************************
233 *
234 * Extern Function Prototypes
235 *
236 ******************************************************************************/
237static const char SKRootName[] = "sk98lin";
238static struct proc_dir_entry *pSkRootDir;
239extern struct file_operations sk_proc_fops;
240
241static inline void SkGeProcCreate(struct net_device *dev)
242{
243 struct proc_dir_entry *pe;
244
245 if (pSkRootDir &&
246 (pe = create_proc_entry(dev->name, S_IRUGO, pSkRootDir))) {
247 pe->proc_fops = &sk_proc_fops;
248 pe->data = dev;
249 pe->owner = THIS_MODULE;
250 }
251}
252
253static inline void SkGeProcRemove(struct net_device *dev)
254{
255 if (pSkRootDir)
256 remove_proc_entry(dev->name, pSkRootDir);
257}
258
259extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
260extern void SkDimDisplayModerationSettings(SK_AC *pAC);
261extern void SkDimStartModerationTimer(SK_AC *pAC);
262extern void SkDimModerate(SK_AC *pAC);
263extern void SkGeBlinkTimer(unsigned long data);
264
265#ifdef DEBUG
266static void DumpMsg(struct sk_buff*, char*);
267static void DumpData(char*, int);
268static void DumpLong(char*, int);
269#endif
270
271/* global variables *********************************************************/
272static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
273extern struct ethtool_ops SkGeEthtoolOps;
274
275/* local variables **********************************************************/
276static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
277static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
278
279/*****************************************************************************
280 *
281 * SkGeInitPCI - Init the PCI resources
282 *
283 * Description:
284 * This function initialize the PCI resources and IO
285 *
286 * Returns: N/A
287 *
288 */
289int SkGeInitPCI(SK_AC *pAC)
290{
291 struct SK_NET_DEVICE *dev = pAC->dev[0];
292 struct pci_dev *pdev = pAC->PciDev;
293 int retval;
294
295 if (pci_enable_device(pdev) != 0) {
296 return 1;
297 }
298
299 dev->mem_start = pci_resource_start (pdev, 0);
300 pci_set_master(pdev);
301
302 if (pci_request_regions(pdev, pAC->Name) != 0) {
303 retval = 2;
304 goto out_disable;
305 }
306
307#ifdef SK_BIG_ENDIAN
308 /*
309 * On big endian machines, we use the adapter's aibility of
310 * reading the descriptors as big endian.
311 */
312 {
313 SK_U32 our2;
314 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
315 our2 |= PCI_REV_DESC;
316 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
317 }
318#endif
319
320 /*
321 * Remap the regs into kernel space.
322 */
323 pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
324
325 if (!pAC->IoBase){
326 retval = 3;
327 goto out_release;
328 }
329
330 return 0;
331
332 out_release:
333 pci_release_regions(pdev);
334 out_disable:
335 pci_disable_device(pdev);
336 return retval;
337}
338
339
340/*****************************************************************************
341 *
342 * FreeResources - release resources allocated for adapter
343 *
344 * Description:
345 * This function releases the IRQ, unmaps the IO and
346 * frees the desriptor ring.
347 *
348 * Returns: N/A
349 *
350 */
351static void FreeResources(struct SK_NET_DEVICE *dev)
352{
353SK_U32 AllocFlag;
354DEV_NET *pNet;
355SK_AC *pAC;
356
357 pNet = netdev_priv(dev);
358 pAC = pNet->pAC;
359 AllocFlag = pAC->AllocFlag;
360 if (pAC->PciDev) {
361 pci_release_regions(pAC->PciDev);
362 }
363 if (AllocFlag & SK_ALLOC_IRQ) {
364 free_irq(dev->irq, dev);
365 }
366 if (pAC->IoBase) {
367 iounmap(pAC->IoBase);
368 }
369 if (pAC->pDescrMem) {
370 BoardFreeMem(pAC);
371 }
372
373} /* FreeResources */
374
375MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
376MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
377MODULE_LICENSE("GPL");
378
379#ifdef LINK_SPEED_A
380static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
381#else
382static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
383#endif
384
385#ifdef LINK_SPEED_B
386static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
387#else
388static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
389#endif
390
391#ifdef AUTO_NEG_A
392static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
393#else
394static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
395#endif
396
397#ifdef DUP_CAP_A
398static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
399#else
400static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
401#endif
402
403#ifdef FLOW_CTRL_A
404static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
405#else
406static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
407#endif
408
409#ifdef ROLE_A
410static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
411#else
412static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
413#endif
414
415#ifdef AUTO_NEG_B
416static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
417#else
418static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
419#endif
420
421#ifdef DUP_CAP_B
422static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
423#else
424static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
425#endif
426
427#ifdef FLOW_CTRL_B
428static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
429#else
430static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
431#endif
432
433#ifdef ROLE_B
434static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
435#else
436static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
437#endif
438
439#ifdef CON_TYPE
440static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
441#else
442static char *ConType[SK_MAX_CARD_PARAM] = {"", };
443#endif
444
445#ifdef PREF_PORT
446static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
447#else
448static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
449#endif
450
451#ifdef RLMT_MODE
452static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
453#else
454static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
455#endif
456
457static int IntsPerSec[SK_MAX_CARD_PARAM];
458static char *Moderation[SK_MAX_CARD_PARAM];
459static char *ModerationMask[SK_MAX_CARD_PARAM];
460static char *AutoSizing[SK_MAX_CARD_PARAM];
461static char *Stats[SK_MAX_CARD_PARAM];
462
463module_param_array(Speed_A, charp, NULL, 0);
464module_param_array(Speed_B, charp, NULL, 0);
465module_param_array(AutoNeg_A, charp, NULL, 0);
466module_param_array(AutoNeg_B, charp, NULL, 0);
467module_param_array(DupCap_A, charp, NULL, 0);
468module_param_array(DupCap_B, charp, NULL, 0);
469module_param_array(FlowCtrl_A, charp, NULL, 0);
470module_param_array(FlowCtrl_B, charp, NULL, 0);
471module_param_array(Role_A, charp, NULL, 0);
472module_param_array(Role_B, charp, NULL, 0);
473module_param_array(ConType, charp, NULL, 0);
474module_param_array(PrefPort, charp, NULL, 0);
475module_param_array(RlmtMode, charp, NULL, 0);
476/* used for interrupt moderation */
477module_param_array(IntsPerSec, int, NULL, 0);
478module_param_array(Moderation, charp, NULL, 0);
479module_param_array(Stats, charp, NULL, 0);
480module_param_array(ModerationMask, charp, NULL, 0);
481module_param_array(AutoSizing, charp, NULL, 0);
482
483/*****************************************************************************
484 *
485 * SkGeBoardInit - do level 0 and 1 initialization
486 *
487 * Description:
488 * This function prepares the board hardware for running. The desriptor
489 * ring is set up, the IRQ is allocated and the configuration settings
490 * are examined.
491 *
492 * Returns:
493 * 0, if everything is ok
494 * !=0, on error
495 */
496static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
497{
498short i;
499unsigned long Flags;
500char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
501char *VerStr = VER_STRING;
502int Ret; /* return code of request_irq */
503SK_BOOL DualNet;
504
505 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
506 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
507 for (i=0; i<SK_MAX_MACS; i++) {
508 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
509 pAC->TxPort[i][0].PortIndex = i;
510 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
511 pAC->RxPort[i].PortIndex = i;
512 }
513
514 /* Initialize the mutexes */
515 for (i=0; i<SK_MAX_MACS; i++) {
516 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
517 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
518 }
519 spin_lock_init(&pAC->SlowPathLock);
520
521 /* setup phy_id blink timer */
522 pAC->BlinkTimer.function = SkGeBlinkTimer;
523 pAC->BlinkTimer.data = (unsigned long) dev;
524 init_timer(&pAC->BlinkTimer);
525
526 /* level 0 init common modules here */
527
528 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
529 /* Does a RESET on board ...*/
530 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
531 printk("HWInit (0) failed.\n");
532 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
533 return(-EAGAIN);
534 }
535 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
536 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
537 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
538 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
539 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
540 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
541
542 pAC->BoardLevel = SK_INIT_DATA;
543 pAC->RxBufSize = ETH_BUF_SIZE;
544
545 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
546 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
547
548 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
549
550 /* level 1 init common modules here (HW init) */
551 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
552 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
553 printk("sk98lin: HWInit (1) failed.\n");
554 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
555 return(-EAGAIN);
556 }
557 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
558 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
559 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
560 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
561 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
562 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
563
564 /* Set chipset type support */
565 pAC->ChipsetType = 0;
566 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
567 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
568 pAC->ChipsetType = 1;
569 }
570
571 GetConfiguration(pAC);
572 if (pAC->RlmtNets == 2) {
573 pAC->GIni.GIPortUsage = SK_MUL_LINK;
574 }
575
576 pAC->BoardLevel = SK_INIT_IO;
577 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
578
579 if (pAC->GIni.GIMacsFound == 2) {
580 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
581 } else if (pAC->GIni.GIMacsFound == 1) {
582 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
583 pAC->Name, dev);
584 } else {
585 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
586 pAC->GIni.GIMacsFound);
587 return -EAGAIN;
588 }
589
590 if (Ret) {
591 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
592 dev->irq);
593 return -EAGAIN;
594 }
595 pAC->AllocFlag |= SK_ALLOC_IRQ;
596
597 /* Alloc memory for this board (Mem for RxD/TxD) : */
598 if(!BoardAllocMem(pAC)) {
599 printk("No memory for descriptor rings.\n");
600 return(-EAGAIN);
601 }
602
603 SkCsSetReceiveFlags(pAC,
604 SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
605 &pAC->CsOfs1, &pAC->CsOfs2, 0);
606 pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
607
608 BoardInitMem(pAC);
609 /* tschilling: New common function with minimum size check. */
610 DualNet = SK_FALSE;
611 if (pAC->RlmtNets == 2) {
612 DualNet = SK_TRUE;
613 }
614
615 if (SkGeInitAssignRamToQueues(
616 pAC,
617 pAC->ActivePort,
618 DualNet)) {
619 BoardFreeMem(pAC);
620 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
621 return(-EAGAIN);
622 }
623
624 return (0);
625} /* SkGeBoardInit */
626
627
628/*****************************************************************************
629 *
630 * BoardAllocMem - allocate the memory for the descriptor rings
631 *
632 * Description:
633 * This function allocates the memory for all descriptor rings.
634 * Each ring is aligned for the desriptor alignment and no ring
635 * has a 4 GByte boundary in it (because the upper 32 bit must
636 * be constant for all descriptiors in one rings).
637 *
638 * Returns:
639 * SK_TRUE, if all memory could be allocated
640 * SK_FALSE, if not
641 */
642static SK_BOOL BoardAllocMem(
643SK_AC *pAC)
644{
645caddr_t pDescrMem; /* pointer to descriptor memory area */
646size_t AllocLength; /* length of complete descriptor area */
647int i; /* loop counter */
648unsigned long BusAddr;
649
650
651 /* rings plus one for alignment (do not cross 4 GB boundary) */
652 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
653#if (BITS_PER_LONG == 32)
654 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
655#else
656 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
657 + RX_RING_SIZE + 8;
658#endif
659
660 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
661 &pAC->pDescrMemDMA);
662
663 if (pDescrMem == NULL) {
664 return (SK_FALSE);
665 }
666 pAC->pDescrMem = pDescrMem;
667 BusAddr = (unsigned long) pAC->pDescrMemDMA;
668
669 /* Descriptors need 8 byte alignment, and this is ensured
670 * by pci_alloc_consistent.
671 */
672 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
673 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
674 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
675 i, (unsigned long) pDescrMem,
676 BusAddr));
677 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
678 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
679 pDescrMem += TX_RING_SIZE;
680 BusAddr += TX_RING_SIZE;
681
682 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
683 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
684 i, (unsigned long) pDescrMem,
685 (unsigned long)BusAddr));
686 pAC->RxPort[i].pRxDescrRing = pDescrMem;
687 pAC->RxPort[i].VRxDescrRing = BusAddr;
688 pDescrMem += RX_RING_SIZE;
689 BusAddr += RX_RING_SIZE;
690 } /* for */
691
692 return (SK_TRUE);
693} /* BoardAllocMem */
694
695
696/****************************************************************************
697 *
698 * BoardFreeMem - reverse of BoardAllocMem
699 *
700 * Description:
701 * Free all memory allocated in BoardAllocMem: adapter context,
702 * descriptor rings, locks.
703 *
704 * Returns: N/A
705 */
706static void BoardFreeMem(
707SK_AC *pAC)
708{
709size_t AllocLength; /* length of complete descriptor area */
710
711 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
712 ("BoardFreeMem\n"));
713#if (BITS_PER_LONG == 32)
714 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
715#else
716 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
717 + RX_RING_SIZE + 8;
718#endif
719
720 pci_free_consistent(pAC->PciDev, AllocLength,
721 pAC->pDescrMem, pAC->pDescrMemDMA);
722 pAC->pDescrMem = NULL;
723} /* BoardFreeMem */
724
725
726/*****************************************************************************
727 *
728 * BoardInitMem - initiate the descriptor rings
729 *
730 * Description:
731 * This function sets the descriptor rings up in memory.
732 * The adapter is initialized with the descriptor start addresses.
733 *
734 * Returns: N/A
735 */
736static void BoardInitMem(
737SK_AC *pAC) /* pointer to adapter context */
738{
739int i; /* loop counter */
740int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
741int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
742
743 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
744 ("BoardInitMem\n"));
745
746 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
747 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
748 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
749 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
750
751 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
752 SetupRing(
753 pAC,
754 pAC->TxPort[i][0].pTxDescrRing,
755 pAC->TxPort[i][0].VTxDescrRing,
756 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
757 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
758 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
759 &pAC->TxPort[i][0].TxdRingFree,
760 SK_TRUE);
761 SetupRing(
762 pAC,
763 pAC->RxPort[i].pRxDescrRing,
764 pAC->RxPort[i].VRxDescrRing,
765 &pAC->RxPort[i].pRxdRingHead,
766 &pAC->RxPort[i].pRxdRingTail,
767 &pAC->RxPort[i].pRxdRingPrev,
768 &pAC->RxPort[i].RxdRingFree,
769 SK_FALSE);
770 }
771} /* BoardInitMem */
772
773
774/*****************************************************************************
775 *
776 * SetupRing - create one descriptor ring
777 *
778 * Description:
779 * This function creates one descriptor ring in the given memory area.
780 * The head, tail and number of free descriptors in the ring are set.
781 *
782 * Returns:
783 * none
784 */
785static void SetupRing(
786SK_AC *pAC,
787void *pMemArea, /* a pointer to the memory area for the ring */
788uintptr_t VMemArea, /* the virtual bus address of the memory area */
789RXD **ppRingHead, /* address where the head should be written */
790RXD **ppRingTail, /* address where the tail should be written */
791RXD **ppRingPrev, /* address where the tail should be written */
792int *pRingFree, /* address where the # of free descr. goes */
793SK_BOOL IsTx) /* flag: is this a tx ring */
794{
795int i; /* loop counter */
796int DescrSize; /* the size of a descriptor rounded up to alignment*/
797int DescrNum; /* number of descriptors per ring */
798RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
799RXD *pNextDescr; /* pointer to the next descriptor */
800RXD *pPrevDescr; /* pointer to the previous descriptor */
801uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
802
803 if (IsTx == SK_TRUE) {
804 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
805 DESCR_ALIGN;
806 DescrNum = TX_RING_SIZE / DescrSize;
807 } else {
808 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
809 DESCR_ALIGN;
810 DescrNum = RX_RING_SIZE / DescrSize;
811 }
812
813 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
814 ("Descriptor size: %d Descriptor Number: %d\n",
815 DescrSize,DescrNum));
816
817 pDescr = (RXD*) pMemArea;
818 pPrevDescr = NULL;
819 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
820 VNextDescr = VMemArea + DescrSize;
821 for(i=0; i<DescrNum; i++) {
822 /* set the pointers right */
823 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
824 pDescr->pNextRxd = pNextDescr;
825 pDescr->TcpSumStarts = pAC->CsOfs;
826
827 /* advance one step */
828 pPrevDescr = pDescr;
829 pDescr = pNextDescr;
830 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
831 VNextDescr += DescrSize;
832 }
833 pPrevDescr->pNextRxd = (RXD*) pMemArea;
834 pPrevDescr->VNextRxd = VMemArea;
835 pDescr = (RXD*) pMemArea;
836 *ppRingHead = (RXD*) pMemArea;
837 *ppRingTail = *ppRingHead;
838 *ppRingPrev = pPrevDescr;
839 *pRingFree = DescrNum;
840} /* SetupRing */
841
842
843/*****************************************************************************
844 *
845 * PortReInitBmu - re-initiate the descriptor rings for one port
846 *
847 * Description:
848 * This function reinitializes the descriptor rings of one port
849 * in memory. The port must be stopped before.
850 * The HW is initialized with the descriptor start addresses.
851 *
852 * Returns:
853 * none
854 */
855static void PortReInitBmu(
856SK_AC *pAC, /* pointer to adapter context */
857int PortIndex) /* index of the port for which to re-init */
858{
859 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
860 ("PortReInitBmu "));
861
862 /* set address of first descriptor of ring in BMU */
863 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
864 (uint32_t)(((caddr_t)
865 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
866 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
867 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
868 0xFFFFFFFF));
869 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
870 (uint32_t)(((caddr_t)
871 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
872 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
873 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
874 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
875 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
876 pAC->RxPort[PortIndex].pRxDescrRing +
877 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
878 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
879 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
880 pAC->RxPort[PortIndex].pRxDescrRing +
881 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
882} /* PortReInitBmu */
883
884
885/****************************************************************************
886 *
887 * SkGeIsr - handle adapter interrupts
888 *
889 * Description:
890 * The interrupt routine is called when the network adapter
891 * generates an interrupt. It may also be called if another device
892 * shares this interrupt vector with the driver.
893 *
894 * Returns: N/A
895 *
896 */
897static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
898{
899struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
900DEV_NET *pNet;
901SK_AC *pAC;
902SK_U32 IntSrc; /* interrupts source register contents */
903
904 pNet = netdev_priv(dev);
905 pAC = pNet->pAC;
906
907 /*
908 * Check and process if its our interrupt
909 */
910 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
911 if (IntSrc == 0) {
912 return SkIsrRetNone;
913 }
914
915 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
916#if 0 /* software irq currently not used */
917 if (IntSrc & IS_IRQ_SW) {
918 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
919 SK_DBGCAT_DRV_INT_SRC,
920 ("Software IRQ\n"));
921 }
922#endif
923 if (IntSrc & IS_R1_F) {
924 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
925 SK_DBGCAT_DRV_INT_SRC,
926 ("EOF RX1 IRQ\n"));
927 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
928 SK_PNMI_CNT_RX_INTR(pAC, 0);
929 }
930 if (IntSrc & IS_R2_F) {
931 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
932 SK_DBGCAT_DRV_INT_SRC,
933 ("EOF RX2 IRQ\n"));
934 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
935 SK_PNMI_CNT_RX_INTR(pAC, 1);
936 }
937#ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
938 if (IntSrc & IS_XA1_F) {
939 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
940 SK_DBGCAT_DRV_INT_SRC,
941 ("EOF AS TX1 IRQ\n"));
942 SK_PNMI_CNT_TX_INTR(pAC, 0);
943 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
944 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
945 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
946 }
947 if (IntSrc & IS_XA2_F) {
948 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
949 SK_DBGCAT_DRV_INT_SRC,
950 ("EOF AS TX2 IRQ\n"));
951 SK_PNMI_CNT_TX_INTR(pAC, 1);
952 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
953 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
954 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
955 }
956#if 0 /* only if sync. queues used */
957 if (IntSrc & IS_XS1_F) {
958 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
959 SK_DBGCAT_DRV_INT_SRC,
960 ("EOF SY TX1 IRQ\n"));
961 SK_PNMI_CNT_TX_INTR(pAC, 1);
962 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
963 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
964 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
965 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
966 }
967 if (IntSrc & IS_XS2_F) {
968 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
969 SK_DBGCAT_DRV_INT_SRC,
970 ("EOF SY TX2 IRQ\n"));
971 SK_PNMI_CNT_TX_INTR(pAC, 1);
972 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
973 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
974 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
975 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
976 }
977#endif
978#endif
979
980 /* do all IO at once */
981 if (IntSrc & IS_R1_F)
982 ClearAndStartRx(pAC, 0);
983 if (IntSrc & IS_R2_F)
984 ClearAndStartRx(pAC, 1);
985#ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
986 if (IntSrc & IS_XA1_F)
987 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
988 if (IntSrc & IS_XA2_F)
989 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
990#endif
991 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
992 } /* while (IntSrc & IRQ_MASK != 0) */
993
994 IntSrc &= pAC->GIni.GIValIrqMask;
995 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
996 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
997 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
998 pAC->CheckQueue = SK_FALSE;
999 spin_lock(&pAC->SlowPathLock);
1000 if (IntSrc & SPECIAL_IRQS)
1001 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1002
1003 SkEventDispatcher(pAC, pAC->IoBase);
1004 spin_unlock(&pAC->SlowPathLock);
1005 }
1006 /*
1007 * do it all again is case we cleared an interrupt that
1008 * came in after handling the ring (OUTs may be delayed
1009 * in hardware buffers, but are through after IN)
1010 *
1011 * rroesler: has been commented out and shifted to
1012 * SkGeDrvEvent(), because it is timer
1013 * guarded now
1014 *
1015 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1016 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1017 */
1018
1019 if (pAC->CheckQueue) {
1020 pAC->CheckQueue = SK_FALSE;
1021 spin_lock(&pAC->SlowPathLock);
1022 SkEventDispatcher(pAC, pAC->IoBase);
1023 spin_unlock(&pAC->SlowPathLock);
1024 }
1025
1026 /* IRQ is processed - Enable IRQs again*/
1027 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1028
1029 return SkIsrRetHandled;
1030} /* SkGeIsr */
1031
1032
1033/****************************************************************************
1034 *
1035 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1036 *
1037 * Description:
1038 * The interrupt routine is called when the network adapter
1039 * generates an interrupt. It may also be called if another device
1040 * shares this interrupt vector with the driver.
1041 * This is the same as above, but handles only one port.
1042 *
1043 * Returns: N/A
1044 *
1045 */
1046static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1047{
1048struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1049DEV_NET *pNet;
1050SK_AC *pAC;
1051SK_U32 IntSrc; /* interrupts source register contents */
1052
1053 pNet = netdev_priv(dev);
1054 pAC = pNet->pAC;
1055
1056 /*
1057 * Check and process if its our interrupt
1058 */
1059 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1060 if (IntSrc == 0) {
1061 return SkIsrRetNone;
1062 }
1063
1064 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1065#if 0 /* software irq currently not used */
1066 if (IntSrc & IS_IRQ_SW) {
1067 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1068 SK_DBGCAT_DRV_INT_SRC,
1069 ("Software IRQ\n"));
1070 }
1071#endif
1072 if (IntSrc & IS_R1_F) {
1073 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1074 SK_DBGCAT_DRV_INT_SRC,
1075 ("EOF RX1 IRQ\n"));
1076 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1077 SK_PNMI_CNT_RX_INTR(pAC, 0);
1078 }
1079#ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1080 if (IntSrc & IS_XA1_F) {
1081 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1082 SK_DBGCAT_DRV_INT_SRC,
1083 ("EOF AS TX1 IRQ\n"));
1084 SK_PNMI_CNT_TX_INTR(pAC, 0);
1085 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1086 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1087 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1088 }
1089#if 0 /* only if sync. queues used */
1090 if (IntSrc & IS_XS1_F) {
1091 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1092 SK_DBGCAT_DRV_INT_SRC,
1093 ("EOF SY TX1 IRQ\n"));
1094 SK_PNMI_CNT_TX_INTR(pAC, 0);
1095 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1096 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1097 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1098 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1099 }
1100#endif
1101#endif
1102
1103 /* do all IO at once */
1104 if (IntSrc & IS_R1_F)
1105 ClearAndStartRx(pAC, 0);
1106#ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1107 if (IntSrc & IS_XA1_F)
1108 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1109#endif
1110 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1111 } /* while (IntSrc & IRQ_MASK != 0) */
1112
1113 IntSrc &= pAC->GIni.GIValIrqMask;
1114 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1115 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1116 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1117 pAC->CheckQueue = SK_FALSE;
1118 spin_lock(&pAC->SlowPathLock);
1119 if (IntSrc & SPECIAL_IRQS)
1120 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1121
1122 SkEventDispatcher(pAC, pAC->IoBase);
1123 spin_unlock(&pAC->SlowPathLock);
1124 }
1125 /*
1126 * do it all again is case we cleared an interrupt that
1127 * came in after handling the ring (OUTs may be delayed
1128 * in hardware buffers, but are through after IN)
1129 *
1130 * rroesler: has been commented out and shifted to
1131 * SkGeDrvEvent(), because it is timer
1132 * guarded now
1133 *
1134 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1135 */
1136
1137 /* IRQ is processed - Enable IRQs again*/
1138 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1139
1140 return SkIsrRetHandled;
1141} /* SkGeIsrOnePort */
1142
1143#ifdef CONFIG_NET_POLL_CONTROLLER
1144/****************************************************************************
1145 *
1146 * SkGePollController - polling receive, for netconsole
1147 *
1148 * Description:
1149 * Polling receive - used by netconsole and other diagnostic tools
1150 * to allow network i/o with interrupts disabled.
1151 *
1152 * Returns: N/A
1153 */
1154static void SkGePollController(struct net_device *dev)
1155{
1156 disable_irq(dev->irq);
1157 SkGeIsr(dev->irq, dev, NULL);
1158 enable_irq(dev->irq);
1159}
1160#endif
1161
1162/****************************************************************************
1163 *
1164 * SkGeOpen - handle start of initialized adapter
1165 *
1166 * Description:
1167 * This function starts the initialized adapter.
1168 * The board level variable is set and the adapter is
1169 * brought to full functionality.
1170 * The device flags are set for operation.
1171 * Do all necessary level 2 initialization, enable interrupts and
1172 * give start command to RLMT.
1173 *
1174 * Returns:
1175 * 0 on success
1176 * != 0 on error
1177 */
1178static int SkGeOpen(
1179struct SK_NET_DEVICE *dev)
1180{
1181 DEV_NET *pNet;
1182 SK_AC *pAC;
1183 unsigned long Flags; /* for spin lock */
1184 int i;
1185 SK_EVPARA EvPara; /* an event parameter union */
1186
1187 pNet = netdev_priv(dev);
1188 pAC = pNet->pAC;
1189
1190 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1191 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1192
1193#ifdef SK_DIAG_SUPPORT
1194 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1195 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1196 return (-1); /* still in use by diag; deny actions */
1197 }
1198 }
1199#endif
1200
1201 /* Set blink mode */
1202 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1203 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1204
1205 if (pAC->BoardLevel == SK_INIT_DATA) {
1206 /* level 1 init common modules here */
1207 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1208 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1209 return (-1);
1210 }
1211 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1212 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1213 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1214 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1215 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1216 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1217 pAC->BoardLevel = SK_INIT_IO;
1218 }
1219
1220 if (pAC->BoardLevel != SK_INIT_RUN) {
1221 /* tschilling: Level 2 init modules here, check return value. */
1222 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1223 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1224 return (-1);
1225 }
1226 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1227 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1228 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1229 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1230 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1231 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1232 pAC->BoardLevel = SK_INIT_RUN;
1233 }
1234
1235 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1236 /* Enable transmit descriptor polling. */
1237 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1238 FillRxRing(pAC, &pAC->RxPort[i]);
1239 }
1240 SkGeYellowLED(pAC, pAC->IoBase, 1);
1241
1242 StartDrvCleanupTimer(pAC);
1243 SkDimEnableModerationIfNeeded(pAC);
1244 SkDimDisplayModerationSettings(pAC);
1245
1246 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1247
1248 /* enable Interrupts */
1249 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1250 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1251
1252 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1253
1254 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1255 EvPara.Para32[0] = pAC->RlmtNets;
1256 EvPara.Para32[1] = -1;
1257 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1258 EvPara);
1259 EvPara.Para32[0] = pAC->RlmtMode;
1260 EvPara.Para32[1] = 0;
1261 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1262 EvPara);
1263 }
1264
1265 EvPara.Para32[0] = pNet->NetNr;
1266 EvPara.Para32[1] = -1;
1267 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1268 SkEventDispatcher(pAC, pAC->IoBase);
1269 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1270
1271 pAC->MaxPorts++;
1272 pNet->Up = 1;
1273
1274
1275 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1276 ("SkGeOpen suceeded\n"));
1277
1278 return (0);
1279} /* SkGeOpen */
1280
1281
1282/****************************************************************************
1283 *
1284 * SkGeClose - Stop initialized adapter
1285 *
1286 * Description:
1287 * Close initialized adapter.
1288 *
1289 * Returns:
1290 * 0 - on success
1291 * error code - on error
1292 */
1293static int SkGeClose(
1294struct SK_NET_DEVICE *dev)
1295{
1296 DEV_NET *pNet;
1297 DEV_NET *newPtrNet;
1298 SK_AC *pAC;
1299
1300 unsigned long Flags; /* for spin lock */
1301 int i;
1302 int PortIdx;
1303 SK_EVPARA EvPara;
1304
1305 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1306 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1307
1308 pNet = netdev_priv(dev);
1309 pAC = pNet->pAC;
1310
1311#ifdef SK_DIAG_SUPPORT
1312 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1313 if (pAC->DiagFlowCtrl == SK_FALSE) {
1314 /*
1315 ** notify that the interface which has been closed
1316 ** by operator interaction must not be started up
1317 ** again when the DIAG has finished.
1318 */
1319 newPtrNet = netdev_priv(pAC->dev[0]);
1320 if (newPtrNet == pNet) {
1321 pAC->WasIfUp[0] = SK_FALSE;
1322 } else {
1323 pAC->WasIfUp[1] = SK_FALSE;
1324 }
1325 return 0; /* return to system everything is fine... */
1326 } else {
1327 pAC->DiagFlowCtrl = SK_FALSE;
1328 }
1329 }
1330#endif
1331
1332 netif_stop_queue(dev);
1333
1334 if (pAC->RlmtNets == 1)
1335 PortIdx = pAC->ActivePort;
1336 else
1337 PortIdx = pNet->NetNr;
1338
1339 StopDrvCleanupTimer(pAC);
1340
1341 /*
1342 * Clear multicast table, promiscuous mode ....
1343 */
1344 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1345 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1346 SK_PROM_MODE_NONE);
1347
1348 if (pAC->MaxPorts == 1) {
1349 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1350 /* disable interrupts */
1351 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1352 EvPara.Para32[0] = pNet->NetNr;
1353 EvPara.Para32[1] = -1;
1354 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1355 SkEventDispatcher(pAC, pAC->IoBase);
1356 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1357 /* stop the hardware */
1358 SkGeDeInit(pAC, pAC->IoBase);
1359 pAC->BoardLevel = SK_INIT_DATA;
1360 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1361 } else {
1362
1363 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1364 EvPara.Para32[0] = pNet->NetNr;
1365 EvPara.Para32[1] = -1;
1366 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1367 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1368 SkEventDispatcher(pAC, pAC->IoBase);
1369 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1370
1371 /* Stop port */
1372 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1373 [TX_PRIO_LOW].TxDesRingLock, Flags);
1374 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1375 SK_STOP_ALL, SK_HARD_RST);
1376 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1377 [TX_PRIO_LOW].TxDesRingLock, Flags);
1378 }
1379
1380 if (pAC->RlmtNets == 1) {
1381 /* clear all descriptor rings */
1382 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1383 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1384 ClearRxRing(pAC, &pAC->RxPort[i]);
1385 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1386 }
1387 } else {
1388 /* clear port descriptor rings */
1389 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1390 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1391 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1392 }
1393
1394 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1395 ("SkGeClose: done "));
1396
1397 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1398 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1399 sizeof(SK_PNMI_STRUCT_DATA));
1400
1401 pAC->MaxPorts--;
1402 pNet->Up = 0;
1403
1404 return (0);
1405} /* SkGeClose */
1406
1407
1408/*****************************************************************************
1409 *
1410 * SkGeXmit - Linux frame transmit function
1411 *
1412 * Description:
1413 * The system calls this function to send frames onto the wire.
1414 * It puts the frame in the tx descriptor ring. If the ring is
1415 * full then, the 'tbusy' flag is set.
1416 *
1417 * Returns:
1418 * 0, if everything is ok
1419 * !=0, on error
1420 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1421 * allocated skb's) !!!
1422 */
1423static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1424{
1425DEV_NET *pNet;
1426SK_AC *pAC;
1427int Rc; /* return code of XmitFrame */
1428
1429 pNet = netdev_priv(dev);
1430 pAC = pNet->pAC;
1431
1432 if ((!skb_shinfo(skb)->nr_frags) ||
1433 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1434 /* Don't activate scatter-gather and hardware checksum */
1435
1436 if (pAC->RlmtNets == 2)
1437 Rc = XmitFrame(
1438 pAC,
1439 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1440 skb);
1441 else
1442 Rc = XmitFrame(
1443 pAC,
1444 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1445 skb);
1446 } else {
1447 /* scatter-gather and hardware TCP checksumming anabled*/
1448 if (pAC->RlmtNets == 2)
1449 Rc = XmitFrameSG(
1450 pAC,
1451 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1452 skb);
1453 else
1454 Rc = XmitFrameSG(
1455 pAC,
1456 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1457 skb);
1458 }
1459
1460 /* Transmitter out of resources? */
1461 if (Rc <= 0) {
1462 netif_stop_queue(dev);
1463 }
1464
1465 /* If not taken, give buffer ownership back to the
1466 * queueing layer.
1467 */
1468 if (Rc < 0)
1469 return (1);
1470
1471 dev->trans_start = jiffies;
1472 return (0);
1473} /* SkGeXmit */
1474
1475
1476/*****************************************************************************
1477 *
1478 * XmitFrame - fill one socket buffer into the transmit ring
1479 *
1480 * Description:
1481 * This function puts a message into the transmit descriptor ring
1482 * if there is a descriptors left.
1483 * Linux skb's consist of only one continuous buffer.
1484 * The first step locks the ring. It is held locked
1485 * all time to avoid problems with SWITCH_../PORT_RESET.
1486 * Then the descriptoris allocated.
1487 * The second part is linking the buffer to the descriptor.
1488 * At the very last, the Control field of the descriptor
1489 * is made valid for the BMU and a start TX command is given
1490 * if necessary.
1491 *
1492 * Returns:
1493 * > 0 - on succes: the number of bytes in the message
1494 * = 0 - on resource shortage: this frame sent or dropped, now
1495 * the ring is full ( -> set tbusy)
1496 * < 0 - on failure: other problems ( -> return failure to upper layers)
1497 */
1498static int XmitFrame(
1499SK_AC *pAC, /* pointer to adapter context */
1500TX_PORT *pTxPort, /* pointer to struct of port to send to */
1501struct sk_buff *pMessage) /* pointer to send-message */
1502{
1503 TXD *pTxd; /* the rxd to fill */
1504 TXD *pOldTxd;
1505 unsigned long Flags;
1506 SK_U64 PhysAddr;
1507 int Protocol;
1508 int IpHeaderLength;
1509 int BytesSend = pMessage->len;
1510
1511 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1512
1513 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1514#ifndef USE_TX_COMPLETE
1515 FreeTxDescriptors(pAC, pTxPort);
1516#endif
1517 if (pTxPort->TxdRingFree == 0) {
1518 /*
1519 ** no enough free descriptors in ring at the moment.
1520 ** Maybe free'ing some old one help?
1521 */
1522 FreeTxDescriptors(pAC, pTxPort);
1523 if (pTxPort->TxdRingFree == 0) {
1524 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1525 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1526 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1527 SK_DBGCAT_DRV_TX_PROGRESS,
1528 ("XmitFrame failed\n"));
1529 /*
1530 ** the desired message can not be sent
1531 ** Because tbusy seems to be set, the message
1532 ** should not be freed here. It will be used
1533 ** by the scheduler of the ethernet handler
1534 */
1535 return (-1);
1536 }
1537 }
1538
1539 /*
1540 ** If the passed socket buffer is of smaller MTU-size than 60,
1541 ** copy everything into new buffer and fill all bytes between
1542 ** the original packet end and the new packet end of 60 with 0x00.
1543 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1544 */
1545 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1546 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1547 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1548 return 0;
1549 }
1550 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1551 }
1552
1553 /*
1554 ** advance head counter behind descriptor needed for this frame,
1555 ** so that needed descriptor is reserved from that on. The next
1556 ** action will be to add the passed buffer to the TX-descriptor
1557 */
1558 pTxd = pTxPort->pTxdRingHead;
1559 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1560 pTxPort->TxdRingFree--;
1561
1562#ifdef SK_DUMP_TX
1563 DumpMsg(pMessage, "XmitFrame");
1564#endif
1565
1566 /*
1567 ** First step is to map the data to be sent via the adapter onto
1568 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1569 ** and 2.6 need to use pci_map_page() for that mapping.
1570 */
1571 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1572 virt_to_page(pMessage->data),
1573 ((unsigned long) pMessage->data & ~PAGE_MASK),
1574 pMessage->len,
1575 PCI_DMA_TODEVICE);
1576 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1577 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1578 pTxd->pMBuf = pMessage;
1579
1580 if (pMessage->ip_summed == CHECKSUM_HW) {
1581 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1582 if ((Protocol == C_PROTO_ID_UDP) &&
1583 (pAC->GIni.GIChipRev == 0) &&
1584 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1585 pTxd->TBControl = BMU_TCP_CHECK;
1586 } else {
1587 pTxd->TBControl = BMU_UDP_CHECK;
1588 }
1589
1590 IpHeaderLength = (SK_U8)pMessage->data[C_OFFSET_IPHEADER];
1591 IpHeaderLength = (IpHeaderLength & 0xf) * 4;
1592 pTxd->TcpSumOfs = 0; /* PH-Checksum already calculated */
1593 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1594 (Protocol == C_PROTO_ID_UDP ?
1595 C_OFFSET_UDPHEADER_UDPCS :
1596 C_OFFSET_TCPHEADER_TCPCS);
1597 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1598
1599 pTxd->TBControl |= BMU_OWN | BMU_STF |
1600 BMU_SW | BMU_EOF |
1601#ifdef USE_TX_COMPLETE
1602 BMU_IRQ_EOF |
1603#endif
1604 pMessage->len;
1605 } else {
1606 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1607 BMU_SW | BMU_EOF |
1608#ifdef USE_TX_COMPLETE
1609 BMU_IRQ_EOF |
1610#endif
1611 pMessage->len;
1612 }
1613
1614 /*
1615 ** If previous descriptor already done, give TX start cmd
1616 */
1617 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1618 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1619 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1620 }
1621
1622 /*
1623 ** after releasing the lock, the skb may immediately be free'd
1624 */
1625 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1626 if (pTxPort->TxdRingFree != 0) {
1627 return (BytesSend);
1628 } else {
1629 return (0);
1630 }
1631
1632} /* XmitFrame */
1633
1634/*****************************************************************************
1635 *
1636 * XmitFrameSG - fill one socket buffer into the transmit ring
1637 * (use SG and TCP/UDP hardware checksumming)
1638 *
1639 * Description:
1640 * This function puts a message into the transmit descriptor ring
1641 * if there is a descriptors left.
1642 *
1643 * Returns:
1644 * > 0 - on succes: the number of bytes in the message
1645 * = 0 - on resource shortage: this frame sent or dropped, now
1646 * the ring is full ( -> set tbusy)
1647 * < 0 - on failure: other problems ( -> return failure to upper layers)
1648 */
1649static int XmitFrameSG(
1650SK_AC *pAC, /* pointer to adapter context */
1651TX_PORT *pTxPort, /* pointer to struct of port to send to */
1652struct sk_buff *pMessage) /* pointer to send-message */
1653{
1654
1655 TXD *pTxd;
1656 TXD *pTxdFst;
1657 TXD *pTxdLst;
1658 int CurrFrag;
1659 int BytesSend;
1660 int IpHeaderLength;
1661 int Protocol;
1662 skb_frag_t *sk_frag;
1663 SK_U64 PhysAddr;
1664 unsigned long Flags;
1665
1666 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1667#ifndef USE_TX_COMPLETE
1668 FreeTxDescriptors(pAC, pTxPort);
1669#endif
1670 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1671 FreeTxDescriptors(pAC, pTxPort);
1672 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1673 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1674 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1675 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1676 SK_DBGCAT_DRV_TX_PROGRESS,
1677 ("XmitFrameSG failed - Ring full\n"));
1678 /* this message can not be sent now */
1679 return(-1);
1680 }
1681 }
1682
1683 pTxd = pTxPort->pTxdRingHead;
1684 pTxdFst = pTxd;
1685 pTxdLst = pTxd;
1686 BytesSend = 0;
1687 Protocol = 0;
1688
1689 /*
1690 ** Map the first fragment (header) into the DMA-space
1691 */
1692 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1693 virt_to_page(pMessage->data),
1694 ((unsigned long) pMessage->data & ~PAGE_MASK),
1695 skb_headlen(pMessage),
1696 PCI_DMA_TODEVICE);
1697
1698 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1699 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1700
1701 /*
1702 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1703 */
1704 if (pMessage->ip_summed == CHECKSUM_HW) {
1705 pTxd->TBControl = BMU_STF | BMU_STFWD | skb_headlen(pMessage);
1706 /*
1707 ** We have to use the opcode for tcp here, because the
1708 ** opcode for udp is not working in the hardware yet
1709 ** (Revision 2.0)
1710 */
1711 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1712 if ((Protocol == C_PROTO_ID_UDP) &&
1713 (pAC->GIni.GIChipRev == 0) &&
1714 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1715 pTxd->TBControl |= BMU_TCP_CHECK;
1716 } else {
1717 pTxd->TBControl |= BMU_UDP_CHECK;
1718 }
1719
1720 IpHeaderLength = ((SK_U8)pMessage->data[C_OFFSET_IPHEADER] & 0xf)*4;
1721 pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
1722 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1723 (Protocol == C_PROTO_ID_UDP ?
1724 C_OFFSET_UDPHEADER_UDPCS :
1725 C_OFFSET_TCPHEADER_TCPCS);
1726 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1727 } else {
1728 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_STF |
1729 skb_headlen(pMessage);
1730 }
1731
1732 pTxd = pTxd->pNextTxd;
1733 pTxPort->TxdRingFree--;
1734 BytesSend += skb_headlen(pMessage);
1735
1736 /*
1737 ** Browse over all SG fragments and map each of them into the DMA space
1738 */
1739 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1740 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1741 /*
1742 ** we already have the proper value in entry
1743 */
1744 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1745 sk_frag->page,
1746 sk_frag->page_offset,
1747 sk_frag->size,
1748 PCI_DMA_TODEVICE);
1749
1750 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1751 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1752 pTxd->pMBuf = pMessage;
1753
1754 /*
1755 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1756 */
1757 if (pMessage->ip_summed == CHECKSUM_HW) {
1758 pTxd->TBControl = BMU_OWN | BMU_SW | BMU_STFWD;
1759 /*
1760 ** We have to use the opcode for tcp here because the
1761 ** opcode for udp is not working in the hardware yet
1762 ** (revision 2.0)
1763 */
1764 if ((Protocol == C_PROTO_ID_UDP) &&
1765 (pAC->GIni.GIChipRev == 0) &&
1766 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1767 pTxd->TBControl |= BMU_TCP_CHECK;
1768 } else {
1769 pTxd->TBControl |= BMU_UDP_CHECK;
1770 }
1771 } else {
1772 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_OWN;
1773 }
1774
1775 /*
1776 ** Do we have the last fragment?
1777 */
1778 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1779#ifdef USE_TX_COMPLETE
1780 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF | sk_frag->size;
1781#else
1782 pTxd->TBControl |= BMU_EOF | sk_frag->size;
1783#endif
1784 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1785
1786 } else {
1787 pTxd->TBControl |= sk_frag->size;
1788 }
1789 pTxdLst = pTxd;
1790 pTxd = pTxd->pNextTxd;
1791 pTxPort->TxdRingFree--;
1792 BytesSend += sk_frag->size;
1793 }
1794
1795 /*
1796 ** If previous descriptor already done, give TX start cmd
1797 */
1798 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1799 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1800 }
1801
1802 pTxPort->pTxdRingPrev = pTxdLst;
1803 pTxPort->pTxdRingHead = pTxd;
1804
1805 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1806
1807 if (pTxPort->TxdRingFree > 0) {
1808 return (BytesSend);
1809 } else {
1810 return (0);
1811 }
1812}
1813
1814/*****************************************************************************
1815 *
1816 * FreeTxDescriptors - release descriptors from the descriptor ring
1817 *
1818 * Description:
1819 * This function releases descriptors from a transmit ring if they
1820 * have been sent by the BMU.
1821 * If a descriptors is sent, it can be freed and the message can
1822 * be freed, too.
1823 * The SOFTWARE controllable bit is used to prevent running around a
1824 * completely free ring for ever. If this bit is no set in the
1825 * frame (by XmitFrame), this frame has never been sent or is
1826 * already freed.
1827 * The Tx descriptor ring lock must be held while calling this function !!!
1828 *
1829 * Returns:
1830 * none
1831 */
1832static void FreeTxDescriptors(
1833SK_AC *pAC, /* pointer to the adapter context */
1834TX_PORT *pTxPort) /* pointer to destination port structure */
1835{
1836TXD *pTxd; /* pointer to the checked descriptor */
1837TXD *pNewTail; /* pointer to 'end' of the ring */
1838SK_U32 Control; /* TBControl field of descriptor */
1839SK_U64 PhysAddr; /* address of DMA mapping */
1840
1841 pNewTail = pTxPort->pTxdRingTail;
1842 pTxd = pNewTail;
1843 /*
1844 ** loop forever; exits if BMU_SW bit not set in start frame
1845 ** or BMU_OWN bit set in any frame
1846 */
1847 while (1) {
1848 Control = pTxd->TBControl;
1849 if ((Control & BMU_SW) == 0) {
1850 /*
1851 ** software controllable bit is set in first
1852 ** fragment when given to BMU. Not set means that
1853 ** this fragment was never sent or is already
1854 ** freed ( -> ring completely free now).
1855 */
1856 pTxPort->pTxdRingTail = pTxd;
1857 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1858 return;
1859 }
1860 if (Control & BMU_OWN) {
1861 pTxPort->pTxdRingTail = pTxd;
1862 if (pTxPort->TxdRingFree > 0) {
1863 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1864 }
1865 return;
1866 }
1867
1868 /*
1869 ** release the DMA mapping, because until not unmapped
1870 ** this buffer is considered being under control of the
1871 ** adapter card!
1872 */
1873 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1874 PhysAddr |= (SK_U64) pTxd->VDataLow;
1875 pci_unmap_page(pAC->PciDev, PhysAddr,
1876 pTxd->pMBuf->len,
1877 PCI_DMA_TODEVICE);
1878
1879 if (Control & BMU_EOF)
1880 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1881
1882 pTxPort->TxdRingFree++;
1883 pTxd->TBControl &= ~BMU_SW;
1884 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1885 } /* while(forever) */
1886} /* FreeTxDescriptors */
1887
1888/*****************************************************************************
1889 *
1890 * FillRxRing - fill the receive ring with valid descriptors
1891 *
1892 * Description:
1893 * This function fills the receive ring descriptors with data
1894 * segments and makes them valid for the BMU.
1895 * The active ring is filled completely, if possible.
1896 * The non-active ring is filled only partial to save memory.
1897 *
1898 * Description of rx ring structure:
1899 * head - points to the descriptor which will be used next by the BMU
1900 * tail - points to the next descriptor to give to the BMU
1901 *
1902 * Returns: N/A
1903 */
1904static void FillRxRing(
1905SK_AC *pAC, /* pointer to the adapter context */
1906RX_PORT *pRxPort) /* ptr to port struct for which the ring
1907 should be filled */
1908{
1909unsigned long Flags;
1910
1911 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1912 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1913 if(!FillRxDescriptor(pAC, pRxPort))
1914 break;
1915 }
1916 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1917} /* FillRxRing */
1918
1919
1920/*****************************************************************************
1921 *
1922 * FillRxDescriptor - fill one buffer into the receive ring
1923 *
1924 * Description:
1925 * The function allocates a new receive buffer and
1926 * puts it into the next descriptor.
1927 *
1928 * Returns:
1929 * SK_TRUE - a buffer was added to the ring
1930 * SK_FALSE - a buffer could not be added
1931 */
1932static SK_BOOL FillRxDescriptor(
1933SK_AC *pAC, /* pointer to the adapter context struct */
1934RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1935{
1936struct sk_buff *pMsgBlock; /* pointer to a new message block */
1937RXD *pRxd; /* the rxd to fill */
1938SK_U16 Length; /* data fragment length */
1939SK_U64 PhysAddr; /* physical address of a rx buffer */
1940
1941 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1942 if (pMsgBlock == NULL) {
1943 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1944 SK_DBGCAT_DRV_ENTRY,
1945 ("%s: Allocation of rx buffer failed !\n",
1946 pAC->dev[pRxPort->PortIndex]->name));
1947 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1948 return(SK_FALSE);
1949 }
1950 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1951 /* skb allocated ok, so add buffer */
1952 pRxd = pRxPort->pRxdRingTail;
1953 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1954 pRxPort->RxdRingFree--;
1955 Length = pAC->RxBufSize;
1956 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1957 virt_to_page(pMsgBlock->data),
1958 ((unsigned long) pMsgBlock->data &
1959 ~PAGE_MASK),
1960 pAC->RxBufSize - 2,
1961 PCI_DMA_FROMDEVICE);
1962
1963 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1964 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1965 pRxd->pMBuf = pMsgBlock;
1966 pRxd->RBControl = BMU_OWN |
1967 BMU_STF |
1968 BMU_IRQ_EOF |
1969 BMU_TCP_CHECK |
1970 Length;
1971 return (SK_TRUE);
1972
1973} /* FillRxDescriptor */
1974
1975
1976/*****************************************************************************
1977 *
1978 * ReQueueRxBuffer - fill one buffer back into the receive ring
1979 *
1980 * Description:
1981 * Fill a given buffer back into the rx ring. The buffer
1982 * has been previously allocated and aligned, and its phys.
1983 * address calculated, so this is no more necessary.
1984 *
1985 * Returns: N/A
1986 */
1987static void ReQueueRxBuffer(
1988SK_AC *pAC, /* pointer to the adapter context struct */
1989RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1990struct sk_buff *pMsg, /* pointer to the buffer */
1991SK_U32 PhysHigh, /* phys address high dword */
1992SK_U32 PhysLow) /* phys address low dword */
1993{
1994RXD *pRxd; /* the rxd to fill */
1995SK_U16 Length; /* data fragment length */
1996
1997 pRxd = pRxPort->pRxdRingTail;
1998 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1999 pRxPort->RxdRingFree--;
2000 Length = pAC->RxBufSize;
2001
2002 pRxd->VDataLow = PhysLow;
2003 pRxd->VDataHigh = PhysHigh;
2004 pRxd->pMBuf = pMsg;
2005 pRxd->RBControl = BMU_OWN |
2006 BMU_STF |
2007 BMU_IRQ_EOF |
2008 BMU_TCP_CHECK |
2009 Length;
2010 return;
2011} /* ReQueueRxBuffer */
2012
2013/*****************************************************************************
2014 *
2015 * ReceiveIrq - handle a receive IRQ
2016 *
2017 * Description:
2018 * This function is called when a receive IRQ is set.
2019 * It walks the receive descriptor ring and sends up all
2020 * frames that are complete.
2021 *
2022 * Returns: N/A
2023 */
2024static void ReceiveIrq(
2025 SK_AC *pAC, /* pointer to adapter context */
2026 RX_PORT *pRxPort, /* pointer to receive port struct */
2027 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
2028{
2029RXD *pRxd; /* pointer to receive descriptors */
2030SK_U32 Control; /* control field of descriptor */
2031struct sk_buff *pMsg; /* pointer to message holding frame */
2032struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
2033int FrameLength; /* total length of received frame */
2034int IpFrameLength;
2035SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2036SK_EVPARA EvPara; /* an event parameter union */
2037unsigned long Flags; /* for spin lock */
2038int PortIndex = pRxPort->PortIndex;
2039unsigned int Offset;
2040unsigned int NumBytes;
2041unsigned int ForRlmt;
2042SK_BOOL IsBc;
2043SK_BOOL IsMc;
2044SK_BOOL IsBadFrame; /* Bad frame */
2045
2046SK_U32 FrameStat;
2047unsigned short Csum1;
2048unsigned short Csum2;
2049unsigned short Type;
2050int Result;
2051SK_U64 PhysAddr;
2052
2053rx_start:
2054 /* do forever; exit if BMU_OWN found */
2055 for ( pRxd = pRxPort->pRxdRingHead ;
2056 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2057 pRxd = pRxd->pNextRxd,
2058 pRxPort->pRxdRingHead = pRxd,
2059 pRxPort->RxdRingFree ++) {
2060
2061 /*
2062 * For a better understanding of this loop
2063 * Go through every descriptor beginning at the head
2064 * Please note: the ring might be completely received so the OWN bit
2065 * set is not a good crirteria to leave that loop.
2066 * Therefore the RingFree counter is used.
2067 * On entry of this loop pRxd is a pointer to the Rxd that needs
2068 * to be checked next.
2069 */
2070
2071 Control = pRxd->RBControl;
2072
2073 /* check if this descriptor is ready */
2074 if ((Control & BMU_OWN) != 0) {
2075 /* this descriptor is not yet ready */
2076 /* This is the usual end of the loop */
2077 /* We don't need to start the ring again */
2078 FillRxRing(pAC, pRxPort);
2079 return;
2080 }
2081 pAC->DynIrqModInfo.NbrProcessedDescr++;
2082
2083 /* get length of frame and check it */
2084 FrameLength = Control & BMU_BBC;
2085 if (FrameLength > pAC->RxBufSize) {
2086 goto rx_failed;
2087 }
2088
2089 /* check for STF and EOF */
2090 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2091 goto rx_failed;
2092 }
2093
2094 /* here we have a complete frame in the ring */
2095 pMsg = pRxd->pMBuf;
2096
2097 FrameStat = pRxd->FrameStat;
2098
2099 /* check for frame length mismatch */
2100#define XMR_FS_LEN_SHIFT 18
2101#define GMR_FS_LEN_SHIFT 16
2102 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2103 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2104 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2105 SK_DBGCAT_DRV_RX_PROGRESS,
2106 ("skge: Frame length mismatch (%u/%u).\n",
2107 FrameLength,
2108 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2109 goto rx_failed;
2110 }
2111 }
2112 else {
2113 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2114 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2115 SK_DBGCAT_DRV_RX_PROGRESS,
2116 ("skge: Frame length mismatch (%u/%u).\n",
2117 FrameLength,
2118 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2119 goto rx_failed;
2120 }
2121 }
2122
2123 /* Set Rx Status */
2124 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2125 IsBc = (FrameStat & XMR_FS_BC) != 0;
2126 IsMc = (FrameStat & XMR_FS_MC) != 0;
2127 IsBadFrame = (FrameStat &
2128 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2129 } else {
2130 IsBc = (FrameStat & GMR_FS_BC) != 0;
2131 IsMc = (FrameStat & GMR_FS_MC) != 0;
2132 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2133 ((FrameStat & GMR_FS_RX_OK) == 0));
2134 }
2135
2136 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2137 ("Received frame of length %d on port %d\n",
2138 FrameLength, PortIndex));
2139 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2140 ("Number of free rx descriptors: %d\n",
2141 pRxPort->RxdRingFree));
2142/* DumpMsg(pMsg, "Rx"); */
2143
2144 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2145#if 0
2146 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2147#endif
2148 /* there is a receive error in this frame */
2149 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2150 SK_DBGCAT_DRV_RX_PROGRESS,
2151 ("skge: Error in received frame, dropped!\n"
2152 "Control: %x\nRxStat: %x\n",
2153 Control, FrameStat));
2154
2155 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2156 pRxd->VDataHigh, pRxd->VDataLow);
2157
2158 continue;
2159 }
2160
2161 /*
2162 * if short frame then copy data to reduce memory waste
2163 */
2164 if ((FrameLength < SK_COPY_THRESHOLD) &&
2165 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2166 /*
2167 * Short frame detected and allocation successfull
2168 */
2169 /* use new skb and copy data */
2170 skb_reserve(pNewMsg, 2);
2171 skb_put(pNewMsg, FrameLength);
2172 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2173 PhysAddr |= (SK_U64) pRxd->VDataLow;
2174
2175 pci_dma_sync_single_for_cpu(pAC->PciDev,
2176 (dma_addr_t) PhysAddr,
2177 FrameLength,
2178 PCI_DMA_FROMDEVICE);
2179 eth_copy_and_sum(pNewMsg, pMsg->data,
2180 FrameLength, 0);
2181 pci_dma_sync_single_for_device(pAC->PciDev,
2182 (dma_addr_t) PhysAddr,
2183 FrameLength,
2184 PCI_DMA_FROMDEVICE);
2185 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2186 pRxd->VDataHigh, pRxd->VDataLow);
2187
2188 pMsg = pNewMsg;
2189
2190 }
2191 else {
2192 /*
2193 * if large frame, or SKB allocation failed, pass
2194 * the SKB directly to the networking
2195 */
2196
2197 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2198 PhysAddr |= (SK_U64) pRxd->VDataLow;
2199
2200 /* release the DMA mapping */
2201 pci_unmap_single(pAC->PciDev,
2202 PhysAddr,
2203 pAC->RxBufSize - 2,
2204 PCI_DMA_FROMDEVICE);
2205
2206 /* set length in message */
2207 skb_put(pMsg, FrameLength);
2208 /* hardware checksum */
2209 Type = ntohs(*((short*)&pMsg->data[12]));
2210
2211#ifdef USE_SK_RX_CHECKSUM
2212 if (Type == 0x800) {
2213 Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
2214 Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
2215 IpFrameLength = (int) ntohs((unsigned short)
2216 ((unsigned short *) pMsg->data)[8]);
2217
2218 /*
2219 * Test: If frame is padded, a check is not possible!
2220 * Frame not padded? Length difference must be 14 (0xe)!
2221 */
2222 if ((FrameLength - IpFrameLength) != 0xe) {
2223 /* Frame padded => TCP offload not possible! */
2224 pMsg->ip_summed = CHECKSUM_NONE;
2225 } else {
2226 /* Frame not padded => TCP offload! */
2227 if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
2228 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
2229 (pAC->ChipsetType)) {
2230 Result = SkCsGetReceiveInfo(pAC,
2231 &pMsg->data[14],
2232 Csum1, Csum2, pRxPort->PortIndex);
2233 if (Result ==
2234 SKCS_STATUS_IP_FRAGMENT ||
2235 Result ==
2236 SKCS_STATUS_IP_CSUM_OK ||
2237 Result ==
2238 SKCS_STATUS_TCP_CSUM_OK ||
2239 Result ==
2240 SKCS_STATUS_UDP_CSUM_OK) {
2241 pMsg->ip_summed =
2242 CHECKSUM_UNNECESSARY;
2243 }
2244 else if (Result ==
2245 SKCS_STATUS_TCP_CSUM_ERROR ||
2246 Result ==
2247 SKCS_STATUS_UDP_CSUM_ERROR ||
2248 Result ==
2249 SKCS_STATUS_IP_CSUM_ERROR_UDP ||
2250 Result ==
2251 SKCS_STATUS_IP_CSUM_ERROR_TCP ||
2252 Result ==
2253 SKCS_STATUS_IP_CSUM_ERROR ) {
2254 /* HW Checksum error */
2255 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2256 SK_DBGCAT_DRV_RX_PROGRESS,
2257 ("skge: CRC error. Frame dropped!\n"));
2258 goto rx_failed;
2259 } else {
2260 pMsg->ip_summed =
2261 CHECKSUM_NONE;
2262 }
2263 }/* checksumControl calculation valid */
2264 } /* Frame length check */
2265 } /* IP frame */
2266#else
2267 pMsg->ip_summed = CHECKSUM_NONE;
2268#endif
2269 } /* frame > SK_COPY_TRESHOLD */
2270
2271 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2272 ForRlmt = SK_RLMT_RX_PROTOCOL;
2273#if 0
2274 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2275#endif
2276 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2277 IsBc, &Offset, &NumBytes);
2278 if (NumBytes != 0) {
2279#if 0
2280 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2281#endif
2282 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2283 &pMsg->data[Offset],
2284 IsBc, IsMc, &ForRlmt);
2285 }
2286 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2287 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2288 /* send up only frames from active port */
2289 if ((PortIndex == pAC->ActivePort) ||
2290 (pAC->RlmtNets == 2)) {
2291 /* frame for upper layer */
2292 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2293#ifdef xDEBUG
2294 DumpMsg(pMsg, "Rx");
2295#endif
2296 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2297 FrameLength, pRxPort->PortIndex);
2298
2299 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2300 pMsg->protocol = eth_type_trans(pMsg,
2301 pAC->dev[pRxPort->PortIndex]);
2302 netif_rx(pMsg);
2303 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2304 }
2305 else {
2306 /* drop frame */
2307 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2308 SK_DBGCAT_DRV_RX_PROGRESS,
2309 ("D"));
2310 DEV_KFREE_SKB(pMsg);
2311 }
2312
2313 } /* if not for rlmt */
2314 else {
2315 /* packet for rlmt */
2316 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2317 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2318 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2319 pAC->IoBase, FrameLength);
2320 if (pRlmtMbuf != NULL) {
2321 pRlmtMbuf->pNext = NULL;
2322 pRlmtMbuf->Length = FrameLength;
2323 pRlmtMbuf->PortIdx = PortIndex;
2324 EvPara.pParaPtr = pRlmtMbuf;
2325 memcpy((char*)(pRlmtMbuf->pData),
2326 (char*)(pMsg->data),
2327 FrameLength);
2328
2329 /* SlowPathLock needed? */
2330 if (SlowPathLock == SK_TRUE) {
2331 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2332 SkEventQueue(pAC, SKGE_RLMT,
2333 SK_RLMT_PACKET_RECEIVED,
2334 EvPara);
2335 pAC->CheckQueue = SK_TRUE;
2336 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2337 } else {
2338 SkEventQueue(pAC, SKGE_RLMT,
2339 SK_RLMT_PACKET_RECEIVED,
2340 EvPara);
2341 pAC->CheckQueue = SK_TRUE;
2342 }
2343
2344 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2345 SK_DBGCAT_DRV_RX_PROGRESS,
2346 ("Q"));
2347 }
2348 if ((pAC->dev[pRxPort->PortIndex]->flags &
2349 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2350 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2351 SK_RLMT_RX_PROTOCOL) {
2352 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2353 pMsg->protocol = eth_type_trans(pMsg,
2354 pAC->dev[pRxPort->PortIndex]);
2355 netif_rx(pMsg);
2356 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2357 }
2358 else {
2359 DEV_KFREE_SKB(pMsg);
2360 }
2361
2362 } /* if packet for rlmt */
2363 } /* for ... scanning the RXD ring */
2364
2365 /* RXD ring is empty -> fill and restart */
2366 FillRxRing(pAC, pRxPort);
2367 /* do not start if called from Close */
2368 if (pAC->BoardLevel > SK_INIT_DATA) {
2369 ClearAndStartRx(pAC, PortIndex);
2370 }
2371 return;
2372
2373rx_failed:
2374 /* remove error frame */
2375 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2376 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2377
2378 /* release the DMA mapping */
2379
2380 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2381 PhysAddr |= (SK_U64) pRxd->VDataLow;
2382 pci_unmap_page(pAC->PciDev,
2383 PhysAddr,
2384 pAC->RxBufSize - 2,
2385 PCI_DMA_FROMDEVICE);
2386 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2387 pRxd->pMBuf = NULL;
2388 pRxPort->RxdRingFree++;
2389 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2390 goto rx_start;
2391
2392} /* ReceiveIrq */
2393
2394
2395/*****************************************************************************
2396 *
2397 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2398 *
2399 * Description:
2400 * This function sends a start command and a clear interrupt
2401 * command for one receive queue to the BMU.
2402 *
2403 * Returns: N/A
2404 * none
2405 */
2406static void ClearAndStartRx(
2407SK_AC *pAC, /* pointer to the adapter context */
2408int PortIndex) /* index of the receive port (XMAC) */
2409{
2410 SK_OUT8(pAC->IoBase,
2411 RxQueueAddr[PortIndex]+Q_CSR,
2412 CSR_START | CSR_IRQ_CL_F);
2413} /* ClearAndStartRx */
2414
2415
2416/*****************************************************************************
2417 *
2418 * ClearTxIrq - give a clear transmit IRQ command to BMU
2419 *
2420 * Description:
2421 * This function sends a clear tx IRQ command for one
2422 * transmit queue to the BMU.
2423 *
2424 * Returns: N/A
2425 */
2426static void ClearTxIrq(
2427SK_AC *pAC, /* pointer to the adapter context */
2428int PortIndex, /* index of the transmit port (XMAC) */
2429int Prio) /* priority or normal queue */
2430{
2431 SK_OUT8(pAC->IoBase,
2432 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2433 CSR_IRQ_CL_F);
2434} /* ClearTxIrq */
2435
2436
2437/*****************************************************************************
2438 *
2439 * ClearRxRing - remove all buffers from the receive ring
2440 *
2441 * Description:
2442 * This function removes all receive buffers from the ring.
2443 * The receive BMU must be stopped before calling this function.
2444 *
2445 * Returns: N/A
2446 */
2447static void ClearRxRing(
2448SK_AC *pAC, /* pointer to adapter context */
2449RX_PORT *pRxPort) /* pointer to rx port struct */
2450{
2451RXD *pRxd; /* pointer to the current descriptor */
2452unsigned long Flags;
2453SK_U64 PhysAddr;
2454
2455 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2456 return;
2457 }
2458 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2459 pRxd = pRxPort->pRxdRingHead;
2460 do {
2461 if (pRxd->pMBuf != NULL) {
2462
2463 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2464 PhysAddr |= (SK_U64) pRxd->VDataLow;
2465 pci_unmap_page(pAC->PciDev,
2466 PhysAddr,
2467 pAC->RxBufSize - 2,
2468 PCI_DMA_FROMDEVICE);
2469 DEV_KFREE_SKB(pRxd->pMBuf);
2470 pRxd->pMBuf = NULL;
2471 }
2472 pRxd->RBControl &= BMU_OWN;
2473 pRxd = pRxd->pNextRxd;
2474 pRxPort->RxdRingFree++;
2475 } while (pRxd != pRxPort->pRxdRingTail);
2476 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2477 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2478} /* ClearRxRing */
2479
2480/*****************************************************************************
2481 *
2482 * ClearTxRing - remove all buffers from the transmit ring
2483 *
2484 * Description:
2485 * This function removes all transmit buffers from the ring.
2486 * The transmit BMU must be stopped before calling this function
2487 * and transmitting at the upper level must be disabled.
2488 * The BMU own bit of all descriptors is cleared, the rest is
2489 * done by calling FreeTxDescriptors.
2490 *
2491 * Returns: N/A
2492 */
2493static void ClearTxRing(
2494SK_AC *pAC, /* pointer to adapter context */
2495TX_PORT *pTxPort) /* pointer to tx prt struct */
2496{
2497TXD *pTxd; /* pointer to the current descriptor */
2498int i;
2499unsigned long Flags;
2500
2501 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2502 pTxd = pTxPort->pTxdRingHead;
2503 for (i=0; i<pAC->TxDescrPerRing; i++) {
2504 pTxd->TBControl &= ~BMU_OWN;
2505 pTxd = pTxd->pNextTxd;
2506 }
2507 FreeTxDescriptors(pAC, pTxPort);
2508 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2509} /* ClearTxRing */
2510
2511/*****************************************************************************
2512 *
2513 * SkGeSetMacAddr - Set the hardware MAC address
2514 *
2515 * Description:
2516 * This function sets the MAC address used by the adapter.
2517 *
2518 * Returns:
2519 * 0, if everything is ok
2520 * !=0, on error
2521 */
2522static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2523{
2524
2525DEV_NET *pNet = netdev_priv(dev);
2526SK_AC *pAC = pNet->pAC;
2527
2528struct sockaddr *addr = p;
2529unsigned long Flags;
2530
2531 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2532 ("SkGeSetMacAddr starts now...\n"));
2533 if(netif_running(dev))
2534 return -EBUSY;
2535
2536 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2537
2538 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2539
2540 if (pAC->RlmtNets == 2)
2541 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2542 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2543 else
2544 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2545 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2546
2547
2548
2549 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2550 return 0;
2551} /* SkGeSetMacAddr */
2552
2553
2554/*****************************************************************************
2555 *
2556 * SkGeSetRxMode - set receive mode
2557 *
2558 * Description:
2559 * This function sets the receive mode of an adapter. The adapter
2560 * supports promiscuous mode, allmulticast mode and a number of
2561 * multicast addresses. If more multicast addresses the available
2562 * are selected, a hash function in the hardware is used.
2563 *
2564 * Returns:
2565 * 0, if everything is ok
2566 * !=0, on error
2567 */
2568static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2569{
2570
2571DEV_NET *pNet;
2572SK_AC *pAC;
2573
2574struct dev_mc_list *pMcList;
2575int i;
2576int PortIdx;
2577unsigned long Flags;
2578
2579 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2580 ("SkGeSetRxMode starts now... "));
2581
2582 pNet = netdev_priv(dev);
2583 pAC = pNet->pAC;
2584 if (pAC->RlmtNets == 1)
2585 PortIdx = pAC->ActivePort;
2586 else
2587 PortIdx = pNet->NetNr;
2588
2589 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2590 if (dev->flags & IFF_PROMISC) {
2591 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2592 ("PROMISCUOUS mode\n"));
2593 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2594 SK_PROM_MODE_LLC);
2595 } else if (dev->flags & IFF_ALLMULTI) {
2596 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2597 ("ALLMULTI mode\n"));
2598 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2599 SK_PROM_MODE_ALL_MC);
2600 } else {
2601 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2602 SK_PROM_MODE_NONE);
2603 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2604
2605 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2606 ("Number of MC entries: %d ", dev->mc_count));
2607
2608 pMcList = dev->mc_list;
2609 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2610 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2611 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2612 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2613 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2614 pMcList->dmi_addr[0],
2615 pMcList->dmi_addr[1],
2616 pMcList->dmi_addr[2],
2617 pMcList->dmi_addr[3],
2618 pMcList->dmi_addr[4],
2619 pMcList->dmi_addr[5]));
2620 }
2621 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2622 }
2623 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2624
2625 return;
2626} /* SkGeSetRxMode */
2627
2628
2629/*****************************************************************************
2630 *
2631 * SkGeChangeMtu - set the MTU to another value
2632 *
2633 * Description:
2634 * This function sets is called whenever the MTU size is changed
2635 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2636 * ethernet MTU size, long frame support is activated.
2637 *
2638 * Returns:
2639 * 0, if everything is ok
2640 * !=0, on error
2641 */
2642static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2643{
2644DEV_NET *pNet;
2645DEV_NET *pOtherNet;
2646SK_AC *pAC;
2647unsigned long Flags;
2648int i;
2649SK_EVPARA EvPara;
2650
2651 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2652 ("SkGeChangeMtu starts now...\n"));
2653
2654 pNet = netdev_priv(dev);
2655 pAC = pNet->pAC;
2656
2657 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2658 return -EINVAL;
2659 }
2660
2661 if(pAC->BoardLevel != SK_INIT_RUN) {
2662 return -EINVAL;
2663 }
2664
2665#ifdef SK_DIAG_SUPPORT
2666 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2667 if (pAC->DiagFlowCtrl == SK_FALSE) {
2668 return -1; /* still in use, deny any actions of MTU */
2669 } else {
2670 pAC->DiagFlowCtrl = SK_FALSE;
2671 }
2672 }
2673#endif
2674
2675 pNet->Mtu = NewMtu;
2676 pOtherNet = netdev_priv(pAC->dev[1 - pNet->NetNr]);
2677 if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
2678 return(0);
2679 }
2680
2681 pAC->RxBufSize = NewMtu + 32;
2682 dev->mtu = NewMtu;
2683
2684 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2685 ("New MTU: %d\n", NewMtu));
2686
2687 /*
2688 ** Prevent any reconfiguration while changing the MTU
2689 ** by disabling any interrupts
2690 */
2691 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2692 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2693
2694 /*
2695 ** Notify RLMT that any ports are to be stopped
2696 */
2697 EvPara.Para32[0] = 0;
2698 EvPara.Para32[1] = -1;
2699 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2700 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2701 EvPara.Para32[0] = 1;
2702 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2703 } else {
2704 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2705 }
2706
2707 /*
2708 ** After calling the SkEventDispatcher(), RLMT is aware about
2709 ** the stopped ports -> configuration can take place!
2710 */
2711 SkEventDispatcher(pAC, pAC->IoBase);
2712
2713 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2714 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2715 netif_stop_queue(pAC->dev[i]);
2716
2717 }
2718
2719 /*
2720 ** Depending on the desired MTU size change, a different number of
2721 ** RX buffers need to be allocated
2722 */
2723 if (NewMtu > 1500) {
2724 /*
2725 ** Use less rx buffers
2726 */
2727 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2728 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2729 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2730 (pAC->RxDescrPerRing / 4);
2731 } else {
2732 if (i == pAC->ActivePort) {
2733 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2734 (pAC->RxDescrPerRing / 4);
2735 } else {
2736 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2737 (pAC->RxDescrPerRing / 10);
2738 }
2739 }
2740 }
2741 } else {
2742 /*
2743 ** Use the normal amount of rx buffers
2744 */
2745 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2746 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2747 pAC->RxPort[i].RxFillLimit = 1;
2748 } else {
2749 if (i == pAC->ActivePort) {
2750 pAC->RxPort[i].RxFillLimit = 1;
2751 } else {
2752 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2753 (pAC->RxDescrPerRing / 4);
2754 }
2755 }
2756 }
2757 }
2758
2759 SkGeDeInit(pAC, pAC->IoBase);
2760
2761 /*
2762 ** enable/disable hardware support for long frames
2763 */
2764 if (NewMtu > 1500) {
2765// pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2766 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2767 } else {
2768 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2769 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2770 } else {
2771 pAC->GIni.GIPortUsage = SK_RED_LINK;
2772 }
2773 }
2774
2775 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2776 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2777 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2778 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2779 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2780 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2781 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2782
2783 /*
2784 ** tschilling:
2785 ** Speed and others are set back to default in level 1 init!
2786 */
2787 GetConfiguration(pAC);
2788
2789 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2790 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2791 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2792 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2793 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2794 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2795 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2796
2797 /*
2798 ** clear and reinit the rx rings here
2799 */
2800 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2801 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2802 ClearRxRing(pAC, &pAC->RxPort[i]);
2803 FillRxRing(pAC, &pAC->RxPort[i]);
2804
2805 /*
2806 ** Enable transmit descriptor polling
2807 */
2808 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2809 FillRxRing(pAC, &pAC->RxPort[i]);
2810 };
2811
2812 SkGeYellowLED(pAC, pAC->IoBase, 1);
2813 SkDimEnableModerationIfNeeded(pAC);
2814 SkDimDisplayModerationSettings(pAC);
2815
2816 netif_start_queue(pAC->dev[pNet->PortNr]);
2817 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2818 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2819 }
2820
2821 /*
2822 ** Enable Interrupts again
2823 */
2824 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2825 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2826
2827 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2828 SkEventDispatcher(pAC, pAC->IoBase);
2829
2830 /*
2831 ** Notify RLMT about the changing and restarting one (or more) ports
2832 */
2833 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2834 EvPara.Para32[0] = pAC->RlmtNets;
2835 EvPara.Para32[1] = -1;
2836 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2837 EvPara.Para32[0] = pNet->PortNr;
2838 EvPara.Para32[1] = -1;
2839 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2840
2841 if (pOtherNet->Up) {
2842 EvPara.Para32[0] = pOtherNet->PortNr;
2843 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2844 }
2845 } else {
2846 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2847 }
2848
2849 SkEventDispatcher(pAC, pAC->IoBase);
2850 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2851
2852 /*
2853 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2854 ** seems as if upper layers have a problem to handle a successful
2855 ** return value of '0'. If such a zero is returned, the complete
2856 ** system hangs for several minutes (!), which is in acceptable.
2857 **
2858 ** Currently it is not clear, what the exact reason for this problem
2859 ** is. The implemented workaround for 2.5 is to return the desired
2860 ** new MTU size if all needed changes for the new MTU size where
2861 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2862 ** which indicates the successful change of the mtu-size.
2863 */
2864 return NewMtu;
2865
2866} /* SkGeChangeMtu */
2867
2868
2869/*****************************************************************************
2870 *
2871 * SkGeStats - return ethernet device statistics
2872 *
2873 * Description:
2874 * This function return statistic data about the ethernet device
2875 * to the operating system.
2876 *
2877 * Returns:
2878 * pointer to the statistic structure.
2879 */
2880static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2881{
2882DEV_NET *pNet = netdev_priv(dev);
2883SK_AC *pAC = pNet->pAC;
2884SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2885SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2886SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2887unsigned int Size; /* size of pnmi struct */
2888unsigned long Flags; /* for spin lock */
2889
2890 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2891 ("SkGeStats starts now...\n"));
2892 pPnmiStruct = &pAC->PnmiStruct;
2893
2894#ifdef SK_DIAG_SUPPORT
2895 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2896 (pAC->BoardLevel == SK_INIT_RUN)) {
2897#endif
2898 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2899 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2900 Size = SK_PNMI_STRUCT_SIZE;
2901 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2902 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2903#ifdef SK_DIAG_SUPPORT
2904 }
2905#endif
2906
2907 pPnmiStat = &pPnmiStruct->Stat[0];
2908 pPnmiConf = &pPnmiStruct->Conf[0];
2909
2910 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2911 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2912 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2913 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2914
2915 if (pNet->Mtu <= 1500) {
2916 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2917 } else {
2918 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2919 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2920 }
2921
2922
2923 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2924 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2925
2926 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2927 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2928 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2929 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2930 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2931
2932 /* detailed rx_errors: */
2933 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2934 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2935 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2936 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2937 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2938 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2939
2940 /* detailed tx_errors */
2941 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2942 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2943 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2944 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2945 pAC->stats.tx_window_errors = (SK_U32) 0;
2946
2947 return(&pAC->stats);
2948} /* SkGeStats */
2949
2950
2951/*****************************************************************************
2952 *
2953 * SkGeIoctl - IO-control function
2954 *
2955 * Description:
2956 * This function is called if an ioctl is issued on the device.
2957 * There are three subfunction for reading, writing and test-writing
2958 * the private MIB data structure (usefull for SysKonnect-internal tools).
2959 *
2960 * Returns:
2961 * 0, if everything is ok
2962 * !=0, on error
2963 */
2964static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2965{
2966DEV_NET *pNet;
2967SK_AC *pAC;
2968void *pMemBuf;
2969struct pci_dev *pdev = NULL;
2970SK_GE_IOCTL Ioctl;
2971unsigned int Err = 0;
2972int Size = 0;
2973int Ret = 0;
2974unsigned int Length = 0;
2975int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2976
2977 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2978 ("SkGeIoctl starts now...\n"));
2979
2980 pNet = netdev_priv(dev);
2981 pAC = pNet->pAC;
2982
2983 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2984 return -EFAULT;
2985 }
2986
2987 switch(cmd) {
2988 case SK_IOCTL_SETMIB:
2989 case SK_IOCTL_PRESETMIB:
2990 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2991 case SK_IOCTL_GETMIB:
2992 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2993 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2994 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2995 return -EFAULT;
2996 }
2997 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2998 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2999 Ioctl.Len<Size? Ioctl.Len : Size)) {
3000 return -EFAULT;
3001 }
3002 Ioctl.Len = Size;
3003 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3004 return -EFAULT;
3005 }
3006 break;
3007 case SK_IOCTL_GEN:
3008 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3009 Length = Ioctl.Len;
3010 } else {
3011 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3012 }
3013 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3014 return -ENOMEM;
3015 }
3016 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3017 Err = -EFAULT;
3018 goto fault_gen;
3019 }
3020 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
3021 Err = -EFAULT;
3022 goto fault_gen;
3023 }
3024 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3025 Err = -EFAULT;
3026 goto fault_gen;
3027 }
3028 Ioctl.Len = Length;
3029 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3030 Err = -EFAULT;
3031 goto fault_gen;
3032 }
3033fault_gen:
3034 kfree(pMemBuf); /* cleanup everything */
3035 break;
3036#ifdef SK_DIAG_SUPPORT
3037 case SK_IOCTL_DIAG:
3038 if (!capable(CAP_NET_ADMIN)) return -EPERM;
3039 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3040 Length = Ioctl.Len;
3041 } else {
3042 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3043 }
3044 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3045 return -ENOMEM;
3046 }
3047 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3048 Err = -EFAULT;
3049 goto fault_diag;
3050 }
3051 pdev = pAC->PciDev;
3052 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
3053 /*
3054 ** While coding this new IOCTL interface, only a few lines of code
3055 ** are to to be added. Therefore no dedicated function has been
3056 ** added. If more functionality is added, a separate function
3057 ** should be used...
3058 */
3059 * ((SK_U32 *)pMemBuf) = 0;
3060 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
3061 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
3062 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3063 Err = -EFAULT;
3064 goto fault_diag;
3065 }
3066 Ioctl.Len = Length;
3067 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3068 Err = -EFAULT;
3069 goto fault_diag;
3070 }
3071fault_diag:
3072 kfree(pMemBuf); /* cleanup everything */
3073 break;
3074#endif
3075 default:
3076 Err = -EOPNOTSUPP;
3077 }
3078
3079 return(Err);
3080
3081} /* SkGeIoctl */
3082
3083
3084/*****************************************************************************
3085 *
3086 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3087 *
3088 * Description:
3089 * This function reads/writes the MIB data using PNMI (Private Network
3090 * Management Interface).
3091 * The destination for the data must be provided with the
3092 * ioctl call and is given to the driver in the form of
3093 * a user space address.
3094 * Copying from the user-provided data area into kernel messages
3095 * and back is done by copy_from_user and copy_to_user calls in
3096 * SkGeIoctl.
3097 *
3098 * Returns:
3099 * returned size from PNMI call
3100 */
3101static int SkGeIocMib(
3102DEV_NET *pNet, /* pointer to the adapter context */
3103unsigned int Size, /* length of ioctl data */
3104int mode) /* flag for set/preset */
3105{
3106unsigned long Flags; /* for spin lock */
3107SK_AC *pAC;
3108
3109 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3110 ("SkGeIocMib starts now...\n"));
3111 pAC = pNet->pAC;
3112 /* access MIB */
3113 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3114 switch(mode) {
3115 case SK_IOCTL_GETMIB:
3116 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3117 pNet->NetNr);
3118 break;
3119 case SK_IOCTL_PRESETMIB:
3120 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3121 pNet->NetNr);
3122 break;
3123 case SK_IOCTL_SETMIB:
3124 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3125 pNet->NetNr);
3126 break;
3127 default:
3128 break;
3129 }
3130 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3131 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3132 ("MIB data access succeeded\n"));
3133 return (Size);
3134} /* SkGeIocMib */
3135
3136
3137/*****************************************************************************
3138 *
3139 * GetConfiguration - read configuration information
3140 *
3141 * Description:
3142 * This function reads per-adapter configuration information from
3143 * the options provided on the command line.
3144 *
3145 * Returns:
3146 * none
3147 */
3148static void GetConfiguration(
3149SK_AC *pAC) /* pointer to the adapter context structure */
3150{
3151SK_I32 Port; /* preferred port */
3152SK_BOOL AutoSet;
3153SK_BOOL DupSet;
3154int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3155int AutoNeg = 1; /* autoneg off (0) or on (1) */
3156int DuplexCap = 0; /* 0=both,1=full,2=half */
3157int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3158int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3159
3160SK_BOOL IsConTypeDefined = SK_TRUE;
3161SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3162SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3163SK_BOOL IsRoleDefined = SK_TRUE;
3164SK_BOOL IsModeDefined = SK_TRUE;
3165/*
3166 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3167 * parameter. The mapping is described by this table:
3168 * DuplexCap -> | both | full | half |
3169 * AutoNeg | | | |
3170 * -----------------------------------------------------------------
3171 * Off | illegal | Full | Half |
3172 * -----------------------------------------------------------------
3173 * On | AutoBoth | AutoFull | AutoHalf |
3174 * -----------------------------------------------------------------
3175 * Sense | AutoSense | AutoSense | AutoSense |
3176 */
3177int Capabilities[3][3] =
3178 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3179 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3180 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3181
3182#define DC_BOTH 0
3183#define DC_FULL 1
3184#define DC_HALF 2
3185#define AN_OFF 0
3186#define AN_ON 1
3187#define AN_SENS 2
3188#define M_CurrPort pAC->GIni.GP[Port]
3189
3190
3191 /*
3192 ** Set the default values first for both ports!
3193 */
3194 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3195 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3196 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3197 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3198 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3199 }
3200
3201 /*
3202 ** Check merged parameter ConType. If it has not been used,
3203 ** verify any other parameter (e.g. AutoNeg) and use default values.
3204 **
3205 ** Stating both ConType and other lowlevel link parameters is also
3206 ** possible. If this is the case, the passed ConType-parameter is
3207 ** overwritten by the lowlevel link parameter.
3208 **
3209 ** The following settings are used for a merged ConType-parameter:
3210 **
3211 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3212 ** ------- ------ ------- -------- ---------- -----
3213 ** Auto Both On SymOrRem Auto Auto
3214 ** 100FD Full Off None <ignored> 100
3215 ** 100HD Half Off None <ignored> 100
3216 ** 10FD Full Off None <ignored> 10
3217 ** 10HD Half Off None <ignored> 10
3218 **
3219 ** This ConType parameter is used for all ports of the adapter!
3220 */
3221 if ( (ConType != NULL) &&
3222 (pAC->Index < SK_MAX_CARD_PARAM) &&
3223 (ConType[pAC->Index] != NULL) ) {
3224
3225 /* Check chipset family */
3226 if ((!pAC->ChipsetType) &&
3227 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3228 (strcmp(ConType[pAC->Index],"")!=0)) {
3229 /* Set the speed parameter back */
3230 printk("sk98lin: Illegal value \"%s\" "
3231 "for ConType."
3232 " Using Auto.\n",
3233 ConType[pAC->Index]);
3234
3235 sprintf(ConType[pAC->Index], "Auto");
3236 }
3237
3238 if (strcmp(ConType[pAC->Index],"")==0) {
3239 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3240 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3241 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3242 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3243 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3244 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3245 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3246 }
3247 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3248 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3249 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3250 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3251 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3252 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3253 }
3254 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3255 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3256 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3257 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3258 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3259 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3260 }
3261 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3262 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3263 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3264 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3265 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3266 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3267 }
3268 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3269 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3270 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3271 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3272 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3273 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3274 }
3275 } else {
3276 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3277 ConType[pAC->Index]);
3278 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3279 }
3280 } else {
3281 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3282 }
3283
3284 /*
3285 ** Parse any parameter settings for port A:
3286 ** a) any LinkSpeed stated?
3287 */
3288 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3289 Speed_A[pAC->Index] != NULL) {
3290 if (strcmp(Speed_A[pAC->Index],"")==0) {
3291 IsLinkSpeedDefined = SK_FALSE;
3292 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3293 LinkSpeed = SK_LSPEED_AUTO;
3294 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3295 LinkSpeed = SK_LSPEED_10MBPS;
3296 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3297 LinkSpeed = SK_LSPEED_100MBPS;
3298 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3299 LinkSpeed = SK_LSPEED_1000MBPS;
3300 } else {
3301 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3302 Speed_A[pAC->Index]);
3303 IsLinkSpeedDefined = SK_FALSE;
3304 }
3305 } else {
3306 IsLinkSpeedDefined = SK_FALSE;
3307 }
3308
3309 /*
3310 ** Check speed parameter:
3311 ** Only copper type adapter and GE V2 cards
3312 */
3313 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3314 ((LinkSpeed != SK_LSPEED_AUTO) &&
3315 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3316 printk("sk98lin: Illegal value for Speed_A. "
3317 "Not a copper card or GE V2 card\n Using "
3318 "speed 1000\n");
3319 LinkSpeed = SK_LSPEED_1000MBPS;
3320 }
3321
3322 /*
3323 ** Decide whether to set new config value if somethig valid has
3324 ** been received.
3325 */
3326 if (IsLinkSpeedDefined) {
3327 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3328 }
3329
3330 /*
3331 ** b) Any Autonegotiation and DuplexCapabilities set?
3332 ** Please note that both belong together...
3333 */
3334 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3335 AutoSet = SK_FALSE;
3336 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3337 AutoNeg_A[pAC->Index] != NULL) {
3338 AutoSet = SK_TRUE;
3339 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3340 AutoSet = SK_FALSE;
3341 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3342 AutoNeg = AN_ON;
3343 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3344 AutoNeg = AN_OFF;
3345 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3346 AutoNeg = AN_SENS;
3347 } else {
3348 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3349 AutoNeg_A[pAC->Index]);
3350 }
3351 }
3352
3353 DuplexCap = DC_BOTH;
3354 DupSet = SK_FALSE;
3355 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3356 DupCap_A[pAC->Index] != NULL) {
3357 DupSet = SK_TRUE;
3358 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3359 DupSet = SK_FALSE;
3360 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3361 DuplexCap = DC_BOTH;
3362 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3363 DuplexCap = DC_FULL;
3364 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3365 DuplexCap = DC_HALF;
3366 } else {
3367 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3368 DupCap_A[pAC->Index]);
3369 }
3370 }
3371
3372 /*
3373 ** Check for illegal combinations
3374 */
3375 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3376 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3377 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3378 (pAC->ChipsetType)) {
3379 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3380 " Using Full Duplex.\n");
3381 DuplexCap = DC_FULL;
3382 }
3383
3384 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3385 printk("sk98lin, Port A: DuplexCapabilities"
3386 " ignored using Sense mode\n");
3387 }
3388
3389 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3390 printk("sk98lin: Port A: Illegal combination"
3391 " of values AutoNeg. and DuplexCap.\n Using "
3392 "Full Duplex\n");
3393 DuplexCap = DC_FULL;
3394 }
3395
3396 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3397 DuplexCap = DC_FULL;
3398 }
3399
3400 if (!AutoSet && DupSet) {
3401 printk("sk98lin: Port A: Duplex setting not"
3402 " possible in\n default AutoNegotiation mode"
3403 " (Sense).\n Using AutoNegotiation On\n");
3404 AutoNeg = AN_ON;
3405 }
3406
3407 /*
3408 ** set the desired mode
3409 */
3410 if (AutoSet || DupSet) {
3411 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3412 }
3413
3414 /*
3415 ** c) Any Flowcontrol-parameter set?
3416 */
3417 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3418 FlowCtrl_A[pAC->Index] != NULL) {
3419 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3420 IsFlowCtrlDefined = SK_FALSE;
3421 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3422 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3423 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3424 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3425 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3426 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3427 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3428 FlowCtrl = SK_FLOW_MODE_NONE;
3429 } else {
3430 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3431 FlowCtrl_A[pAC->Index]);
3432 IsFlowCtrlDefined = SK_FALSE;
3433 }
3434 } else {
3435 IsFlowCtrlDefined = SK_FALSE;
3436 }
3437
3438 if (IsFlowCtrlDefined) {
3439 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3440 printk("sk98lin: Port A: FlowControl"
3441 " impossible without AutoNegotiation,"
3442 " disabled\n");
3443 FlowCtrl = SK_FLOW_MODE_NONE;
3444 }
3445 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3446 }
3447
3448 /*
3449 ** d) What is with the RoleParameter?
3450 */
3451 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3452 Role_A[pAC->Index] != NULL) {
3453 if (strcmp(Role_A[pAC->Index],"")==0) {
3454 IsRoleDefined = SK_FALSE;
3455 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3456 MSMode = SK_MS_MODE_AUTO;
3457 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3458 MSMode = SK_MS_MODE_MASTER;
3459 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3460 MSMode = SK_MS_MODE_SLAVE;
3461 } else {
3462 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3463 Role_A[pAC->Index]);
3464 IsRoleDefined = SK_FALSE;
3465 }
3466 } else {
3467 IsRoleDefined = SK_FALSE;
3468 }
3469
3470 if (IsRoleDefined == SK_TRUE) {
3471 pAC->GIni.GP[0].PMSMode = MSMode;
3472 }
3473
3474
3475
3476 /*
3477 ** Parse any parameter settings for port B:
3478 ** a) any LinkSpeed stated?
3479 */
3480 IsConTypeDefined = SK_TRUE;
3481 IsLinkSpeedDefined = SK_TRUE;
3482 IsFlowCtrlDefined = SK_TRUE;
3483 IsModeDefined = SK_TRUE;
3484
3485 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3486 Speed_B[pAC->Index] != NULL) {
3487 if (strcmp(Speed_B[pAC->Index],"")==0) {
3488 IsLinkSpeedDefined = SK_FALSE;
3489 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3490 LinkSpeed = SK_LSPEED_AUTO;
3491 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3492 LinkSpeed = SK_LSPEED_10MBPS;
3493 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3494 LinkSpeed = SK_LSPEED_100MBPS;
3495 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3496 LinkSpeed = SK_LSPEED_1000MBPS;
3497 } else {
3498 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3499 Speed_B[pAC->Index]);
3500 IsLinkSpeedDefined = SK_FALSE;
3501 }
3502 } else {
3503 IsLinkSpeedDefined = SK_FALSE;
3504 }
3505
3506 /*
3507 ** Check speed parameter:
3508 ** Only copper type adapter and GE V2 cards
3509 */
3510 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3511 ((LinkSpeed != SK_LSPEED_AUTO) &&
3512 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3513 printk("sk98lin: Illegal value for Speed_B. "
3514 "Not a copper card or GE V2 card\n Using "
3515 "speed 1000\n");
3516 LinkSpeed = SK_LSPEED_1000MBPS;
3517 }
3518
3519 /*
3520 ** Decide whether to set new config value if somethig valid has
3521 ** been received.
3522 */
3523 if (IsLinkSpeedDefined) {
3524 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3525 }
3526
3527 /*
3528 ** b) Any Autonegotiation and DuplexCapabilities set?
3529 ** Please note that both belong together...
3530 */
3531 AutoNeg = AN_SENS; /* default: do auto Sense */
3532 AutoSet = SK_FALSE;
3533 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3534 AutoNeg_B[pAC->Index] != NULL) {
3535 AutoSet = SK_TRUE;
3536 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3537 AutoSet = SK_FALSE;
3538 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3539 AutoNeg = AN_ON;
3540 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3541 AutoNeg = AN_OFF;
3542 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3543 AutoNeg = AN_SENS;
3544 } else {
3545 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3546 AutoNeg_B[pAC->Index]);
3547 }
3548 }
3549
3550 DuplexCap = DC_BOTH;
3551 DupSet = SK_FALSE;
3552 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3553 DupCap_B[pAC->Index] != NULL) {
3554 DupSet = SK_TRUE;
3555 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3556 DupSet = SK_FALSE;
3557 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3558 DuplexCap = DC_BOTH;
3559 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3560 DuplexCap = DC_FULL;
3561 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3562 DuplexCap = DC_HALF;
3563 } else {
3564 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3565 DupCap_B[pAC->Index]);
3566 }
3567 }
3568
3569
3570 /*
3571 ** Check for illegal combinations
3572 */
3573 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3574 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3575 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3576 (pAC->ChipsetType)) {
3577 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3578 " Using Full Duplex.\n");
3579 DuplexCap = DC_FULL;
3580 }
3581
3582 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3583 printk("sk98lin, Port B: DuplexCapabilities"
3584 " ignored using Sense mode\n");
3585 }
3586
3587 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3588 printk("sk98lin: Port B: Illegal combination"
3589 " of values AutoNeg. and DuplexCap.\n Using "
3590 "Full Duplex\n");
3591 DuplexCap = DC_FULL;
3592 }
3593
3594 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3595 DuplexCap = DC_FULL;
3596 }
3597
3598 if (!AutoSet && DupSet) {
3599 printk("sk98lin: Port B: Duplex setting not"
3600 " possible in\n default AutoNegotiation mode"
3601 " (Sense).\n Using AutoNegotiation On\n");
3602 AutoNeg = AN_ON;
3603 }
3604
3605 /*
3606 ** set the desired mode
3607 */
3608 if (AutoSet || DupSet) {
3609 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3610 }
3611
3612 /*
3613 ** c) Any FlowCtrl parameter set?
3614 */
3615 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3616 FlowCtrl_B[pAC->Index] != NULL) {
3617 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3618 IsFlowCtrlDefined = SK_FALSE;
3619 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3620 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3621 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3622 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3623 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3624 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3625 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3626 FlowCtrl = SK_FLOW_MODE_NONE;
3627 } else {
3628 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3629 FlowCtrl_B[pAC->Index]);
3630 IsFlowCtrlDefined = SK_FALSE;
3631 }
3632 } else {
3633 IsFlowCtrlDefined = SK_FALSE;
3634 }
3635
3636 if (IsFlowCtrlDefined) {
3637 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3638 printk("sk98lin: Port B: FlowControl"
3639 " impossible without AutoNegotiation,"
3640 " disabled\n");
3641 FlowCtrl = SK_FLOW_MODE_NONE;
3642 }
3643 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3644 }
3645
3646 /*
3647 ** d) What is the RoleParameter?
3648 */
3649 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3650 Role_B[pAC->Index] != NULL) {
3651 if (strcmp(Role_B[pAC->Index],"")==0) {
3652 IsRoleDefined = SK_FALSE;
3653 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3654 MSMode = SK_MS_MODE_AUTO;
3655 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3656 MSMode = SK_MS_MODE_MASTER;
3657 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3658 MSMode = SK_MS_MODE_SLAVE;
3659 } else {
3660 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3661 Role_B[pAC->Index]);
3662 IsRoleDefined = SK_FALSE;
3663 }
3664 } else {
3665 IsRoleDefined = SK_FALSE;
3666 }
3667
3668 if (IsRoleDefined) {
3669 pAC->GIni.GP[1].PMSMode = MSMode;
3670 }
3671
3672 /*
3673 ** Evaluate settings for both ports
3674 */
3675 pAC->ActivePort = 0;
3676 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3677 PrefPort[pAC->Index] != NULL) {
3678 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3679 pAC->ActivePort = 0;
3680 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3681 pAC->Rlmt.Net[0].PrefPort = 0;
3682 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3683 /*
3684 ** do not set ActivePort here, thus a port
3685 ** switch is issued after net up.
3686 */
3687 Port = 0;
3688 pAC->Rlmt.Net[0].Preference = Port;
3689 pAC->Rlmt.Net[0].PrefPort = Port;
3690 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3691 /*
3692 ** do not set ActivePort here, thus a port
3693 ** switch is issued after net up.
3694 */
3695 if (pAC->GIni.GIMacsFound == 1) {
3696 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3697 " Port B not available on single port adapters.\n");
3698
3699 pAC->ActivePort = 0;
3700 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3701 pAC->Rlmt.Net[0].PrefPort = 0;
3702 } else {
3703 Port = 1;
3704 pAC->Rlmt.Net[0].Preference = Port;
3705 pAC->Rlmt.Net[0].PrefPort = Port;
3706 }
3707 } else {
3708 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3709 PrefPort[pAC->Index]);
3710 }
3711 }
3712
3713 pAC->RlmtNets = 1;
3714
3715 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3716 RlmtMode[pAC->Index] != NULL) {
3717 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3718 pAC->RlmtMode = 0;
3719 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3720 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3721 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3722 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3723 SK_RLMT_CHECK_LOC_LINK;
3724 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3725 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3726 SK_RLMT_CHECK_LOC_LINK |
3727 SK_RLMT_CHECK_SEG;
3728 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3729 (pAC->GIni.GIMacsFound == 2)) {
3730 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3731 pAC->RlmtNets = 2;
3732 } else {
3733 printk("sk98lin: Illegal value \"%s\" for"
3734 " RlmtMode, using default\n",
3735 RlmtMode[pAC->Index]);
3736 pAC->RlmtMode = 0;
3737 }
3738 } else {
3739 pAC->RlmtMode = 0;
3740 }
3741
3742 /*
3743 ** Check the interrupt moderation parameters
3744 */
3745 if (Moderation[pAC->Index] != NULL) {
3746 if (strcmp(Moderation[pAC->Index], "") == 0) {
3747 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3748 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3749 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3750 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3751 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3752 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3753 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3754 } else {
3755 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3756 " Disable interrupt moderation.\n",
3757 Moderation[pAC->Index]);
3758 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3759 }
3760 } else {
3761 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3762 }
3763
3764 if (Stats[pAC->Index] != NULL) {
3765 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3766 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3767 } else {
3768 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3769 }
3770 } else {
3771 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3772 }
3773
3774 if (ModerationMask[pAC->Index] != NULL) {
3775 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3776 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3777 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3778 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3779 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3780 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3781 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3782 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3783 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3784 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3785 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3786 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3787 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3788 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3789 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3790 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3791 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3792 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3793 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3794 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3795 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3796 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3797 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3798 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3799 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3800 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3801 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3802 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3803 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3804 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3805 } else { /* some rubbish */
3806 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3807 }
3808 } else { /* operator has stated nothing */
3809 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3810 }
3811
3812 if (AutoSizing[pAC->Index] != NULL) {
3813 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3814 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3815 } else {
3816 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3817 }
3818 } else { /* operator has stated nothing */
3819 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3820 }
3821
3822 if (IntsPerSec[pAC->Index] != 0) {
3823 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3824 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3825 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3826 " Using default value of %i.\n",
3827 IntsPerSec[pAC->Index],
3828 C_INT_MOD_IPS_LOWER_RANGE,
3829 C_INT_MOD_IPS_UPPER_RANGE,
3830 C_INTS_PER_SEC_DEFAULT);
3831 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3832 } else {
3833 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3834 }
3835 } else {
3836 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3837 }
3838
3839 /*
3840 ** Evaluate upper and lower moderation threshold
3841 */
3842 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3843 pAC->DynIrqModInfo.MaxModIntsPerSec +
3844 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3845
3846 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3847 pAC->DynIrqModInfo.MaxModIntsPerSec -
3848 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3849
3850 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3851
3852
3853} /* GetConfiguration */
3854
3855
3856/*****************************************************************************
3857 *
3858 * ProductStr - return a adapter identification string from vpd
3859 *
3860 * Description:
3861 * This function reads the product name string from the vpd area
3862 * and puts it the field pAC->DeviceString.
3863 *
3864 * Returns: N/A
3865 */
3866static void ProductStr(
3867SK_AC *pAC /* pointer to adapter context */
3868)
3869{
3870int StrLen = 80; /* length of the string, defined in SK_AC */
3871char Keyword[] = VPD_NAME; /* vpd productname identifier */
3872int ReturnCode; /* return code from vpd_read */
3873unsigned long Flags;
3874
3875 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3876 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3877 &StrLen);
3878 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3879 if (ReturnCode != 0) {
3880 /* there was an error reading the vpd data */
3881 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3882 ("Error reading VPD data: %d\n", ReturnCode));
3883 pAC->DeviceStr[0] = '\0';
3884 }
3885} /* ProductStr */
3886
3887/*****************************************************************************
3888 *
3889 * StartDrvCleanupTimer - Start timer to check for descriptors which
3890 * might be placed in descriptor ring, but
3891 * havent been handled up to now
3892 *
3893 * Description:
3894 * This function requests a HW-timer fo the Yukon card. The actions to
3895 * perform when this timer expires, are located in the SkDrvEvent().
3896 *
3897 * Returns: N/A
3898 */
3899static void
3900StartDrvCleanupTimer(SK_AC *pAC) {
3901 SK_EVPARA EventParam; /* Event struct for timer event */
3902
3903 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3904 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3905 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3906 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3907 SKGE_DRV, SK_DRV_TIMER, EventParam);
3908}
3909
3910/*****************************************************************************
3911 *
3912 * StopDrvCleanupTimer - Stop timer to check for descriptors
3913 *
3914 * Description:
3915 * This function requests a HW-timer fo the Yukon card. The actions to
3916 * perform when this timer expires, are located in the SkDrvEvent().
3917 *
3918 * Returns: N/A
3919 */
3920static void
3921StopDrvCleanupTimer(SK_AC *pAC) {
3922 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3923 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3924}
3925
3926/****************************************************************************/
3927/* functions for common modules *********************************************/
3928/****************************************************************************/
3929
3930
3931/*****************************************************************************
3932 *
3933 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3934 *
3935 * Description:
3936 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3937 * is embedded into a socket buff data area.
3938 *
3939 * Context:
3940 * runtime
3941 *
3942 * Returns:
3943 * NULL or pointer to Mbuf.
3944 */
3945SK_MBUF *SkDrvAllocRlmtMbuf(
3946SK_AC *pAC, /* pointer to adapter context */
3947SK_IOC IoC, /* the IO-context */
3948unsigned BufferSize) /* size of the requested buffer */
3949{
3950SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3951struct sk_buff *pMsgBlock; /* pointer to a new message block */
3952
3953 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3954 if (pMsgBlock == NULL) {
3955 return (NULL);
3956 }
3957 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3958 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3959 pRlmtMbuf->pNext = NULL;
3960 pRlmtMbuf->pOs = pMsgBlock;
3961 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3962 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3963 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3964 return (pRlmtMbuf);
3965
3966} /* SkDrvAllocRlmtMbuf */
3967
3968
3969/*****************************************************************************
3970 *
3971 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3972 *
3973 * Description:
3974 * This routine frees one or more RLMT mbuf(s).
3975 *
3976 * Context:
3977 * runtime
3978 *
3979 * Returns:
3980 * Nothing
3981 */
3982void SkDrvFreeRlmtMbuf(
3983SK_AC *pAC, /* pointer to adapter context */
3984SK_IOC IoC, /* the IO-context */
3985SK_MBUF *pMbuf) /* size of the requested buffer */
3986{
3987SK_MBUF *pFreeMbuf;
3988SK_MBUF *pNextMbuf;
3989
3990 pFreeMbuf = pMbuf;
3991 do {
3992 pNextMbuf = pFreeMbuf->pNext;
3993 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3994 pFreeMbuf = pNextMbuf;
3995 } while ( pFreeMbuf != NULL );
3996} /* SkDrvFreeRlmtMbuf */
3997
3998
3999/*****************************************************************************
4000 *
4001 * SkOsGetTime - provide a time value
4002 *
4003 * Description:
4004 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
4005 * It is not used for absolute time, but only for time differences.
4006 *
4007 *
4008 * Returns:
4009 * Time value
4010 */
4011SK_U64 SkOsGetTime(SK_AC *pAC)
4012{
4013 SK_U64 PrivateJiffies;
4014 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
4015 return PrivateJiffies;
4016} /* SkOsGetTime */
4017
4018
4019/*****************************************************************************
4020 *
4021 * SkPciReadCfgDWord - read a 32 bit value from pci config space
4022 *
4023 * Description:
4024 * This routine reads a 32 bit value from the pci configuration
4025 * space.
4026 *
4027 * Returns:
4028 * 0 - indicate everything worked ok.
4029 * != 0 - error indication
4030 */
4031int SkPciReadCfgDWord(
4032SK_AC *pAC, /* Adapter Control structure pointer */
4033int PciAddr, /* PCI register address */
4034SK_U32 *pVal) /* pointer to store the read value */
4035{
4036 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
4037 return(0);
4038} /* SkPciReadCfgDWord */
4039
4040
4041/*****************************************************************************
4042 *
4043 * SkPciReadCfgWord - read a 16 bit value from pci config space
4044 *
4045 * Description:
4046 * This routine reads a 16 bit value from the pci configuration
4047 * space.
4048 *
4049 * Returns:
4050 * 0 - indicate everything worked ok.
4051 * != 0 - error indication
4052 */
4053int SkPciReadCfgWord(
4054SK_AC *pAC, /* Adapter Control structure pointer */
4055int PciAddr, /* PCI register address */
4056SK_U16 *pVal) /* pointer to store the read value */
4057{
4058 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
4059 return(0);
4060} /* SkPciReadCfgWord */
4061
4062
4063/*****************************************************************************
4064 *
4065 * SkPciReadCfgByte - read a 8 bit value from pci config space
4066 *
4067 * Description:
4068 * This routine reads a 8 bit value from the pci configuration
4069 * space.
4070 *
4071 * Returns:
4072 * 0 - indicate everything worked ok.
4073 * != 0 - error indication
4074 */
4075int SkPciReadCfgByte(
4076SK_AC *pAC, /* Adapter Control structure pointer */
4077int PciAddr, /* PCI register address */
4078SK_U8 *pVal) /* pointer to store the read value */
4079{
4080 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4081 return(0);
4082} /* SkPciReadCfgByte */
4083
4084
4085/*****************************************************************************
4086 *
4087 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
4088 *
4089 * Description:
4090 * This routine writes a 32 bit value to the pci configuration
4091 * space.
4092 *
4093 * Returns:
4094 * 0 - indicate everything worked ok.
4095 * != 0 - error indication
4096 */
4097int SkPciWriteCfgDWord(
4098SK_AC *pAC, /* Adapter Control structure pointer */
4099int PciAddr, /* PCI register address */
4100SK_U32 Val) /* pointer to store the read value */
4101{
4102 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
4103 return(0);
4104} /* SkPciWriteCfgDWord */
4105
4106
4107/*****************************************************************************
4108 *
4109 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4110 *
4111 * Description:
4112 * This routine writes a 16 bit value to the pci configuration
4113 * space. The flag PciConfigUp indicates whether the config space
4114 * is accesible or must be set up first.
4115 *
4116 * Returns:
4117 * 0 - indicate everything worked ok.
4118 * != 0 - error indication
4119 */
4120int SkPciWriteCfgWord(
4121SK_AC *pAC, /* Adapter Control structure pointer */
4122int PciAddr, /* PCI register address */
4123SK_U16 Val) /* pointer to store the read value */
4124{
4125 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4126 return(0);
4127} /* SkPciWriteCfgWord */
4128
4129
4130/*****************************************************************************
4131 *
4132 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4133 *
4134 * Description:
4135 * This routine writes a 8 bit value to the pci configuration
4136 * space. The flag PciConfigUp indicates whether the config space
4137 * is accesible or must be set up first.
4138 *
4139 * Returns:
4140 * 0 - indicate everything worked ok.
4141 * != 0 - error indication
4142 */
4143int SkPciWriteCfgByte(
4144SK_AC *pAC, /* Adapter Control structure pointer */
4145int PciAddr, /* PCI register address */
4146SK_U8 Val) /* pointer to store the read value */
4147{
4148 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4149 return(0);
4150} /* SkPciWriteCfgByte */
4151
4152
4153/*****************************************************************************
4154 *
4155 * SkDrvEvent - handle driver events
4156 *
4157 * Description:
4158 * This function handles events from all modules directed to the driver
4159 *
4160 * Context:
4161 * Is called under protection of slow path lock.
4162 *
4163 * Returns:
4164 * 0 if everything ok
4165 * < 0 on error
4166 *
4167 */
4168int SkDrvEvent(
4169SK_AC *pAC, /* pointer to adapter context */
4170SK_IOC IoC, /* io-context */
4171SK_U32 Event, /* event-id */
4172SK_EVPARA Param) /* event-parameter */
4173{
4174SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4175struct sk_buff *pMsg; /* pointer to a message block */
4176int FromPort; /* the port from which we switch away */
4177int ToPort; /* the port we switch to */
4178SK_EVPARA NewPara; /* parameter for further events */
4179int Stat;
4180unsigned long Flags;
4181SK_BOOL DualNet;
4182
4183 switch (Event) {
4184 case SK_DRV_ADAP_FAIL:
4185 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4186 ("ADAPTER FAIL EVENT\n"));
4187 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4188 /* disable interrupts */
4189 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4190 /* cgoos */
4191 break;
4192 case SK_DRV_PORT_FAIL:
4193 FromPort = Param.Para32[0];
4194 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4195 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4196 if (FromPort == 0) {
4197 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4198 } else {
4199 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4200 }
4201 /* cgoos */
4202 break;
4203 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4204 /* action list 4 */
4205 FromPort = Param.Para32[0];
4206 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4207 ("PORT RESET EVENT, Port: %d ", FromPort));
4208 NewPara.Para64 = FromPort;
4209 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4210 spin_lock_irqsave(
4211 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4212 Flags);
4213
4214 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4215 pAC->dev[Param.Para32[0]]->flags &= ~IFF_RUNNING;
4216 spin_unlock_irqrestore(
4217 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4218 Flags);
4219
4220 /* clear rx ring from received frames */
4221 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4222
4223 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4224 spin_lock_irqsave(
4225 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4226 Flags);
4227
4228 /* tschilling: Handling of return value inserted. */
4229 if (SkGeInitPort(pAC, IoC, FromPort)) {
4230 if (FromPort == 0) {
4231 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4232 } else {
4233 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4234 }
4235 }
4236 SkAddrMcUpdate(pAC,IoC, FromPort);
4237 PortReInitBmu(pAC, FromPort);
4238 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4239 ClearAndStartRx(pAC, FromPort);
4240 spin_unlock_irqrestore(
4241 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4242 Flags);
4243 break;
4244 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4245 /* action list 5 */
4246 FromPort = Param.Para32[0];
4247 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4248 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4249 /* Mac update */
4250 SkAddrMcUpdate(pAC,IoC, FromPort);
4251
4252 if (DoPrintInterfaceChange) {
4253 printk("%s: network connection up using"
4254 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4255
4256 /* tschilling: Values changed according to LinkSpeedUsed. */
4257 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4258 if (Stat == SK_LSPEED_STAT_10MBPS) {
4259 printk(" speed: 10\n");
4260 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4261 printk(" speed: 100\n");
4262 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4263 printk(" speed: 1000\n");
4264 } else {
4265 printk(" speed: unknown\n");
4266 }
4267
4268
4269 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4270 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4271 Stat == SK_LMODE_STAT_AUTOFULL) {
4272 printk(" autonegotiation: yes\n");
4273 }
4274 else {
4275 printk(" autonegotiation: no\n");
4276 }
4277 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4278 Stat == SK_LMODE_STAT_HALF) {
4279 printk(" duplex mode: half\n");
4280 }
4281 else {
4282 printk(" duplex mode: full\n");
4283 }
4284 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4285 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4286 printk(" flowctrl: remote send\n");
4287 }
4288 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4289 printk(" flowctrl: local send\n");
4290 }
4291 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4292 printk(" flowctrl: symmetric\n");
4293 }
4294 else {
4295 printk(" flowctrl: none\n");
4296 }
4297
4298 /* tschilling: Check against CopperType now. */
4299 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4300 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4301 SK_LSPEED_STAT_1000MBPS)) {
4302 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4303 if (Stat == SK_MS_STAT_MASTER ) {
4304 printk(" role: master\n");
4305 }
4306 else if (Stat == SK_MS_STAT_SLAVE ) {
4307 printk(" role: slave\n");
4308 }
4309 else {
4310 printk(" role: ???\n");
4311 }
4312 }
4313
4314 /*
4315 Display dim (dynamic interrupt moderation)
4316 informations
4317 */
4318 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4319 printk(" irq moderation: static (%d ints/sec)\n",
4320 pAC->DynIrqModInfo.MaxModIntsPerSec);
4321 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4322 printk(" irq moderation: dynamic (%d ints/sec)\n",
4323 pAC->DynIrqModInfo.MaxModIntsPerSec);
4324 else
4325 printk(" irq moderation: disabled\n");
4326
4327
4328#ifdef SK_ZEROCOPY
4329 if (pAC->ChipsetType)
4330#ifdef USE_SK_TX_CHECKSUM
4331 printk(" scatter-gather: enabled\n");
4332#else
4333 printk(" tx-checksum: disabled\n");
4334#endif
4335 else
4336 printk(" scatter-gather: disabled\n");
4337#else
4338 printk(" scatter-gather: disabled\n");
4339#endif
4340
4341#ifndef USE_SK_RX_CHECKSUM
4342 printk(" rx-checksum: disabled\n");
4343#endif
4344
4345 } else {
4346 DoPrintInterfaceChange = SK_TRUE;
4347 }
4348
4349 if ((Param.Para32[0] != pAC->ActivePort) &&
4350 (pAC->RlmtNets == 1)) {
4351 NewPara.Para32[0] = pAC->ActivePort;
4352 NewPara.Para32[1] = Param.Para32[0];
4353 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4354 NewPara);
4355 }
4356
4357 /* Inform the world that link protocol is up. */
4358 pAC->dev[Param.Para32[0]]->flags |= IFF_RUNNING;
4359
4360 break;
4361 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4362 /* action list 7 */
4363 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4364 ("NET DOWN EVENT "));
4365 if (DoPrintInterfaceChange) {
4366 printk("%s: network connection down\n",
4367 pAC->dev[Param.Para32[1]]->name);
4368 } else {
4369 DoPrintInterfaceChange = SK_TRUE;
4370 }
4371 pAC->dev[Param.Para32[1]]->flags &= ~IFF_RUNNING;
4372 break;
4373 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4374 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4375 ("PORT SWITCH HARD "));
4376 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4377 /* action list 6 */
4378 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4379 'A'+Param.Para32[1]);
4380 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4381 FromPort = Param.Para32[0];
4382 ToPort = Param.Para32[1];
4383 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4384 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4385 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4386 NewPara.Para64 = FromPort;
4387 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4388 NewPara.Para64 = ToPort;
4389 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4390 spin_lock_irqsave(
4391 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4392 Flags);
4393 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4394 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4395 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4396 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4397 spin_unlock_irqrestore(
4398 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4399 Flags);
4400
4401 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4402 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4403
4404 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4405 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4406 spin_lock_irqsave(
4407 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4408 Flags);
4409 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4410 pAC->ActivePort = ToPort;
4411#if 0
4412 SetQueueSizes(pAC);
4413#else
4414 /* tschilling: New common function with minimum size check. */
4415 DualNet = SK_FALSE;
4416 if (pAC->RlmtNets == 2) {
4417 DualNet = SK_TRUE;
4418 }
4419
4420 if (SkGeInitAssignRamToQueues(
4421 pAC,
4422 pAC->ActivePort,
4423 DualNet)) {
4424 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4425 spin_unlock_irqrestore(
4426 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4427 Flags);
4428 printk("SkGeInitAssignRamToQueues failed.\n");
4429 break;
4430 }
4431#endif
4432 /* tschilling: Handling of return values inserted. */
4433 if (SkGeInitPort(pAC, IoC, FromPort) ||
4434 SkGeInitPort(pAC, IoC, ToPort)) {
4435 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4436 }
4437 if (Event == SK_DRV_SWITCH_SOFT) {
4438 SkMacRxTxEnable(pAC, IoC, FromPort);
4439 }
4440 SkMacRxTxEnable(pAC, IoC, ToPort);
4441 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4442 SkAddrMcUpdate(pAC, IoC, FromPort);
4443 SkAddrMcUpdate(pAC, IoC, ToPort);
4444 PortReInitBmu(pAC, FromPort);
4445 PortReInitBmu(pAC, ToPort);
4446 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4447 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4448 ClearAndStartRx(pAC, FromPort);
4449 ClearAndStartRx(pAC, ToPort);
4450 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4451 spin_unlock_irqrestore(
4452 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4453 Flags);
4454 break;
4455 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4456 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4457 ("RLS "));
4458 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4459 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4460 skb_put(pMsg, pRlmtMbuf->Length);
4461 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4462 pMsg) < 0)
4463
4464 DEV_KFREE_SKB_ANY(pMsg);
4465 break;
4466 case SK_DRV_TIMER:
4467 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4468 /*
4469 ** expiration of the moderation timer implies that
4470 ** dynamic moderation is to be applied
4471 */
4472 SkDimStartModerationTimer(pAC);
4473 SkDimModerate(pAC);
4474 if (pAC->DynIrqModInfo.DisplayStats) {
4475 SkDimDisplayModerationSettings(pAC);
4476 }
4477 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4478 /*
4479 ** check if we need to check for descriptors which
4480 ** haven't been handled the last millisecs
4481 */
4482 StartDrvCleanupTimer(pAC);
4483 if (pAC->GIni.GIMacsFound == 2) {
4484 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4485 }
4486 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4487 } else {
4488 printk("Expiration of unknown timer\n");
4489 }
4490 break;
4491 default:
4492 break;
4493 }
4494 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4495 ("END EVENT "));
4496
4497 return (0);
4498} /* SkDrvEvent */
4499
4500
4501/*****************************************************************************
4502 *
4503 * SkErrorLog - log errors
4504 *
4505 * Description:
4506 * This function logs errors to the system buffer and to the console
4507 *
4508 * Returns:
4509 * 0 if everything ok
4510 * < 0 on error
4511 *
4512 */
4513void SkErrorLog(
4514SK_AC *pAC,
4515int ErrClass,
4516int ErrNum,
4517char *pErrorMsg)
4518{
4519char ClassStr[80];
4520
4521 switch (ErrClass) {
4522 case SK_ERRCL_OTHER:
4523 strcpy(ClassStr, "Other error");
4524 break;
4525 case SK_ERRCL_CONFIG:
4526 strcpy(ClassStr, "Configuration error");
4527 break;
4528 case SK_ERRCL_INIT:
4529 strcpy(ClassStr, "Initialization error");
4530 break;
4531 case SK_ERRCL_NORES:
4532 strcpy(ClassStr, "Out of resources error");
4533 break;
4534 case SK_ERRCL_SW:
4535 strcpy(ClassStr, "internal Software error");
4536 break;
4537 case SK_ERRCL_HW:
4538 strcpy(ClassStr, "Hardware failure");
4539 break;
4540 case SK_ERRCL_COMM:
4541 strcpy(ClassStr, "Communication error");
4542 break;
4543 }
4544 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4545 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4546 ClassStr, ErrNum, pErrorMsg);
4547
4548} /* SkErrorLog */
4549
4550#ifdef SK_DIAG_SUPPORT
4551
4552/*****************************************************************************
4553 *
4554 * SkDrvEnterDiagMode - handles DIAG attach request
4555 *
4556 * Description:
4557 * Notify the kernel to NOT access the card any longer due to DIAG
4558 * Deinitialize the Card
4559 *
4560 * Returns:
4561 * int
4562 */
4563int SkDrvEnterDiagMode(
4564SK_AC *pAc) /* pointer to adapter context */
4565{
4566 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4567 SK_AC *pAC = pNet->pAC;
4568
4569 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4570 sizeof(SK_PNMI_STRUCT_DATA));
4571
4572 pAC->DiagModeActive = DIAG_ACTIVE;
4573 if (pAC->BoardLevel > SK_INIT_DATA) {
4574 if (pNet->Up) {
4575 pAC->WasIfUp[0] = SK_TRUE;
4576 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4577 DoPrintInterfaceChange = SK_FALSE;
4578 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4579 } else {
4580 pAC->WasIfUp[0] = SK_FALSE;
4581 }
4582 if (pNet != netdev_priv(pAC->dev[1])) {
4583 pNet = netdev_priv(pAC->dev[1]);
4584 if (pNet->Up) {
4585 pAC->WasIfUp[1] = SK_TRUE;
4586 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4587 DoPrintInterfaceChange = SK_FALSE;
4588 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4589 } else {
4590 pAC->WasIfUp[1] = SK_FALSE;
4591 }
4592 }
4593 pAC->BoardLevel = SK_INIT_DATA;
4594 }
4595 return(0);
4596}
4597
4598/*****************************************************************************
4599 *
4600 * SkDrvLeaveDiagMode - handles DIAG detach request
4601 *
4602 * Description:
4603 * Notify the kernel to may access the card again after use by DIAG
4604 * Initialize the Card
4605 *
4606 * Returns:
4607 * int
4608 */
4609int SkDrvLeaveDiagMode(
4610SK_AC *pAc) /* pointer to adapter control context */
4611{
4612 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4613 sizeof(SK_PNMI_STRUCT_DATA));
4614 pAc->DiagModeActive = DIAG_NOTACTIVE;
4615 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4616 if (pAc->WasIfUp[0] == SK_TRUE) {
4617 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4618 DoPrintInterfaceChange = SK_FALSE;
4619 SkDrvInitAdapter(pAc, 0); /* first device */
4620 }
4621 if (pAc->WasIfUp[1] == SK_TRUE) {
4622 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4623 DoPrintInterfaceChange = SK_FALSE;
4624 SkDrvInitAdapter(pAc, 1); /* second device */
4625 }
4626 return(0);
4627}
4628
4629/*****************************************************************************
4630 *
4631 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4632 *
4633 * Description:
4634 * This function parses the PCI slot name information string and will
4635 * retrieve the devcie number out of it. The slot_name maintianed by
4636 * linux is in the form of '02:0a.0', whereas the first two characters
4637 * represent the bus number in hex (in the sample above this is
4638 * pci bus 0x02) and the next two characters the device number (0x0a).
4639 *
4640 * Returns:
4641 * SK_U32: The device number from the PCI slot name
4642 */
4643
4644static SK_U32 ParseDeviceNbrFromSlotName(
4645const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4646{
4647 char *CurrCharPos = (char *) SlotName;
4648 int FirstNibble = -1;
4649 int SecondNibble = -1;
4650 SK_U32 Result = 0;
4651
4652 while (*CurrCharPos != '\0') {
4653 if (*CurrCharPos == ':') {
4654 while (*CurrCharPos != '.') {
4655 CurrCharPos++;
4656 if ( (*CurrCharPos >= '0') &&
4657 (*CurrCharPos <= '9')) {
4658 if (FirstNibble == -1) {
4659 /* dec. value for '0' */
4660 FirstNibble = *CurrCharPos - 48;
4661 } else {
4662 SecondNibble = *CurrCharPos - 48;
4663 }
4664 } else if ( (*CurrCharPos >= 'a') &&
4665 (*CurrCharPos <= 'f') ) {
4666 if (FirstNibble == -1) {
4667 FirstNibble = *CurrCharPos - 87;
4668 } else {
4669 SecondNibble = *CurrCharPos - 87;
4670 }
4671 } else {
4672 Result = 0;
4673 }
4674 }
4675
4676 Result = FirstNibble;
4677 Result = Result << 4; /* first nibble is higher one */
4678 Result = Result | SecondNibble;
4679 }
4680 CurrCharPos++; /* next character */
4681 }
4682 return (Result);
4683}
4684
4685/****************************************************************************
4686 *
4687 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4688 * called if Diag attaches to that card)
4689 *
4690 * Description:
4691 * Close initialized adapter.
4692 *
4693 * Returns:
4694 * 0 - on success
4695 * error code - on error
4696 */
4697static int SkDrvDeInitAdapter(
4698SK_AC *pAC, /* pointer to adapter context */
4699int devNbr) /* what device is to be handled */
4700{
4701 struct SK_NET_DEVICE *dev;
4702
4703 dev = pAC->dev[devNbr];
4704
4705 /* On Linux 2.6 the network driver does NOT mess with reference
4706 ** counts. The driver MUST be able to be unloaded at any time
4707 ** due to the possibility of hotplug.
4708 */
4709 if (SkGeClose(dev) != 0) {
4710 return (-1);
4711 }
4712 return (0);
4713
4714} /* SkDrvDeInitAdapter() */
4715
4716/****************************************************************************
4717 *
4718 * SkDrvInitAdapter - Initialize adapter (this function is only
4719 * called if Diag deattaches from that card)
4720 *
4721 * Description:
4722 * Close initialized adapter.
4723 *
4724 * Returns:
4725 * 0 - on success
4726 * error code - on error
4727 */
4728static int SkDrvInitAdapter(
4729SK_AC *pAC, /* pointer to adapter context */
4730int devNbr) /* what device is to be handled */
4731{
4732 struct SK_NET_DEVICE *dev;
4733
4734 dev = pAC->dev[devNbr];
4735
4736 if (SkGeOpen(dev) != 0) {
4737 return (-1);
4738 }
4739
4740 /*
4741 ** Use correct MTU size and indicate to kernel TX queue can be started
4742 */
4743 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4744 return (-1);
4745 }
4746 return (0);
4747
4748} /* SkDrvInitAdapter */
4749
4750#endif
4751
4752#ifdef DEBUG
4753/****************************************************************************/
4754/* "debug only" section *****************************************************/
4755/****************************************************************************/
4756
4757
4758/*****************************************************************************
4759 *
4760 * DumpMsg - print a frame
4761 *
4762 * Description:
4763 * This function prints frames to the system logfile/to the console.
4764 *
4765 * Returns: N/A
4766 *
4767 */
4768static void DumpMsg(struct sk_buff *skb, char *str)
4769{
4770 int msglen;
4771
4772 if (skb == NULL) {
4773 printk("DumpMsg(): NULL-Message\n");
4774 return;
4775 }
4776
4777 if (skb->data == NULL) {
4778 printk("DumpMsg(): Message empty\n");
4779 return;
4780 }
4781
4782 msglen = skb->len;
4783 if (msglen > 64)
4784 msglen = 64;
4785
4786 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4787
4788 DumpData((char *)skb->data, msglen);
4789
4790 printk("------- End of message ---------\n");
4791} /* DumpMsg */
4792
4793
4794
4795/*****************************************************************************
4796 *
4797 * DumpData - print a data area
4798 *
4799 * Description:
4800 * This function prints a area of data to the system logfile/to the
4801 * console.
4802 *
4803 * Returns: N/A
4804 *
4805 */
4806static void DumpData(char *p, int size)
4807{
4808register int i;
4809int haddr, addr;
4810char hex_buffer[180];
4811char asc_buffer[180];
4812char HEXCHAR[] = "0123456789ABCDEF";
4813
4814 addr = 0;
4815 haddr = 0;
4816 hex_buffer[0] = 0;
4817 asc_buffer[0] = 0;
4818 for (i=0; i < size; ) {
4819 if (*p >= '0' && *p <='z')
4820 asc_buffer[addr] = *p;
4821 else
4822 asc_buffer[addr] = '.';
4823 addr++;
4824 asc_buffer[addr] = 0;
4825 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4826 haddr++;
4827 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4828 haddr++;
4829 hex_buffer[haddr] = ' ';
4830 haddr++;
4831 hex_buffer[haddr] = 0;
4832 p++;
4833 i++;
4834 if (i%16 == 0) {
4835 printk("%s %s\n", hex_buffer, asc_buffer);
4836 addr = 0;
4837 haddr = 0;
4838 }
4839 }
4840} /* DumpData */
4841
4842
4843/*****************************************************************************
4844 *
4845 * DumpLong - print a data area as long values
4846 *
4847 * Description:
4848 * This function prints a area of data to the system logfile/to the
4849 * console.
4850 *
4851 * Returns: N/A
4852 *
4853 */
4854static void DumpLong(char *pc, int size)
4855{
4856register int i;
4857int haddr, addr;
4858char hex_buffer[180];
4859char asc_buffer[180];
4860char HEXCHAR[] = "0123456789ABCDEF";
4861long *p;
4862int l;
4863
4864 addr = 0;
4865 haddr = 0;
4866 hex_buffer[0] = 0;
4867 asc_buffer[0] = 0;
4868 p = (long*) pc;
4869 for (i=0; i < size; ) {
4870 l = (long) *p;
4871 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4872 haddr++;
4873 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4874 haddr++;
4875 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4876 haddr++;
4877 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4878 haddr++;
4879 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4880 haddr++;
4881 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4882 haddr++;
4883 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4884 haddr++;
4885 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4886 haddr++;
4887 hex_buffer[haddr] = ' ';
4888 haddr++;
4889 hex_buffer[haddr] = 0;
4890 p++;
4891 i++;
4892 if (i%8 == 0) {
4893 printk("%4x %s\n", (i-8)*4, hex_buffer);
4894 haddr = 0;
4895 }
4896 }
4897 printk("------------------------\n");
4898} /* DumpLong */
4899
4900#endif
4901
4902static int __devinit skge_probe_one(struct pci_dev *pdev,
4903 const struct pci_device_id *ent)
4904{
4905 SK_AC *pAC;
4906 DEV_NET *pNet = NULL;
4907 struct net_device *dev = NULL;
4908 static int boards_found = 0;
4909 int error = -ENODEV;
4910
4911 if (pci_enable_device(pdev))
4912 goto out;
4913
4914 /* Configure DMA attributes. */
4915 if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL) &&
4916 pci_set_dma_mask(pdev, (u64) 0xffffffff))
4917 goto out_disable_device;
4918
4919
4920 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4921 printk(KERN_ERR "Unable to allocate etherdev "
4922 "structure!\n");
4923 goto out_disable_device;
4924 }
4925
4926 pNet = netdev_priv(dev);
4927 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4928 if (!pNet->pAC) {
4929 printk(KERN_ERR "Unable to allocate adapter "
4930 "structure!\n");
4931 goto out_free_netdev;
4932 }
4933
4934 memset(pNet->pAC, 0, sizeof(SK_AC));
4935 pAC = pNet->pAC;
4936 pAC->PciDev = pdev;
4937 pAC->PciDevId = pdev->device;
4938 pAC->dev[0] = dev;
4939 pAC->dev[1] = dev;
4940 sprintf(pAC->Name, "SysKonnect SK-98xx");
4941 pAC->CheckQueue = SK_FALSE;
4942
4943 pNet->Mtu = 1500;
4944 pNet->Up = 0;
4945 dev->irq = pdev->irq;
4946 error = SkGeInitPCI(pAC);
4947 if (error) {
4948 printk("SKGE: PCI setup failed: %i\n", error);
4949 goto out_free_netdev;
4950 }
4951
4952 SET_MODULE_OWNER(dev);
4953 dev->open = &SkGeOpen;
4954 dev->stop = &SkGeClose;
4955 dev->hard_start_xmit = &SkGeXmit;
4956 dev->get_stats = &SkGeStats;
4957 dev->set_multicast_list = &SkGeSetRxMode;
4958 dev->set_mac_address = &SkGeSetMacAddr;
4959 dev->do_ioctl = &SkGeIoctl;
4960 dev->change_mtu = &SkGeChangeMtu;
4961#ifdef CONFIG_NET_POLL_CONTROLLER
4962 dev->poll_controller = &SkGePollController;
4963#endif
4964 dev->flags &= ~IFF_RUNNING;
4965 SET_NETDEV_DEV(dev, &pdev->dev);
4966 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4967
4968#ifdef SK_ZEROCOPY
4969#ifdef USE_SK_TX_CHECKSUM
4970 if (pAC->ChipsetType) {
4971 /* Use only if yukon hardware */
4972 /* SK and ZEROCOPY - fly baby... */
4973 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
4974 }
4975#endif
4976#endif
4977
4978 pAC->Index = boards_found++;
4979
4980 if (SkGeBoardInit(dev, pAC))
4981 goto out_free_netdev;
4982
4983 /* Register net device */
4984 if (register_netdev(dev)) {
4985 printk(KERN_ERR "SKGE: Could not register device.\n");
4986 goto out_free_resources;
4987 }
4988
4989 /* Print adapter specific string from vpd */
4990 ProductStr(pAC);
4991 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4992
4993 /* Print configuration settings */
4994 printk(" PrefPort:%c RlmtMode:%s\n",
4995 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4996 (pAC->RlmtMode==0) ? "Check Link State" :
4997 ((pAC->RlmtMode==1) ? "Check Link State" :
4998 ((pAC->RlmtMode==3) ? "Check Local Port" :
4999 ((pAC->RlmtMode==7) ? "Check Segmentation" :
5000 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
5001
5002 SkGeYellowLED(pAC, pAC->IoBase, 1);
5003
5004
5005 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
5006
5007 SkGeProcCreate(dev);
5008
5009 pNet->PortNr = 0;
5010 pNet->NetNr = 0;
5011
5012 boards_found++;
5013
5014 /* More then one port found */
5015 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
5016 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
5017 printk(KERN_ERR "Unable to allocate etherdev "
5018 "structure!\n");
5019 goto out;
5020 }
5021
5022 pAC->dev[1] = dev;
5023 pNet = netdev_priv(dev);
5024 pNet->PortNr = 1;
5025 pNet->NetNr = 1;
5026 pNet->pAC = pAC;
5027 pNet->Mtu = 1500;
5028 pNet->Up = 0;
5029
5030 dev->open = &SkGeOpen;
5031 dev->stop = &SkGeClose;
5032 dev->hard_start_xmit = &SkGeXmit;
5033 dev->get_stats = &SkGeStats;
5034 dev->set_multicast_list = &SkGeSetRxMode;
5035 dev->set_mac_address = &SkGeSetMacAddr;
5036 dev->do_ioctl = &SkGeIoctl;
5037 dev->change_mtu = &SkGeChangeMtu;
5038 dev->flags &= ~IFF_RUNNING;
5039 SET_NETDEV_DEV(dev, &pdev->dev);
5040 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
5041
5042#ifdef SK_ZEROCOPY
5043#ifdef USE_SK_TX_CHECKSUM
5044 if (pAC->ChipsetType) {
5045 /* SG and ZEROCOPY - fly baby... */
5046 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
5047 }
5048#endif
5049#endif
5050
5051 if (register_netdev(dev)) {
5052 printk(KERN_ERR "SKGE: Could not register device.\n");
5053 free_netdev(dev);
5054 pAC->dev[1] = pAC->dev[0];
5055 } else {
5056 SkGeProcCreate(dev);
5057 memcpy(&dev->dev_addr,
5058 &pAC->Addr.Net[1].CurrentMacAddress, 6);
5059
5060 printk("%s: %s\n", dev->name, pAC->DeviceStr);
5061 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
5062 }
5063 }
5064
5065 /* Save the hardware revision */
5066 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
5067 (pAC->GIni.GIPciHwRev & 0x0F);
5068
5069 /* Set driver globals */
5070 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
5071 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
5072
5073 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
5074 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
5075
5076 pci_set_drvdata(pdev, dev);
5077 return 0;
5078
5079 out_free_resources:
5080 FreeResources(dev);
5081 out_free_netdev:
5082 free_netdev(dev);
5083 out_disable_device:
5084 pci_disable_device(pdev);
5085 out:
5086 return error;
5087}
5088
5089static void __devexit skge_remove_one(struct pci_dev *pdev)
5090{
5091 struct net_device *dev = pci_get_drvdata(pdev);
5092 DEV_NET *pNet = netdev_priv(dev);
5093 SK_AC *pAC = pNet->pAC;
5094 struct net_device *otherdev = pAC->dev[1];
5095
5096 SkGeProcRemove(dev);
5097 unregister_netdev(dev);
5098 if (otherdev != dev)
5099 SkGeProcRemove(otherdev);
5100
5101 SkGeYellowLED(pAC, pAC->IoBase, 0);
5102
5103 if (pAC->BoardLevel == SK_INIT_RUN) {
5104 SK_EVPARA EvPara;
5105 unsigned long Flags;
5106
5107 /* board is still alive */
5108 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5109 EvPara.Para32[0] = 0;
5110 EvPara.Para32[1] = -1;
5111 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5112 EvPara.Para32[0] = 1;
5113 EvPara.Para32[1] = -1;
5114 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5115 SkEventDispatcher(pAC, pAC->IoBase);
5116 /* disable interrupts */
5117 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5118 SkGeDeInit(pAC, pAC->IoBase);
5119 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5120 pAC->BoardLevel = SK_INIT_DATA;
5121 /* We do NOT check here, if IRQ was pending, of course*/
5122 }
5123
5124 if (pAC->BoardLevel == SK_INIT_IO) {
5125 /* board is still alive */
5126 SkGeDeInit(pAC, pAC->IoBase);
5127 pAC->BoardLevel = SK_INIT_DATA;
5128 }
5129
5130 FreeResources(dev);
5131 free_netdev(dev);
5132 if (otherdev != dev)
5133 free_netdev(otherdev);
5134 kfree(pAC);
5135}
5136
5137static struct pci_device_id skge_pci_tbl[] = {
5138 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5139 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5140 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5141 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5142 { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5143 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5144#if 0 /* don't handle Yukon2 cards at the moment -- mlindner@syskonnect.de */
5145 { PCI_VENDOR_ID_MARVELL, 0x4360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5146 { PCI_VENDOR_ID_MARVELL, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5147#endif
5148 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5149 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5150 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5151 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5152 { 0, }
5153};
5154
5155MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5156
5157static struct pci_driver skge_driver = {
5158 .name = "sk98lin",
5159 .id_table = skge_pci_tbl,
5160 .probe = skge_probe_one,
5161 .remove = __devexit_p(skge_remove_one),
5162};
5163
5164static int __init skge_init(void)
5165{
5166 int error;
5167
5168 pSkRootDir = proc_mkdir(SKRootName, proc_net);
5169 if (pSkRootDir)
5170 pSkRootDir->owner = THIS_MODULE;
5171
5172 error = pci_register_driver(&skge_driver);
5173 if (error)
5174 proc_net_remove(SKRootName);
5175 return error;
5176}
5177
5178static void __exit skge_exit(void)
5179{
5180 pci_unregister_driver(&skge_driver);
5181 proc_net_remove(SKRootName);
5182
5183}
5184
5185module_init(skge_init);
5186module_exit(skge_exit);