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