Import 2.3.47pre4
[davej-history.git] / drivers / net / sk98lin / skge.c
blob27d0dba242a23ba5b303e90ca5a2b38233df33ae
1 /******************************************************************************
3 * Name: skge.c
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.27 $
6 * Date: $Date: 1999/11/25 09:06:28 $
7 * Purpose: The main driver source module
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998,1999 SysKonnect,
14 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
16 * Driver for SysKonnect Gigabit Ethernet Server Adapters:
18 * SK-9841 (single link 1000Base-LX)
19 * SK-9842 (dual link 1000Base-LX)
20 * SK-9843 (single link 1000Base-SX)
21 * SK-9844 (dual link 1000Base-SX)
22 * SK-9821 (single link 1000Base-T)
23 * SK-9822 (dual link 1000Base-T)
25 * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
26 * SysKonnects GEnesis Solaris driver
27 * Author: Christoph Goos (cgoos@syskonnect.de)
29 * Address all question to: linux@syskonnect.de
31 * The technical manual for the adapters is available from SysKonnect's
32 * web pages: www.syskonnect.com
33 * Goto "Support" and search Knowledge Base for "manual".
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2 of the License, or
38 * (at your option) any later version.
40 * The information in this file is provided "AS IS" without warranty.
42 ******************************************************************************/
44 /******************************************************************************
46 * History:
48 * $Log: skge.c,v $
49 * Revision 1.27 1999/11/25 09:06:28 cgoos
50 * Changed base_addr to unsigned long.
52 * Revision 1.26 1999/11/22 13:29:16 cgoos
53 * Changed license header to GPL.
54 * Changes for inclusion in linux kernel (2.2.13).
55 * Removed 2.0.x defines.
56 * Changed SkGeProbe to skge_probe.
57 * Added checks in SkGeIoctl.
59 * Revision 1.25 1999/10/07 14:47:52 cgoos
60 * Changed 984x to 98xx.
62 * Revision 1.24 1999/09/30 07:21:01 cgoos
63 * Removed SK_RLMT_SLOW_LOOKAHEAD option.
64 * Giving spanning tree packets also to OS now.
66 * Revision 1.23 1999/09/29 07:36:50 cgoos
67 * Changed assignment for IsBc/IsMc.
69 * Revision 1.22 1999/09/28 12:57:09 cgoos
70 * Added CheckQueue also to Single-Port-ISR.
72 * Revision 1.21 1999/09/28 12:42:41 cgoos
73 * Changed parameter strings for RlmtMode.
75 * Revision 1.20 1999/09/28 12:37:57 cgoos
76 * Added CheckQueue for fast delivery of RLMT frames.
78 * Revision 1.19 1999/09/16 07:57:25 cgoos
79 * Copperfield changes.
81 * Revision 1.18 1999/09/03 13:06:30 cgoos
82 * Fixed RlmtMode=CheckSeg bug: wrong DEV_KFREE_SKB in RLMT_SEND caused
83 * double allocated skb's.
84 * FrameStat in ReceiveIrq was accessed via wrong Rxd.
85 * Queue size for async. standby Tx queue was zero.
86 * FillRxLimit of 0 could cause problems with ReQueue, changed to 1.
87 * Removed debug output of checksum statistic.
89 * Revision 1.17 1999/08/11 13:55:27 cgoos
90 * Transmit descriptor polling was not reenabled after SkGePortInit.
92 * Revision 1.16 1999/07/27 15:17:29 cgoos
93 * Added some "\n" in output strings (removed while debuging...).
95 * Revision 1.15 1999/07/23 12:09:30 cgoos
96 * Performance optimization, rx checksumming, large frame support.
98 * Revision 1.14 1999/07/14 11:26:27 cgoos
99 * Removed Link LED settings (now in RLMT).
100 * Added status output at NET UP.
101 * Fixed SMP problems with Tx and SWITCH running in parallel.
102 * Fixed return code problem at RLMT_SEND event.
104 * Revision 1.13 1999/04/07 10:11:42 cgoos
105 * Fixed Single Port problems.
106 * Fixed Multi-Adapter problems.
107 * Always display startup string.
109 * Revision 1.12 1999/03/29 12:26:37 cgoos
110 * Reversed locking to fine granularity.
111 * Fixed skb double alloc problem (caused by incorrect xmit return code).
112 * Enhanced function descriptions.
114 * Revision 1.11 1999/03/15 13:10:51 cgoos
115 * Changed device identifier in output string to ethX.
117 * Revision 1.10 1999/03/15 12:12:34 cgoos
118 * Changed copyright notice.
120 * Revision 1.9 1999/03/15 12:10:17 cgoos
121 * Changed locking to one driver lock.
122 * Added check of SK_AC-size (for consistency with library).
124 * Revision 1.8 1999/03/08 11:44:02 cgoos
125 * Fixed missing dev->tbusy in SkGeXmit.
126 * Changed large frame (jumbo) buffer number.
127 * Added copying of short frames.
129 * Revision 1.7 1999/03/04 13:26:57 cgoos
130 * Fixed spinlock calls for SMP.
132 * Revision 1.6 1999/03/02 09:53:51 cgoos
133 * Added descriptor revertion for big endian machines.
135 * Revision 1.5 1999/03/01 08:50:59 cgoos
136 * Fixed SkGeChangeMtu.
137 * Fixed pci config space accesses.
139 * Revision 1.4 1999/02/18 15:48:44 cgoos
140 * Corrected some printk's.
142 * Revision 1.3 1999/02/18 12:45:55 cgoos
143 * Changed SK_MAX_CARD_PARAM to default 16
145 * Revision 1.2 1999/02/18 10:55:32 cgoos
146 * Removed SkGeDrvTimeStamp function.
147 * Printing "ethX:" before adapter type at adapter init.
150 * 10-Feb-1999 cg Created, based on Linux' acenic.c, 3c59x.c and
151 * SysKonnects GEnesis Solaris driver
153 ******************************************************************************/
155 /******************************************************************************
157 * Possible compiler options (#define xxx / -Dxxx):
159 * debugging can be enable by changing SK_DEBUG_CHKMOD and
160 * SK_DEBUG_CHKCAT in makefile (described there).
162 ******************************************************************************/
164 /******************************************************************************
166 * Description:
168 * This is the main module of the Linux GE driver.
170 * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
171 * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
172 * Those are used for drivers on multiple OS', so some thing may seem
173 * unnecessary complicated on Linux. Please do not try to 'clean up'
174 * them without VERY good reasons, because this will make it more
175 * difficult to keep the Linux driver in synchronisation with the
176 * other versions.
178 * Include file hierarchy:
180 * <linux/module.h>
182 * "h/skdrv1st.h"
183 * <linux/version.h>
184 * <linux/types.h>
185 * <linux/kernel.h>
186 * <linux/string.h>
187 * <linux/errno.h>
188 * <linux/ioport.h>
189 * <linux/malloc.h>
190 * <linux/interrupt.h>
191 * <linux/pci.h>
192 * <asm/byteorder.h>
193 * <asm/bitops.h>
194 * <asm/io.h>
195 * <linux/netdevice.h>
196 * <linux/etherdevice.h>
197 * <linux/skbuff.h>
198 * those three depending on kernel version used:
199 * <linux/bios32.h>
200 * <linux/init.h>
201 * <asm/uaccess.h>
202 * <net/checksum.h>
204 * "h/skerror.h"
205 * "h/skdebug.h"
206 * "h/sktypes.h"
207 * "h/lm80.h"
208 * "h/xmac_ii.h"
210 * "h/skdrv2nd.h"
211 * "h/skqueue.h"
212 * "h/skgehwt.h"
213 * "h/sktimer.h"
214 * "h/ski2c.h"
215 * "h/skgepnmi.h"
216 * "h/skvpd.h"
217 * "h/skgehw.h"
218 * "h/skgeinit.h"
219 * "h/skaddr.h"
220 * "h/skgesirq.h"
221 * "h/skcsum.h"
222 * "h/skrlmt.h"
224 ******************************************************************************/
226 static const char SysKonnectFileId[] = "@(#)" __FILE__ " (C) SysKonnect.";
227 static const char SysKonnectBuildNumber[] =
228 "@(#)SK-BUILD: 3.02 (19991111) PL: 01";
230 #include <linux/module.h>
231 #include <linux/init.h>
233 #include "h/skdrv1st.h"
234 #include "h/skdrv2nd.h"
236 /* defines ******************************************************************/
238 #define BOOT_STRING "sk98lin: Network Device Driver v3.02\n" \
239 "Copyright (C) 1999 SysKonnect"
241 #define VER_STRING "3.02"
244 /* for debuging on x86 only */
245 /* #define BREAKPOINT() asm(" int $3"); */
247 /* use of a transmit complete interrupt */
248 #define USE_TX_COMPLETE
250 /* use interrupt moderation (for tx complete only) */
251 // #define USE_INT_MOD
252 #define INTS_PER_SEC 1000
255 * threshold for copying small receive frames
256 * set to 0 to avoid copying, set to 9001 to copy all frames
258 #define SK_COPY_THRESHOLD 200
260 /* number of adapters that can be configured via command line params */
261 #define SK_MAX_CARD_PARAM 16
264 * use those defines for a compile-in version of the driver instead
265 * of command line parameters
267 // #define AUTO_NEG_A {"Sense", }
268 // #define AUTO_NEG_B {"Sense", }
269 // #define DUP_CAP_A {"Both", }
270 // #define DUP_CAP_B {"Both", }
271 // #define FLOW_CTRL_A {"SymOrRem", }
272 // #define FLOW_CTRL_B {"SymOrRem", }
273 // #define ROLE_A {"Auto", }
274 // #define ROLE_B {"Auto", }
275 // #define PREF_PORT {"A", }
276 // #define RLMT_MODE {"CheckLink", }
279 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
280 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
281 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
283 /* function prototypes ******************************************************/
284 static void FreeResources(struct net_device *dev);
285 int init_module(void);
286 void cleanup_module(void);
287 static int SkGeBoardInit(struct net_device *dev, SK_AC *pAC);
288 static SK_BOOL BoardAllocMem(SK_AC *pAC);
289 static void BoardFreeMem(SK_AC *pAC);
290 static void BoardInitMem(SK_AC *pAC);
291 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**,
292 int*, SK_BOOL);
294 static void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
295 static void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
296 static int SkGeOpen(struct net_device *dev);
297 static int SkGeClose(struct net_device *dev);
298 static int SkGeXmit(struct sk_buff *skb, struct net_device *dev);
299 static int SkGeSetMacAddr(struct net_device *dev, void *p);
300 static void SkGeSetRxMode(struct net_device *dev);
301 static struct net_device_stats *SkGeStats(struct net_device *dev);
302 static int SkGeIoctl(struct net_device *dev, struct ifreq *rq, int cmd);
303 static void GetConfiguration(SK_AC*);
304 static void ProductStr(SK_AC*);
305 static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
306 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
307 static void FillRxRing(SK_AC*, RX_PORT*);
308 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
309 static void ReceiveIrq(SK_AC*, RX_PORT*);
310 static void ClearAndStartRx(SK_AC*, int);
311 static void ClearTxIrq(SK_AC*, int, int);
312 static void ClearRxRing(SK_AC*, RX_PORT*);
313 static void ClearTxRing(SK_AC*, TX_PORT*);
314 static void SetQueueSizes(SK_AC *pAC);
315 static int SkGeChangeMtu(struct net_device *dev, int new_mtu);
316 static void PortReInitBmu(SK_AC*, int);
317 static int SkGeIocMib(SK_AC*, unsigned int, int);
318 #ifdef DEBUG
319 static void DumpMsg(struct sk_buff*, char*);
320 static void DumpData(char*, int);
321 static void DumpLong(char*, int);
322 #endif
325 /* global variables *********************************************************/
326 static const char *BootString = BOOT_STRING;
327 static struct net_device *root_dev = NULL;
328 static int probed __initdata = 0;
330 /* local variables **********************************************************/
331 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
332 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
334 /*****************************************************************************
336 * skge_probe - find all SK-98xx adapters
338 * Description:
339 * This function scans the PCI bus for SK-98xx adapters. Resources for
340 * each adapter are allocated and the adapter is brought into Init 1
341 * state.
343 * Returns:
344 * 0, if everything is ok
345 * !=0, on error
347 static int __init skge_probe (void)
349 int boards_found = 0;
350 int version_disp = 0;
351 SK_AC *pAC;
352 struct pci_dev *pdev = NULL;
353 unsigned long base_address;
354 struct net_device *dev = NULL;
356 if (probed)
357 return -ENODEV;
358 probed++;
360 /* display driver info */
361 if (!version_disp)
363 /* set display flag to TRUE so that */
364 /* we only display this string ONCE */
365 version_disp = 1;
366 printk("%s\n", BootString);
369 if (!pci_present()) /* is PCI support present? */
370 return -ENODEV;
372 while((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pdev)))
374 dev = NULL;
376 if (pdev->vendor != PCI_VENDOR_ID_SYSKONNECT ||
377 pdev->device != PCI_DEVICE_ID_SYSKONNECT_GE) {
378 continue;
380 dev = init_etherdev(dev, sizeof(SK_AC));
382 if (dev == NULL || dev->priv == NULL){
383 printk(KERN_ERR "Unable to allocate etherdev "
384 "structure!\n");
385 break;
388 memset(dev->priv, 0, sizeof(SK_AC));
390 pAC = dev->priv;
391 pAC->PciDev = *pdev;
392 pAC->PciDevId = pdev->device;
393 pAC->dev = dev;
394 sprintf(pAC->Name, "SysKonnect SK-98xx");
395 pAC->CheckQueue = SK_FALSE;
397 dev->irq = pdev->irq;
399 dev->open = &SkGeOpen;
400 dev->stop = &SkGeClose;
401 dev->hard_start_xmit = &SkGeXmit;
402 dev->get_stats = &SkGeStats;
403 dev->set_multicast_list = &SkGeSetRxMode;
404 dev->set_mac_address = &SkGeSetMacAddr;
405 dev->do_ioctl = &SkGeIoctl;
406 dev->change_mtu = &SkGeChangeMtu;
409 * Dummy value.
411 dev->base_addr = 42;
413 pci_set_master(pdev);
415 #ifdef __sparc__
416 /* Set the proper cache line size value, plus enable
417 * write-invalidate and fast back-to-back on Sparc.
420 SK_U16 pci_command;
422 SkPciWriteCfgByte(pAC, PCI_CACHE_LINE_SIZE, 0x10);
424 SkPciReadCfgWord(pAC, PCI_COMMAND, &pci_command);
425 pci_command |= (PCI_COMMAND_INVALIDATE | PCI_COMMAND_FAST_BACK);
426 SkPciWriteCfgWord(pAC, PCI_COMMAND, pci_command);
428 #endif
430 base_address = pdev->resource[0].start;
432 #ifdef SK_BIG_ENDIAN
434 * On big endian machines, we use the adapter's aibility of
435 * reading the descriptors as big endian.
438 SK_U32 our2;
439 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
440 our2 |= PCI_REV_DESC;
441 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
443 #endif /* BIG ENDIAN */
446 * Remap the regs into kernel space.
450 pAC->IoBase = (char*)ioremap(base_address, 0x4000);
451 if (!pAC->IoBase){
452 printk(KERN_ERR "%s: Unable to map I/O register, "
453 "SK 98xx No. %i will be disabled.\n",
454 dev->name, boards_found);
455 break;
457 pAC->Index = boards_found;
459 if (SkGeBoardInit(dev, pAC)) {
460 FreeResources(dev);
461 continue;
464 memcpy((caddr_t) &dev->dev_addr,
465 (caddr_t) &pAC->Addr.CurrentMacAddress, 6);
467 boards_found++;
470 * This is bollocks, but we need to tell the net-init
471 * code that it shall go for the next device.
473 #ifndef MODULE
474 dev->base_addr = 0;
475 #endif
479 * If we're at this point we're going through skge_probe() for
480 * the first time. Return success (0) if we've initialized 1
481 * or more boards. Otherwise, return failure (-ENODEV).
484 return boards_found;
485 } /* skge_probe */
488 /*****************************************************************************
490 * FreeResources - release resources allocated for adapter
492 * Description:
493 * This function releases the IRQ, unmaps the IO and
494 * frees the desriptor ring.
496 * Returns: N/A
499 static void FreeResources(struct net_device *dev)
501 SK_U32 AllocFlag;
502 SK_AC *pAC;
504 if (dev->priv) {
505 pAC = (SK_AC*) dev->priv;
506 AllocFlag = pAC->AllocFlag;
507 if (AllocFlag & SK_ALLOC_IRQ) {
508 free_irq(dev->irq, dev);
510 if (pAC->IoBase) {
511 iounmap(pAC->IoBase);
513 if (pAC->pDescrMem) {
514 BoardFreeMem(pAC);
518 } /* FreeResources */
521 MODULE_AUTHOR("Christoph Goos <cgoos@syskonnect.de>");
522 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
523 MODULE_PARM(AutoNeg_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
524 MODULE_PARM(AutoNeg_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
525 MODULE_PARM(DupCap_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
526 MODULE_PARM(DupCap_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
527 MODULE_PARM(FlowCtrl_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
528 MODULE_PARM(FlowCtrl_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
529 MODULE_PARM(Role_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
530 MODULE_PARM(Role_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
531 MODULE_PARM(PrefPort, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
532 MODULE_PARM(RlmtMode, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
533 /* not used, just there because every driver should have them: */
534 MODULE_PARM(options, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
535 MODULE_PARM(debug, "i");
538 #ifdef AUTO_NEG_A
539 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
540 #else
541 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
542 #endif
544 #ifdef DUP_CAP_A
545 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
546 #else
547 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
548 #endif
550 #ifdef FLOW_CTRL_A
551 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
552 #else
553 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
554 #endif
556 #ifdef ROLE_A
557 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
558 #else
559 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
560 #endif
562 #ifdef AUTO_NEG_B
563 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
564 #else
565 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
566 #endif
568 #ifdef DUP_CAP_B
569 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
570 #else
571 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
572 #endif
574 #ifdef FLOW_CTRL_B
575 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
576 #else
577 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
578 #endif
580 #ifdef ROLE_B
581 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
582 #else
583 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
584 #endif
586 #ifdef PREF_PORT
587 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
588 #else
589 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
590 #endif
592 #ifdef RLMT_MODE
593 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
594 #else
595 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
596 #endif
599 static int debug = 0; /* not used */
600 static int options[SK_MAX_CARD_PARAM] = {0, }; /* not used */
603 /*****************************************************************************
605 * skge_init_module - module initialization function
607 * Description:
608 * Very simple, only call skge_probe and return approriate result.
610 * Returns:
611 * 0, if everything is ok
612 * !=0, on error
614 static int __init skge_init_module(void)
616 int cards;
618 root_dev = NULL;
620 /* just to avoid warnings ... */
621 debug = 0;
622 options[0] = 0;
624 cards = skge_probe();
625 if (cards == 0) {
626 printk("No adapter found\n");
628 return cards ? 0 : -ENODEV;
629 } /* skge_init_module */
632 /*****************************************************************************
634 * skge_cleanup_module - module unload function
636 * Description:
637 * Disable adapter if it is still running, free resources,
638 * free device struct.
640 * Returns: N/A
642 static void __exit skge_cleanup_module(void)
644 SK_AC *pAC;
645 struct net_device *next;
646 unsigned long Flags;
647 SK_EVPARA EvPara;
649 while (root_dev) {
650 pAC = (SK_AC*)root_dev->priv;
651 next = pAC->Next;
653 netif_stop_queue(root_dev);
654 SkGeYellowLED(pAC, pAC->IoBase, 0);
656 if(pAC->BoardLevel == 2) {
657 /* board is still alive */
658 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
659 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
660 SkEventDispatcher(pAC, pAC->IoBase);
661 /* disable interrupts */
662 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
663 SkGeDeInit(pAC, pAC->IoBase);
664 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
665 pAC->BoardLevel = 0;
666 /* We do NOT check here, if IRQ was pending, of course*/
669 if(pAC->BoardLevel == 1) {
670 /* board is still alive */
671 SkGeDeInit(pAC, pAC->IoBase);
672 pAC->BoardLevel = 0;
675 FreeResources(root_dev);
677 root_dev->get_stats = NULL;
679 * otherwise unregister_netdev calls get_stats with
680 * invalid IO ... :-(
682 unregister_netdev(root_dev);
683 kfree(root_dev);
685 root_dev = next;
687 } /* skge_cleanup_module */
689 module_init(skge_init_module);
690 module_exit(skge_cleanup_module);
692 /*****************************************************************************
694 * SkGeBoardInit - do level 0 and 1 initialization
696 * Description:
697 * This function prepares the board hardware for running. The desriptor
698 * ring is set up, the IRQ is allocated and the configuration settings
699 * are examined.
701 * Returns:
702 * 0, if everything is ok
703 * !=0, on error
705 static int __init SkGeBoardInit(struct net_device *dev, SK_AC *pAC)
707 short i;
708 unsigned long Flags;
709 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
710 char *VerStr = VER_STRING;
711 int Ret; /* return code of request_irq */
713 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
714 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
715 for (i=0; i<SK_MAX_MACS; i++) {
716 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
717 pAC->TxPort[i][0].PortIndex = i;
718 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
719 pAC->RxPort[i].PortIndex = i;
722 /* Initialize the mutexes */
724 for (i=0; i<SK_MAX_MACS; i++) {
725 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
726 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
728 spin_lock_init(&pAC->SlowPathLock);
730 /* level 0 init common modules here */
732 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
733 /* Does a RESET on board ...*/
734 if (SkGeInit(pAC, pAC->IoBase, 0) != 0) {
735 printk("HWInit (0) failed.\n");
736 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
737 return(-EAGAIN);
739 SkI2cInit( pAC, pAC->IoBase, 0);
740 SkEventInit(pAC, pAC->IoBase, 0);
741 SkPnmiInit( pAC, pAC->IoBase, 0);
742 SkAddrInit( pAC, pAC->IoBase, 0);
743 SkRlmtInit( pAC, pAC->IoBase, 0);
744 SkTimerInit(pAC, pAC->IoBase, 0);
746 pAC->BoardLevel = 0;
747 pAC->RxBufSize = ETH_BUF_SIZE;
749 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
750 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
752 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
754 GetConfiguration(pAC);
756 /* level 1 init common modules here (HW init) */
757 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
758 if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {
759 printk("HWInit (1) failed.\n");
760 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
761 return(-EAGAIN);
763 SkI2cInit( pAC, pAC->IoBase, 1);
764 SkEventInit(pAC, pAC->IoBase, 1);
765 SkPnmiInit( pAC, pAC->IoBase, 1);
766 SkAddrInit( pAC, pAC->IoBase, 1);
767 SkRlmtInit( pAC, pAC->IoBase, 1);
768 SkTimerInit(pAC, pAC->IoBase, 1);
770 pAC->BoardLevel = 1;
771 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
773 if (pAC->GIni.GIMacsFound == 2) {
774 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
775 } else if (pAC->GIni.GIMacsFound == 1) {
776 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
777 pAC->Name, dev);
778 } else {
779 printk(KERN_WARNING "%s: illegal number of ports: %d\n",
780 dev->name, pAC->GIni.GIMacsFound);
781 return -EAGAIN;
783 if (Ret) {
784 printk(KERN_WARNING "%s: Requested IRQ %d is busy\n",
785 dev->name, dev->irq);
786 return -EAGAIN;
788 pAC->AllocFlag |= SK_ALLOC_IRQ;
790 /* Alloc memory for this board (Mem for RxD/TxD) : */
791 if(!BoardAllocMem(pAC)) {
792 printk("No memory for descriptor rings\n");
793 return(-EAGAIN);
796 SkCsSetReceiveFlags(pAC,
797 SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
798 &pAC->CsOfs1, &pAC->CsOfs2);
799 pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
801 BoardInitMem(pAC);
803 SetQueueSizes(pAC);
805 /* Print adapter specific string from vpd */
806 ProductStr(pAC);
807 printk("%s: %s\n", dev->name, pAC->DeviceStr);
809 SkGeYellowLED(pAC, pAC->IoBase, 1);
812 * Register the device here
814 pAC->Next = root_dev;
815 root_dev = dev;
817 return (0);
818 } /* SkGeBoardInit */
821 /*****************************************************************************
823 * BoardAllocMem - allocate the memory for the descriptor rings
825 * Description:
826 * This function allocates the memory for all descriptor rings.
827 * Each ring is aligned for the desriptor alignment and no ring
828 * has a 4 GByte boundary in it (because the upper 32 bit must
829 * be constant for all descriptiors in one rings).
831 * Returns:
832 * SK_TRUE, if all memory could be allocated
833 * SK_FALSE, if not
835 static SK_BOOL BoardAllocMem(
836 SK_AC *pAC)
838 caddr_t pDescrMem; /* pointer to descriptor memory area */
839 size_t AllocLength; /* length of complete descriptor area */
840 int i; /* loop counter */
841 unsigned long BusAddr;
844 /* rings plus one for alignment (do not cross 4 GB boundary) */
845 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
846 #if (BITS_PER_LONG == 32)
847 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
848 #else
849 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
850 + RX_RING_SIZE + 8;
851 #endif
852 pDescrMem = pci_alloc_consistent(&pAC->PciDev, AllocLength,
853 &pAC->pDescrMemDMA);
854 if (pDescrMem == NULL) {
855 return (SK_FALSE);
857 pAC->pDescrMem = pDescrMem;
859 /* Descriptors need 8 byte alignment, and this is ensured
860 * by pci_alloc_consistent.
862 BusAddr = (unsigned long) pAC->pDescrMemDMA;
863 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
864 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
865 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
866 i, (unsigned long) pDescrMem,
867 BusAddr));
868 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
869 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
870 pDescrMem += TX_RING_SIZE;
871 BusAddr += TX_RING_SIZE;
873 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
874 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
875 i, (unsigned long) pDescrMem,
876 (unsigned long)BusAddr));
877 pAC->RxPort[i].pRxDescrRing = pDescrMem;
878 pAC->RxPort[i].VRxDescrRing = BusAddr;
879 pDescrMem += RX_RING_SIZE;
880 BusAddr += RX_RING_SIZE;
881 } /* for */
883 return (SK_TRUE);
884 } /* BoardAllocMem */
887 /****************************************************************************
889 * BoardFreeMem - reverse of BoardAllocMem
891 * Description:
892 * Free all memory allocated in BoardAllocMem: adapter context,
893 * descriptor rings, locks.
895 * Returns: N/A
897 static void BoardFreeMem(
898 SK_AC *pAC)
900 size_t AllocLength; /* length of complete descriptor area */
902 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
903 ("BoardFreeMem\n"));
904 #if (BITS_PER_LONG == 32)
905 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
906 #else
907 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
908 + RX_RING_SIZE + 8;
909 #endif
910 pci_free_consistent(&pAC->PciDev, AllocLength,
911 pAC->pDescrMem, pAC->pDescrMemDMA);
912 pAC->pDescrMem = NULL;
913 } /* BoardFreeMem */
916 /*****************************************************************************
918 * BoardInitMem - initiate the descriptor rings
920 * Description:
921 * This function sets the descriptor rings up in memory.
922 * The adapter is initialized with the descriptor start addresses.
924 * Returns: N/A
926 static void BoardInitMem(
927 SK_AC *pAC) /* pointer to adapter context */
929 int i; /* loop counter */
930 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
931 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
933 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
934 ("BoardInitMem\n"));
936 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
937 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
938 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
939 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
941 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
942 SetupRing(
943 pAC,
944 pAC->TxPort[i][0].pTxDescrRing,
945 pAC->TxPort[i][0].VTxDescrRing,
946 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
947 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
948 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
949 &pAC->TxPort[i][0].TxdRingFree,
950 SK_TRUE);
951 SetupRing(
952 pAC,
953 pAC->RxPort[i].pRxDescrRing,
954 pAC->RxPort[i].VRxDescrRing,
955 &pAC->RxPort[i].pRxdRingHead,
956 &pAC->RxPort[i].pRxdRingTail,
957 &pAC->RxPort[i].pRxdRingPrev,
958 &pAC->RxPort[i].RxdRingFree,
959 SK_FALSE);
961 } /* BoardInitMem */
964 /*****************************************************************************
966 * SetupRing - create one descriptor ring
968 * Description:
969 * This function creates one descriptor ring in the given memory area.
970 * The head, tail and number of free descriptors in the ring are set.
972 * Returns:
973 * none
975 static void SetupRing(
976 SK_AC *pAC,
977 void *pMemArea, /* a pointer to the memory area for the ring */
978 uintptr_t VMemArea, /* the virtual bus address of the memory area */
979 RXD **ppRingHead, /* address where the head should be written */
980 RXD **ppRingTail, /* address where the tail should be written */
981 RXD **ppRingPrev, /* address where the tail should be written */
982 int *pRingFree, /* address where the # of free descr. goes */
983 SK_BOOL IsTx) /* flag: is this a tx ring */
985 int i; /* loop counter */
986 int DescrSize; /* the size of a descriptor rounded up to alignment*/
987 int DescrNum; /* number of descriptors per ring */
988 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
989 RXD *pNextDescr; /* pointer to the next descriptor */
990 RXD *pPrevDescr; /* pointer to the previous descriptor */
991 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
993 if (IsTx == SK_TRUE) {
994 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
995 DESCR_ALIGN;
996 DescrNum = TX_RING_SIZE / DescrSize;
998 else {
999 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
1000 DESCR_ALIGN;
1001 DescrNum = RX_RING_SIZE / DescrSize;
1004 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1005 ("Descriptor size: %d Descriptor Number: %d\n",
1006 DescrSize,DescrNum));
1008 pDescr = (RXD*) pMemArea;
1009 pPrevDescr = NULL;
1010 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1011 VNextDescr = VMemArea + DescrSize;
1012 for(i=0; i<DescrNum; i++) {
1013 /* set the pointers right */
1014 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
1015 pDescr->pNextRxd = pNextDescr;
1016 pDescr->TcpSumStarts = pAC->CsOfs;
1017 /* advance on step */
1018 pPrevDescr = pDescr;
1019 pDescr = pNextDescr;
1020 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1021 VNextDescr += DescrSize;
1023 pPrevDescr->pNextRxd = (RXD*) pMemArea;
1024 pPrevDescr->VNextRxd = VMemArea;
1025 pDescr = (RXD*) pMemArea;
1026 *ppRingHead = (RXD*) pMemArea;
1027 *ppRingTail = *ppRingHead;
1028 *ppRingPrev = pPrevDescr;
1029 *pRingFree = DescrNum;
1030 } /* SetupRing */
1033 /*****************************************************************************
1035 * PortReInitBmu - re-initiate the descriptor rings for one port
1037 * Description:
1038 * This function reinitializes the descriptor rings of one port
1039 * in memory. The port must be stopped before.
1040 * The HW is initialized with the descriptor start addresses.
1042 * Returns:
1043 * none
1045 static void PortReInitBmu(
1046 SK_AC *pAC, /* pointer to adapter context */
1047 int PortIndex) /* index of the port for which to re-init */
1049 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1050 ("PortReInitBmu "));
1052 /* set address of first descriptor of ring in BMU */
1053 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+
1054 TX_Q_CUR_DESCR_LOW,
1055 (uint32_t)(((caddr_t)
1056 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1057 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1058 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
1059 0xFFFFFFFF));
1060 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+
1061 TX_Q_DESCR_HIGH,
1062 (uint32_t)(((caddr_t)
1063 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1064 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1065 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
1066 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_CUR_DESCR_LOW,
1067 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1068 pAC->RxPort[PortIndex].pRxDescrRing +
1069 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
1070 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_DESCR_HIGH,
1071 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1072 pAC->RxPort[PortIndex].pRxDescrRing +
1073 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
1074 } /* PortReInitBmu */
1077 /****************************************************************************
1079 * SkGeIsr - handle adapter interrupts
1081 * Description:
1082 * The interrupt routine is called when the network adapter
1083 * generates an interrupt. It may also be called if another device
1084 * shares this interrupt vector with the driver.
1086 * Returns: N/A
1089 static void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
1091 struct net_device *dev = (struct net_device *)dev_id;
1092 SK_AC *pAC;
1093 SK_U32 IntSrc; /* interrupts source register contents */
1095 pAC = (SK_AC*) dev->priv;
1098 * Check and process if its our interrupt
1100 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1101 if (IntSrc == 0) {
1102 return;
1105 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1106 #if 0 /* software irq currently not used */
1107 if (IntSrc & IRQ_SW) {
1108 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1109 SK_DBGCAT_DRV_INT_SRC,
1110 ("Software IRQ\n"));
1112 #endif
1113 if (IntSrc & IRQ_EOF_RX1) {
1114 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1115 SK_DBGCAT_DRV_INT_SRC,
1116 ("EOF RX1 IRQ\n"));
1117 ReceiveIrq(pAC, &pAC->RxPort[0]);
1118 SK_PNMI_CNT_RX_INTR(pAC);
1120 if (IntSrc & IRQ_EOF_RX2) {
1121 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1122 SK_DBGCAT_DRV_INT_SRC,
1123 ("EOF RX2 IRQ\n"));
1124 ReceiveIrq(pAC, &pAC->RxPort[1]);
1125 SK_PNMI_CNT_RX_INTR(pAC);
1127 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1128 if (IntSrc & IRQ_EOF_AS_TX1) {
1129 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1130 SK_DBGCAT_DRV_INT_SRC,
1131 ("EOF AS TX1 IRQ\n"));
1132 SK_PNMI_CNT_TX_INTR(pAC);
1133 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1134 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1135 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1137 if (IntSrc & IRQ_EOF_AS_TX2) {
1138 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1139 SK_DBGCAT_DRV_INT_SRC,
1140 ("EOF AS TX2 IRQ\n"));
1141 SK_PNMI_CNT_TX_INTR(pAC);
1142 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1143 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
1144 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1146 #if 0 /* only if sync. queues used */
1147 if (IntSrc & IRQ_EOF_SY_TX1) {
1148 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1149 SK_DBGCAT_DRV_INT_SRC,
1150 ("EOF SY TX1 IRQ\n"));
1151 SK_PNMI_CNT_TX_INTR(pAC);
1152 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1153 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1154 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1155 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1157 if (IntSrc & IRQ_EOF_SY_TX2) {
1158 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1159 SK_DBGCAT_DRV_INT_SRC,
1160 ("EOF SY TX2 IRQ\n"));
1161 SK_PNMI_CNT_TX_INTR(pAC);
1162 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1163 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
1164 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1165 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
1167 #endif /* 0 */
1168 #endif /* USE_TX_COMPLETE */
1170 /* do all IO at once */
1171 if (IntSrc & IRQ_EOF_RX1)
1172 ClearAndStartRx(pAC, 0);
1173 if (IntSrc & IRQ_EOF_RX2)
1174 ClearAndStartRx(pAC, 1);
1175 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1176 if (IntSrc & IRQ_EOF_AS_TX1)
1177 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1178 if (IntSrc & IRQ_EOF_AS_TX2)
1179 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
1180 #endif
1181 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1182 } /* while (IntSrc & IRQ_MASK != 0) */
1184 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1185 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1186 ("SPECIAL IRQ\n"));
1187 pAC->CheckQueue = SK_FALSE;
1188 spin_lock(&pAC->SlowPathLock);
1189 if (IntSrc & SPECIAL_IRQS)
1190 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1191 SkEventDispatcher(pAC, pAC->IoBase);
1192 spin_unlock(&pAC->SlowPathLock);
1195 * do it all again is case we cleared an interrupt that
1196 * came in after handling the ring (OUTs may be delayed
1197 * in hardware buffers, but are through after IN)
1199 ReceiveIrq(pAC, &pAC->RxPort[pAC->ActivePort]);
1200 // ReceiveIrq(pAC, &pAC->RxPort[1]);
1202 #if 0
1203 // #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1204 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1205 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1206 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1208 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1209 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
1210 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1212 #if 0 /* only if sync. queues used */
1213 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1214 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1215 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1217 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1218 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
1219 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1220 #endif /* 0 */
1221 #endif /* USE_TX_COMPLETE */
1223 /* IRQ is processed - Enable IRQs again*/
1224 SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1226 return;
1227 } /* SkGeIsr */
1230 /****************************************************************************
1232 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1234 * Description:
1235 * The interrupt routine is called when the network adapter
1236 * generates an interrupt. It may also be called if another device
1237 * shares this interrupt vector with the driver.
1238 * This is the same as above, but handles only one port.
1240 * Returns: N/A
1243 static void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1245 struct net_device *dev = (struct net_device *)dev_id;
1246 SK_AC *pAC;
1247 SK_U32 IntSrc; /* interrupts source register contents */
1249 pAC = (SK_AC*) dev->priv;
1252 * Check and process if its our interrupt
1254 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1255 if (IntSrc == 0) {
1256 return;
1259 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1260 #if 0 /* software irq currently not used */
1261 if (IntSrc & IRQ_SW) {
1262 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1263 SK_DBGCAT_DRV_INT_SRC,
1264 ("Software IRQ\n"));
1266 #endif
1267 if (IntSrc & IRQ_EOF_RX1) {
1268 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1269 SK_DBGCAT_DRV_INT_SRC,
1270 ("EOF RX1 IRQ\n"));
1271 ReceiveIrq(pAC, &pAC->RxPort[0]);
1272 SK_PNMI_CNT_RX_INTR(pAC);
1274 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1275 if (IntSrc & IRQ_EOF_AS_TX1) {
1276 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1277 SK_DBGCAT_DRV_INT_SRC,
1278 ("EOF AS TX1 IRQ\n"));
1279 SK_PNMI_CNT_TX_INTR(pAC);
1280 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1281 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1282 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1284 #if 0 /* only if sync. queues used */
1285 if (IntSrc & IRQ_EOF_SY_TX1) {
1286 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1287 SK_DBGCAT_DRV_INT_SRC,
1288 ("EOF SY TX1 IRQ\n"));
1289 SK_PNMI_CNT_TX_INTR(pAC);
1290 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1291 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1292 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1293 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1295 #endif /* 0 */
1296 #endif /* USE_TX_COMPLETE */
1298 /* do all IO at once */
1299 if (IntSrc & IRQ_EOF_RX1)
1300 ClearAndStartRx(pAC, 0);
1301 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1302 if (IntSrc & IRQ_EOF_AS_TX1)
1303 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1304 #endif
1305 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1306 } /* while (IntSrc & IRQ_MASK != 0) */
1308 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1309 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1310 ("SPECIAL IRQ\n"));
1311 pAC->CheckQueue = SK_FALSE;
1312 spin_lock(&pAC->SlowPathLock);
1313 if (IntSrc & SPECIAL_IRQS)
1314 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1315 SkEventDispatcher(pAC, pAC->IoBase);
1316 spin_unlock(&pAC->SlowPathLock);
1319 * do it all again is case we cleared an interrupt that
1320 * came in after handling the ring (OUTs may be delayed
1321 * in hardware buffers, but are through after IN)
1323 ReceiveIrq(pAC, &pAC->RxPort[0]);
1325 #if 0
1326 // #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1327 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1328 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1329 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1331 #if 0 /* only if sync. queues used */
1332 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1333 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1334 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1336 #endif /* 0 */
1337 #endif /* USE_TX_COMPLETE */
1339 /* IRQ is processed - Enable IRQs again*/
1340 SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1342 return;
1343 } /* SkGeIsrOnePort */
1346 /****************************************************************************
1348 * SkGeOpen - handle start of initialized adapter
1350 * Description:
1351 * This function starts the initialized adapter.
1352 * The board level variable is set and the adapter is
1353 * brought to full functionality.
1354 * The device flags are set for operation.
1355 * Do all necessary level 2 initialization, enable interrupts and
1356 * give start command to RLMT.
1358 * Returns:
1359 * 0 on success
1360 * != 0 on error
1362 static int SkGeOpen(
1363 struct net_device *dev)
1365 SK_AC *pAC; /* pointer to adapter context struct */
1366 unsigned int Flags; /* for spin lock */
1367 int i;
1368 SK_EVPARA EvPara; /* an event parameter union */
1370 pAC = (SK_AC*) dev->priv;
1372 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1373 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1375 if (pAC->BoardLevel == 0) {
1376 /* level 1 init common modules here */
1377 if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {
1378 printk("%s: HWInit(1) failed\n", pAC->dev->name);
1379 return (-1);
1381 SkI2cInit (pAC, pAC->IoBase, 1);
1382 SkEventInit (pAC, pAC->IoBase, 1);
1383 SkPnmiInit (pAC, pAC->IoBase, 1);
1384 SkAddrInit (pAC, pAC->IoBase, 1);
1385 SkRlmtInit (pAC, pAC->IoBase, 1);
1386 SkTimerInit (pAC, pAC->IoBase, 1);
1387 pAC->BoardLevel = 1;
1390 /* level 2 init modules here */
1391 SkGeInit (pAC, pAC->IoBase, 2);
1392 SkI2cInit (pAC, pAC->IoBase, 2);
1393 SkEventInit (pAC, pAC->IoBase, 2);
1394 SkPnmiInit (pAC, pAC->IoBase, 2);
1395 SkAddrInit (pAC, pAC->IoBase, 2);
1396 SkRlmtInit (pAC, pAC->IoBase, 2);
1397 SkTimerInit (pAC, pAC->IoBase, 2);
1398 pAC->BoardLevel = 2;
1400 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1401 // Enable transmit descriptor polling.
1402 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1403 FillRxRing(pAC, &pAC->RxPort[i]);
1405 SkGeYellowLED(pAC, pAC->IoBase, 1);
1407 #ifdef USE_INT_MOD
1408 // moderate only TX complete interrupts (these are not time critical)
1409 #define IRQ_MOD_MASK (IRQ_EOF_AS_TX1 | IRQ_EOF_AS_TX2)
1411 unsigned long ModBase;
1412 ModBase = 53125000 / INTS_PER_SEC;
1413 SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
1414 SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);
1415 SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
1417 #endif
1419 /* enable Interrupts */
1420 SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1421 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1423 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1424 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1425 if (pAC->RlmtMode != 0) {
1426 EvPara.Para32[0] = pAC->RlmtMode;
1427 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1428 EvPara);
1430 SkEventDispatcher(pAC, pAC->IoBase);
1431 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1433 MOD_INC_USE_COUNT;
1435 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1436 ("SkGeOpen suceeded\n"));
1438 return (0);
1439 } /* SkGeOpen */
1442 /****************************************************************************
1444 * SkGeClose - Stop initialized adapter
1446 * Description:
1447 * Close initialized adapter.
1449 * Returns:
1450 * 0 - on success
1451 * error code - on error
1453 static int SkGeClose(
1454 struct net_device *dev)
1456 SK_AC *pAC;
1457 unsigned int Flags; /* for spin lock */
1458 int i;
1459 SK_EVPARA EvPara;
1461 netif_stop_queue(dev);
1463 pAC = (SK_AC*) dev->priv;
1465 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1466 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1469 * Clear multicast table, promiscuous mode ....
1471 SkAddrMcClear(pAC, pAC->IoBase, pAC->ActivePort, 0);
1472 SkAddrPromiscuousChange(pAC, pAC->IoBase, pAC->ActivePort,
1473 SK_PROM_MODE_NONE);
1476 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1477 /* disable interrupts */
1478 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1479 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1480 SkEventDispatcher(pAC, pAC->IoBase);
1481 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1482 /* stop the hardware */
1483 SkGeDeInit(pAC, pAC->IoBase);
1484 pAC->BoardLevel = 0;
1486 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1488 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1489 /* clear all descriptor rings */
1490 ReceiveIrq(pAC, &pAC->RxPort[i]);
1491 ClearRxRing(pAC, &pAC->RxPort[i]);
1492 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1495 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1496 ("SkGeClose: done "));
1498 MOD_DEC_USE_COUNT;
1500 return (0);
1501 } /* SkGeClose */
1503 /*****************************************************************************
1505 * SkGeXmit - Linux frame transmit function
1507 * Description:
1508 * The system calls this function to send frames onto the wire.
1509 * It puts the frame in the tx descriptor ring. If the ring is
1510 * full then, the 'tbusy' flag is set.
1512 * Returns:
1513 * 0, if everything is ok
1514 * !=0, on error
1515 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1516 * allocated skb's) !!!
1518 static int SkGeXmit(struct sk_buff *skb, struct net_device *dev)
1520 SK_AC *pAC;
1521 int Rc; /* return code of XmitFrame */
1523 pAC = (SK_AC*) dev->priv;
1525 Rc = XmitFrame(pAC, &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW], skb);
1527 /* Transmitter out of resources? */
1528 if (Rc <= 0)
1529 netif_stop_queue(dev);
1531 /* If not taken, give buffer ownership back to the
1532 * queueing layer.
1534 if (Rc < 0)
1535 return (1);
1537 dev->trans_start = jiffies;
1538 return (0);
1539 } /* SkGeXmit */
1542 /*****************************************************************************
1544 * XmitFrame - fill one socket buffer into the transmit ring
1546 * Description:
1547 * This function puts a message into the transmit descriptor ring
1548 * if there is a descriptors left.
1549 * Linux skb's consist of only one continuous buffer.
1550 * The first step locks the ring. It is held locked
1551 * all time to avoid problems with SWITCH_../PORT_RESET.
1552 * Then the descriptoris allocated.
1553 * The second part is linking the buffer to the descriptor.
1554 * At the very last, the Control field of the descriptor
1555 * is made valid for the BMU and a start TX command is given
1556 * if necessary.
1558 * Returns:
1559 * > 0 - on succes: the number of bytes in the message
1560 * = 0 - on resource shortage: this frame sent or dropped, now
1561 * the ring is full ( -> set tbusy)
1562 * < 0 - on failure: other problems ( -> return failure to upper layers)
1564 static int XmitFrame(
1565 SK_AC *pAC, /* pointer to adapter context */
1566 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1567 struct sk_buff *pMessage) /* pointer to send-message */
1569 TXD *pTxd; /* the rxd to fill */
1570 unsigned int Flags;
1571 SK_U64 PhysAddr;
1572 int BytesSend;
1574 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1575 ("X"));
1577 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1579 if (pTxPort->TxdRingFree == 0) {
1580 /* no enough free descriptors in ring at the moment */
1581 FreeTxDescriptors(pAC, pTxPort);
1582 if (pTxPort->TxdRingFree == 0) {
1583 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1584 SK_PNMI_CNT_NO_TX_BUF(pAC);
1585 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1586 SK_DBGCAT_DRV_TX_PROGRESS,
1587 ("XmitFrame failed\n"));
1588 /* this message can not be sent now */
1589 return (-1);
1592 /* advance head counter behind descriptor needed for this frame */
1593 pTxd = pTxPort->pTxdRingHead;
1594 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1595 pTxPort->TxdRingFree--;
1596 /* the needed descriptor is reserved now */
1599 * everything allocated ok, so add buffer to descriptor
1602 #ifdef SK_DUMP_TX
1603 DumpMsg(pMessage, "XmitFrame");
1604 #endif
1606 /* set up descriptor and CONTROL dword */
1607 PhysAddr = (SK_U64) pci_map_single(&pAC->PciDev,
1608 pMessage->data,
1609 pMessage->len);
1610 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1611 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1612 pTxd->pMBuf = pMessage;
1613 pTxd->TBControl = TX_CTRL_OWN_BMU | TX_CTRL_STF |
1614 TX_CTRL_CHECK_DEFAULT | TX_CTRL_SOFTWARE |
1615 #ifdef USE_TX_COMPLETE
1616 TX_CTRL_EOF | TX_CTRL_EOF_IRQ | pMessage->len;
1617 #else
1618 TX_CTRL_EOF | pMessage->len;
1619 #endif
1621 if ((pTxPort->pTxdRingPrev->TBControl & TX_CTRL_OWN_BMU) == 0) {
1622 /* previous descriptor already done, so give tx start cmd */
1623 /* StartTx(pAC, pTxPort->HwAddr); */
1624 SK_OUT8(pTxPort->HwAddr, TX_Q_CTRL, TX_Q_CTRL_START);
1626 pTxPort->pTxdRingPrev = pTxd;
1629 BytesSend = pMessage->len;
1630 /* after releasing the lock, the skb may be immidiately freed */
1631 if (pTxPort->TxdRingFree != 0) {
1632 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1633 return (BytesSend);
1635 else {
1636 /* ring full: set tbusy on return */
1637 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1638 return (0);
1640 } /* XmitFrame */
1643 /*****************************************************************************
1645 * FreeTxDescriptors - release descriptors from the descriptor ring
1647 * Description:
1648 * This function releases descriptors from a transmit ring if they
1649 * have been sent by the BMU.
1650 * If a descriptors is sent, it can be freed and the message can
1651 * be freed, too.
1652 * The SOFTWARE controllable bit is used to prevent running around a
1653 * completely free ring for ever. If this bit is no set in the
1654 * frame (by XmitFrame), this frame has never been sent or is
1655 * already freed.
1656 * The Tx descriptor ring lock must be held while calling this function !!!
1658 * Returns:
1659 * none
1661 static void FreeTxDescriptors(
1662 SK_AC *pAC, /* pointer to the adapter context */
1663 TX_PORT *pTxPort) /* pointer to destination port structure */
1665 TXD *pTxd; /* pointer to the checked descriptor */
1666 TXD *pNewTail; /* pointer to 'end' of the ring */
1667 SK_U32 Control; /* TBControl field of descriptor */
1668 SK_U64 PhysAddr; /* address of DMA mapping */
1670 pNewTail = pTxPort->pTxdRingTail;
1671 pTxd = pNewTail;
1674 * loop forever; exits if TX_CTRL_SOFTWARE bit not set in start frame
1675 * or TX_CTRL_OWN_BMU bit set in any frame
1677 while (1) {
1678 Control = pTxd->TBControl;
1679 if ((Control & TX_CTRL_SOFTWARE) == 0) {
1681 * software controllable bit is set in first
1682 * fragment when given to BMU. Not set means that
1683 * this fragment was never sent or is already
1684 * freed ( -> ring completely free now).
1686 pTxPort->pTxdRingTail = pTxd;
1687 netif_start_queue(pAC->dev);
1688 return;
1690 if (Control & TX_CTRL_OWN_BMU) {
1691 pTxPort->pTxdRingTail = pTxd;
1692 if (pTxPort->TxdRingFree > 0) {
1693 netif_start_queue(pAC->dev);
1695 return;
1698 /* release the DMA mapping */
1699 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1700 PhysAddr |= (SK_U64) pTxd->VDataLow;
1701 pci_unmap_single(&pAC->PciDev, PhysAddr,
1702 pTxd->pMBuf->len);
1704 /* free message */
1705 DEV_KFREE_SKB_ANY(pTxd->pMBuf);
1706 pTxPort->TxdRingFree++;
1707 pTxd->TBControl &= ~TX_CTRL_SOFTWARE;
1708 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1709 } /* while(forever) */
1710 } /* FreeTxDescriptors */
1713 /*****************************************************************************
1715 * FillRxRing - fill the receive ring with valid descriptors
1717 * Description:
1718 * This function fills the receive ring descriptors with data
1719 * segments and makes them valid for the BMU.
1720 * The active ring is filled completely, if possible.
1721 * The non-active ring is filled only partial to save memory.
1723 * Description of rx ring structure:
1724 * head - points to the descriptor which will be used next by the BMU
1725 * tail - points to the next descriptor to give to the BMU
1727 * Returns: N/A
1729 static void FillRxRing(
1730 SK_AC *pAC, /* pointer to the adapter context */
1731 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1732 should be filled */
1734 unsigned int Flags;
1736 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1737 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1738 if(!FillRxDescriptor(pAC, pRxPort))
1739 break;
1741 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1742 } /* FillRxRing */
1745 /*****************************************************************************
1747 * FillRxDescriptor - fill one buffer into the receive ring
1749 * Description:
1750 * The function allocates a new receive buffer and
1751 * puts it into the next descriptor.
1753 * Returns:
1754 * SK_TRUE - a buffer was added to the ring
1755 * SK_FALSE - a buffer could not be added
1757 static SK_BOOL FillRxDescriptor(
1758 SK_AC *pAC, /* pointer to the adapter context struct */
1759 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1761 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1762 RXD *pRxd; /* the rxd to fill */
1763 SK_U16 Length; /* data fragment length */
1764 SK_U64 PhysAddr; /* physical address of a rx buffer */
1766 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1767 if (pMsgBlock == NULL) {
1768 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1769 SK_DBGCAT_DRV_ENTRY,
1770 ("%s: Allocation of rx buffer failed !\n",
1771 pAC->dev->name));
1772 SK_PNMI_CNT_NO_RX_BUF(pAC);
1773 return(SK_FALSE);
1775 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1776 /* skb allocated ok, so add buffer */
1777 pRxd = pRxPort->pRxdRingTail;
1778 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1779 pRxPort->RxdRingFree--;
1780 Length = pAC->RxBufSize;
1781 PhysAddr = (SK_U64) pci_map_single(&pAC->PciDev,
1782 pMsgBlock->data,
1783 pAC->RxBufSize - 2);
1784 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1785 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1786 pRxd->pMBuf = pMsgBlock;
1787 pRxd->RBControl = RX_CTRL_OWN_BMU | RX_CTRL_STF |
1788 RX_CTRL_EOF_IRQ | RX_CTRL_CHECK_CSUM | Length;
1789 return (SK_TRUE);
1791 } /* FillRxDescriptor */
1794 /*****************************************************************************
1796 * ReQueueRxBuffer - fill one buffer back into the receive ring
1798 * Description:
1799 * Fill a given buffer back into the rx ring. The buffer
1800 * has been previously allocated and aligned, and its phys.
1801 * address calculated, so this is no more necessary.
1803 * Returns: N/A
1805 static void ReQueueRxBuffer(
1806 SK_AC *pAC, /* pointer to the adapter context struct */
1807 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1808 struct sk_buff *pMsg, /* pointer to the buffer */
1809 SK_U32 PhysHigh, /* phys address high dword */
1810 SK_U32 PhysLow) /* phys address low dword */
1812 RXD *pRxd; /* the rxd to fill */
1813 SK_U16 Length; /* data fragment length */
1815 pRxd = pRxPort->pRxdRingTail;
1816 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1817 pRxPort->RxdRingFree--;
1818 Length = pAC->RxBufSize;
1819 pRxd->VDataLow = PhysLow;
1820 pRxd->VDataHigh = PhysHigh;
1821 pRxd->pMBuf = pMsg;
1822 pRxd->RBControl = RX_CTRL_OWN_BMU | RX_CTRL_STF |
1823 RX_CTRL_EOF_IRQ | RX_CTRL_CHECK_CSUM | Length;
1824 return;
1825 } /* ReQueueRxBuffer */
1828 /*****************************************************************************
1830 * ReceiveIrq - handle a receive IRQ
1832 * Description:
1833 * This function is called when a receive IRQ is set.
1834 * It walks the receive descriptor ring and sends up all
1835 * frames that are complete.
1837 * Returns: N/A
1839 static void ReceiveIrq(
1840 SK_AC *pAC, /* pointer to adapter context */
1841 RX_PORT *pRxPort) /* pointer to receive port struct */
1843 RXD *pRxd; /* pointer to receive descriptors */
1844 SK_U32 Control; /* control field of descriptor */
1845 struct sk_buff *pMsg; /* pointer to message holding frame */
1846 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
1847 int FrameLength; /* total length of received frame */
1848 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
1849 SK_EVPARA EvPara; /* an event parameter union */
1850 int PortIndex = pRxPort->PortIndex;
1851 unsigned int Offset;
1852 unsigned int NumBytes;
1853 unsigned int ForRlmt;
1854 SK_BOOL IsBc;
1855 SK_BOOL IsMc;
1856 SK_U32 FrameStat;
1857 unsigned short Csum1;
1858 unsigned short Csum2;
1859 unsigned short Type;
1860 int Result;
1861 SK_U64 PhysAddr;
1864 rx_start:
1865 /* do forever; exit if RX_CTRL_OWN_BMU found */
1866 while (pRxPort->RxdRingFree < pAC->RxDescrPerRing) {
1867 pRxd = pRxPort->pRxdRingHead;
1869 Control = pRxd->RBControl;
1871 /* check if this descriptor is ready */
1872 if ((Control & RX_CTRL_OWN_BMU) != 0) {
1873 /* this descriptor is not yet ready */
1874 FillRxRing(pAC, pRxPort);
1875 return;
1878 /* get length of frame and check it */
1879 FrameLength = Control & RX_CTRL_LEN_MASK;
1880 if (FrameLength > pAC->RxBufSize)
1881 goto rx_failed;
1883 /* check for STF and EOF */
1884 if ((Control & (RX_CTRL_STF | RX_CTRL_EOF)) !=
1885 (RX_CTRL_STF | RX_CTRL_EOF))
1886 goto rx_failed;
1888 /* here we have a complete frame in the ring */
1889 pMsg = pRxd->pMBuf;
1892 * if short frame then copy data to reduce memory waste
1894 pNewMsg = NULL;
1895 if (FrameLength < SK_COPY_THRESHOLD) {
1896 pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC);
1897 if (pNewMsg != NULL) {
1898 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
1899 PhysAddr |= (SK_U64) pRxd->VDataLow;
1901 /* use new skb and copy data */
1902 skb_reserve(pNewMsg, 2);
1903 skb_put(pNewMsg, FrameLength);
1904 pci_dma_sync_single(&pAC->PciDev,
1905 (dma_addr_t) PhysAddr,
1906 FrameLength);
1907 eth_copy_and_sum(pNewMsg, pMsg->data,
1908 FrameLength, 0);
1909 ReQueueRxBuffer(pAC, pRxPort, pMsg,
1910 pRxd->VDataHigh, pRxd->VDataLow);
1911 pMsg = pNewMsg;
1916 * if large frame, or SKB allocation failed, pass
1917 * the SKB directly to the networking
1919 if (pNewMsg == NULL) {
1920 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
1921 PhysAddr |= (SK_U64) pRxd->VDataLow;
1923 /* release the DMA mapping */
1924 pci_unmap_single(&pAC->PciDev,
1925 PhysAddr,
1926 pAC->RxBufSize - 2);
1928 /* set length in message */
1929 skb_put(pMsg, FrameLength);
1930 /* hardware checksum */
1931 Type = ntohs(*((short*)&pMsg->data[12]));
1932 if (Type == 0x800) {
1933 Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
1934 Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
1935 if ((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) {
1936 Result = SkCsGetReceiveInfo(pAC,
1937 &pMsg->data[14],
1938 Csum1, Csum2);
1939 if (Result ==
1940 SKCS_STATUS_IP_FRAGMENT ||
1941 Result ==
1942 SKCS_STATUS_IP_CSUM_OK ||
1943 Result ==
1944 SKCS_STATUS_TCP_CSUM_OK ||
1945 Result ==
1946 SKCS_STATUS_UDP_CSUM_OK) {
1947 pMsg->ip_summed =
1948 CHECKSUM_UNNECESSARY;
1950 } /* checksum calculation valid */
1951 } /* IP frame */
1952 } /* frame > SK_COPY_TRESHOLD */
1954 FrameStat = pRxd->FrameStat;
1955 pRxd = pRxd->pNextRxd;
1956 pRxPort->pRxdRingHead = pRxd;
1957 pRxPort->RxdRingFree ++;
1958 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_RX_PROGRESS,
1959 ("Received frame of length %d on port %d\n",
1960 FrameLength, PortIndex));
1961 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_RX_PROGRESS,
1962 ("Number of free rx descriptors: %d\n",
1963 pRxPort->RxdRingFree));
1965 if ((Control & RX_CTRL_STAT_VALID) == RX_CTRL_STAT_VALID &&
1966 (FrameStat &
1967 (XMR_FS_ANY_ERR | XMR_FS_1L_VLAN | XMR_FS_2L_VLAN))
1968 == 0) {
1969 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1970 SK_DBGCAT_DRV_RX_PROGRESS,("V"));
1971 ForRlmt = SK_RLMT_RX_PROTOCOL;
1972 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
1973 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
1974 IsBc, &Offset, &NumBytes);
1975 if (NumBytes != 0) {
1976 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
1977 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
1978 &pMsg->data[Offset],
1979 IsBc, IsMc, &ForRlmt);
1981 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
1982 /* send up only frames from active port */
1983 if (PortIndex == pAC->ActivePort) {
1984 /* frame for upper layer */
1985 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1986 SK_DBGCAT_DRV_RX_PROGRESS,
1987 ("U"));
1988 #ifdef DUMP_RX
1989 DumpMsg(pMsg, "Rx");
1990 #endif
1991 pMsg->dev = pAC->dev;
1992 pMsg->protocol = eth_type_trans(pMsg,
1993 pAC->dev);
1994 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
1995 FrameLength);
1996 netif_rx(pMsg);
1997 pAC->dev->last_rx = jiffies;
1999 else {
2000 /* drop frame */
2001 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2002 SK_DBGCAT_DRV_RX_PROGRESS,
2003 ("D"));
2004 DEV_KFREE_SKB_IRQ(pMsg);
2006 } /* if not for rlmt */
2007 else {
2008 /* packet for rlmt */
2009 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2010 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2011 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2012 pAC->IoBase, FrameLength);
2013 if (pRlmtMbuf != NULL) {
2014 pRlmtMbuf->pNext = NULL;
2015 pRlmtMbuf->Length = FrameLength;
2016 pRlmtMbuf->PortIdx = PortIndex;
2017 EvPara.pParaPtr = pRlmtMbuf;
2018 memcpy((char*)(pRlmtMbuf->pData),
2019 (char*)(pMsg->data),
2020 FrameLength);
2021 SkEventQueue(pAC, SKGE_RLMT,
2022 SK_RLMT_PACKET_RECEIVED,
2023 EvPara);
2024 pAC->CheckQueue = SK_TRUE;
2025 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2026 SK_DBGCAT_DRV_RX_PROGRESS,
2027 ("Q"));
2029 if ((pAC->dev->flags &
2030 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2031 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2032 SK_RLMT_RX_PROTOCOL) {
2033 pMsg->dev = pAC->dev;
2034 pMsg->protocol = eth_type_trans(pMsg,
2035 pAC->dev);
2036 netif_rx(pMsg);
2037 pAC->dev->last_rx = jiffies;
2039 else {
2040 DEV_KFREE_SKB_IRQ(pMsg);
2043 } /* if packet for rlmt */
2044 } /* if valid frame */
2045 else {
2046 /* there is a receive error in this frame */
2047 if ((FrameStat & XMR_FS_1L_VLAN) != 0) {
2048 printk("%s: Received frame"
2049 " with VLAN Level 1 header, check"
2050 " switch configuration\n",
2051 pAC->dev->name);
2053 if ((FrameStat & XMR_FS_2L_VLAN) != 0) {
2054 printk("%s: Received frame"
2055 " with VLAN Level 2 header, check"
2056 " switch configuration\n",
2057 pAC->dev->name);
2059 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2060 SK_DBGCAT_DRV_RX_PROGRESS,
2061 ("skge: Error in received frame, dropped!\n"
2062 "Control: %x\nRxStat: %x\n",
2063 Control, FrameStat));
2064 DEV_KFREE_SKB_IRQ(pMsg);
2066 } /* while */
2067 FillRxRing(pAC, pRxPort);
2068 /* do not start if called from Close */
2069 if (pAC->BoardLevel > 0) {
2070 ClearAndStartRx(pAC, PortIndex);
2072 return;
2074 rx_failed:
2075 /* remove error frame */
2076 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2077 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2079 /* release the DMA mapping */
2080 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2081 PhysAddr |= (SK_U64) pRxd->VDataLow;
2082 pci_unmap_single(&pAC->PciDev,
2083 PhysAddr,
2084 pAC->RxBufSize - 2);
2085 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2086 pRxd->pMBuf = NULL;
2087 pRxPort->RxdRingFree++;
2088 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2089 goto rx_start;
2091 } /* ReceiveIrq */
2094 /*****************************************************************************
2096 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2098 * Description:
2099 * This function sends a start command and a clear interrupt
2100 * command for one receive queue to the BMU.
2102 * Returns: N/A
2103 * none
2105 static void ClearAndStartRx(
2106 SK_AC *pAC, /* pointer to the adapter context */
2107 int PortIndex) /* index of the receive port (XMAC) */
2109 SK_OUT8(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_CTRL,
2110 RX_Q_CTRL_START | RX_Q_CTRL_CLR_I_EOF);
2111 } /* ClearAndStartRx */
2114 /*****************************************************************************
2116 * ClearTxIrq - give a clear transmit IRQ command to BMU
2118 * Description:
2119 * This function sends a clear tx IRQ command for one
2120 * transmit queue to the BMU.
2122 * Returns: N/A
2124 static void ClearTxIrq(
2125 SK_AC *pAC, /* pointer to the adapter context */
2126 int PortIndex, /* index of the transmit port (XMAC) */
2127 int Prio) /* priority or normal queue */
2129 SK_OUT8(pAC->IoBase, TxQueueAddr[PortIndex][Prio]+TX_Q_CTRL,
2130 TX_Q_CTRL_CLR_I_EOF);
2131 } /* ClearTxIrq */
2134 /*****************************************************************************
2136 * ClearRxRing - remove all buffers from the receive ring
2138 * Description:
2139 * This function removes all receive buffers from the ring.
2140 * The receive BMU must be stopped before calling this function.
2142 * Returns: N/A
2144 static void ClearRxRing(
2145 SK_AC *pAC, /* pointer to adapter context */
2146 RX_PORT *pRxPort) /* pointer to rx port struct */
2148 RXD *pRxd; /* pointer to the current descriptor */
2149 unsigned int Flags;
2150 SK_U64 PhysAddr;
2152 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2153 return;
2155 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2156 pRxd = pRxPort->pRxdRingHead;
2157 do {
2158 if (pRxd->pMBuf != NULL) {
2159 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2160 PhysAddr |= (SK_U64) pRxd->VDataLow;
2161 pci_unmap_single(&pAC->PciDev,
2162 PhysAddr,
2163 pAC->RxBufSize - 2);
2164 DEV_KFREE_SKB(pRxd->pMBuf);
2165 pRxd->pMBuf = NULL;
2167 pRxd->RBControl &= RX_CTRL_OWN_BMU;
2168 pRxd = pRxd->pNextRxd;
2169 pRxPort->RxdRingFree++;
2170 } while (pRxd != pRxPort->pRxdRingTail);
2171 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2172 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2173 } /* ClearRxRing */
2176 /*****************************************************************************
2178 * ClearTxRing - remove all buffers from the transmit ring
2180 * Description:
2181 * This function removes all transmit buffers from the ring.
2182 * The transmit BMU must be stopped before calling this function
2183 * and transmitting at the upper level must be disabled.
2184 * The BMU own bit of all descriptors is cleared, the rest is
2185 * done by calling FreeTxDescriptors.
2187 * Returns: N/A
2189 static void ClearTxRing(
2190 SK_AC *pAC, /* pointer to adapter context */
2191 TX_PORT *pTxPort) /* pointer to tx prt struct */
2193 TXD *pTxd; /* pointer to the current descriptor */
2194 int i;
2195 unsigned int Flags;
2197 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2198 pTxd = pTxPort->pTxdRingHead;
2199 for (i=0; i<pAC->TxDescrPerRing; i++) {
2200 pTxd->TBControl &= ~TX_CTRL_OWN_BMU;
2201 pTxd = pTxd->pNextTxd;
2203 FreeTxDescriptors(pAC, pTxPort);
2204 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2205 } /* ClearTxRing */
2208 /*****************************************************************************
2210 * SetQueueSizes - configure the sizes of rx and tx queues
2212 * Description:
2213 * This function assigns the sizes for active and passive port
2214 * to the appropriate HWinit structure variables.
2215 * The passive port(s) get standard values, all remaining RAM
2216 * is given to the active port.
2217 * The queue sizes are in kbyte and must be multiple of 8.
2218 * The limits for the number of buffers filled into the rx rings
2219 * is also set in this routine.
2221 * Returns:
2222 * none
2224 static void SetQueueSizes(
2225 SK_AC *pAC) /* pointer to the adapter context */
2227 int StandbyRam; /* adapter RAM used for a standby port */
2228 int RemainingRam; /* adapter RAM available for the active port */
2229 int RxRam; /* RAM used for the active port receive queue */
2230 int i; /* loop counter */
2232 StandbyRam = SK_RLMT_STANDBY_QRXSIZE + SK_RLMT_STANDBY_QXASIZE +
2233 SK_RLMT_STANDBY_QXSSIZE;
2234 RemainingRam = pAC->GIni.GIRamSize -
2235 (pAC->GIni.GIMacsFound-1) * StandbyRam;
2236 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2237 pAC->GIni.GP[i].PRxQSize = SK_RLMT_STANDBY_QRXSIZE;
2238 pAC->GIni.GP[i].PXSQSize = SK_RLMT_STANDBY_QXSSIZE;
2239 pAC->GIni.GP[i].PXAQSize = SK_RLMT_STANDBY_QXASIZE;
2241 RxRam = (RemainingRam * 8 / 10) & ~7;
2242 pAC->GIni.GP[pAC->ActivePort].PRxQSize = RxRam;
2243 pAC->GIni.GP[pAC->ActivePort].PXSQSize = 0;
2244 pAC->GIni.GP[pAC->ActivePort].PXAQSize =
2245 (RemainingRam - RxRam) & ~7;
2246 pAC->RxQueueSize = RxRam;
2247 pAC->TxSQueueSize = 0;
2248 pAC->TxAQueueSize = (RemainingRam - RxRam) & ~7;
2249 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2250 ("queue sizes settings - rx:%d txA:%d txS:%d\n",
2251 pAC->RxQueueSize,pAC->TxAQueueSize, pAC->TxSQueueSize));
2253 for (i=0; i<SK_MAX_MACS; i++) {
2254 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing;
2256 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2257 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 100;
2260 * Do not set the Limit to 0, because this could cause
2261 * wrap around with ReQueue'ed buffers (a buffer could
2262 * be requeued in the same position, made accessable to
2263 * the hardware, and the hardware could change its
2264 * contents!
2266 pAC->RxPort[pAC->ActivePort].RxFillLimit = 1;
2268 #ifdef DEBUG
2269 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2270 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
2271 ("i: %d, RxQSize: %d, PXSQsize: %d, PXAQSize: %d\n",
2273 pAC->GIni.GP[i].PRxQSize,
2274 pAC->GIni.GP[i].PXSQSize,
2275 pAC->GIni.GP[i].PXAQSize));
2277 #endif
2278 } /* SetQueueSizes */
2281 /*****************************************************************************
2283 * SkGeSetMacAddr - Set the hardware MAC address
2285 * Description:
2286 * This function sets the MAC address used by the adapter.
2288 * Returns:
2289 * 0, if everything is ok
2290 * !=0, on error
2292 static int SkGeSetMacAddr(struct net_device *dev, void *p)
2294 SK_AC *pAC = (SK_AC*) dev->priv;
2295 struct sockaddr *addr = p;
2296 unsigned int Flags;
2298 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2299 ("SkGeSetMacAddr starts now...\n"));
2300 if(netif_running(dev)) {
2301 return -EBUSY;
2303 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2305 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2306 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2307 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2309 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2310 return 0;
2311 } /* SkGeSetMacAddr */
2314 /*****************************************************************************
2316 * SkGeSetRxMode - set receive mode
2318 * Description:
2319 * This function sets the receive mode of an adapter. The adapter
2320 * supports promiscuous mode, allmulticast mode and a number of
2321 * multicast addresses. If more multicast addresses the available
2322 * are selected, a hash function in the hardware is used.
2324 * Returns:
2325 * 0, if everything is ok
2326 * !=0, on error
2328 static void SkGeSetRxMode(struct net_device *dev)
2330 SK_AC *pAC;
2331 struct dev_mc_list *pMcList;
2332 int i;
2333 unsigned int Flags;
2335 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2336 ("SkGeSetRxMode starts now... "));
2337 pAC = (SK_AC*) dev->priv;
2339 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2340 if (dev->flags & IFF_PROMISC) {
2341 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2342 ("PROMISCUOUS mode\n"));
2343 SkAddrPromiscuousChange(pAC, pAC->IoBase, pAC->ActivePort,
2344 SK_PROM_MODE_LLC);
2345 } else if (dev->flags & IFF_ALLMULTI) {
2346 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2347 ("ALLMULTI mode\n"));
2348 SkAddrPromiscuousChange(pAC, pAC->IoBase, pAC->ActivePort,
2349 SK_PROM_MODE_ALL_MC);
2350 } else {
2351 SkAddrPromiscuousChange(pAC, pAC->IoBase, pAC->ActivePort,
2352 SK_PROM_MODE_NONE);
2353 SkAddrMcClear(pAC, pAC->IoBase, pAC->ActivePort, 0);
2355 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2356 ("Number of MC entries: %d ", dev->mc_count));
2358 pMcList = dev->mc_list;
2359 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2360 SkAddrMcAdd(pAC, pAC->IoBase, pAC->ActivePort,
2361 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2362 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2363 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2364 pMcList->dmi_addr[0],
2365 pMcList->dmi_addr[1],
2366 pMcList->dmi_addr[2],
2367 pMcList->dmi_addr[3],
2368 pMcList->dmi_addr[4],
2369 pMcList->dmi_addr[5]));
2371 SkAddrMcUpdate(pAC, pAC->IoBase, pAC->ActivePort);
2374 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2376 return;
2377 } /* SkGeSetRxMode */
2380 /*****************************************************************************
2382 * SkGeChangeMtu - set the MTU to another value
2384 * Description:
2385 * This function sets is called whenever the MTU size is changed
2386 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2387 * ethernet MTU size, long frame support is activated.
2389 * Returns:
2390 * 0, if everything is ok
2391 * !=0, on error
2393 static int SkGeChangeMtu(struct net_device *dev, int NewMtu)
2395 SK_AC *pAC;
2396 unsigned int Flags;
2397 int i;
2398 SK_EVPARA EvPara;
2400 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2401 ("SkGeChangeMtu starts now...\n"));
2403 pAC = (SK_AC*) dev->priv;
2404 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2405 return -EINVAL;
2408 pAC->RxBufSize = NewMtu + 32;
2409 dev->mtu = NewMtu;
2411 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2412 ("New MTU: %d\n", NewMtu));
2414 /* prevent reconfiguration while changing the MTU */
2416 /* disable interrupts */
2417 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2418 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2419 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2420 SkEventDispatcher(pAC, pAC->IoBase);
2422 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2423 spin_lock_irqsave(
2424 &pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock, Flags);
2426 netif_stop_queue(pAC->dev);
2429 * adjust number of rx buffers allocated
2431 if (NewMtu > 1500) {
2432 /* use less rx buffers */
2433 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2434 if (i == pAC->ActivePort)
2435 pAC->RxPort[i].RxFillLimit =
2436 pAC->RxDescrPerRing - 100;
2437 else
2438 pAC->RxPort[i].RxFillLimit =
2439 pAC->RxDescrPerRing - 10;
2443 else {
2444 /* use normal anoumt of rx buffers */
2445 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2446 if (i == pAC->ActivePort)
2447 pAC->RxPort[i].RxFillLimit = 1;
2448 else
2449 pAC->RxPort[i].RxFillLimit =
2450 pAC->RxDescrPerRing - 100;
2454 SkGeDeInit(pAC, pAC->IoBase);
2457 * enable/disable hardware support for long frames
2459 if (NewMtu > 1500) {
2460 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2461 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2462 pAC->GIni.GP[i].PRxCmd =
2463 XM_RX_STRIP_FCS | XM_RX_LENERR_OK;
2466 else {
2467 pAC->GIni.GIPortUsage = SK_RED_LINK;
2468 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2469 pAC->GIni.GP[i].PRxCmd =
2470 XM_RX_STRIP_FCS | XM_RX_LENERR_OK;
2474 SkGeInit( pAC, pAC->IoBase, 1);
2475 SkI2cInit( pAC, pAC->IoBase, 1);
2476 SkEventInit(pAC, pAC->IoBase, 1);
2477 SkPnmiInit( pAC, pAC->IoBase, 1);
2478 SkAddrInit( pAC, pAC->IoBase, 1);
2479 SkRlmtInit( pAC, pAC->IoBase, 1);
2480 SkTimerInit(pAC, pAC->IoBase, 1);
2482 SkGeInit( pAC, pAC->IoBase, 2);
2483 SkI2cInit( pAC, pAC->IoBase, 2);
2484 SkEventInit(pAC, pAC->IoBase, 2);
2485 SkPnmiInit( pAC, pAC->IoBase, 2);
2486 SkAddrInit( pAC, pAC->IoBase, 2);
2487 SkRlmtInit( pAC, pAC->IoBase, 2);
2488 SkTimerInit(pAC, pAC->IoBase, 2);
2491 * clear and reinit the rx rings here
2493 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2494 ReceiveIrq(pAC, &pAC->RxPort[i]);
2495 ClearRxRing(pAC, &pAC->RxPort[i]);
2496 FillRxRing(pAC, &pAC->RxPort[i]);
2498 // Enable transmit descriptor polling.
2499 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2500 FillRxRing(pAC, &pAC->RxPort[i]);
2503 SkGeYellowLED(pAC, pAC->IoBase, 1);
2505 #ifdef USE_INT_MOD
2507 unsigned long ModBase;
2508 ModBase = 53125000 / INTS_PER_SEC;
2509 SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
2510 SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);
2511 SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
2513 #endif
2515 netif_start_queue(pAC->dev);
2516 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2517 spin_unlock_irqrestore(
2518 &pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock, Flags);
2521 /* enable Interrupts */
2522 SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
2523 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2525 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2526 SkEventDispatcher(pAC, pAC->IoBase);
2529 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2531 return 0;
2532 } /* SkGeChangeMtu */
2535 /*****************************************************************************
2537 * SkGeStats - return ethernet device statistics
2539 * Description:
2540 * This function return statistic data about the ethernet device
2541 * to the operating system.
2543 * Returns:
2544 * pointer to the statistic structure.
2546 static struct net_device_stats *SkGeStats(struct net_device *dev)
2548 SK_AC *pAC = (SK_AC*) dev->priv;
2549 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2550 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2551 unsigned int Size; /* size of pnmi struct */
2552 unsigned int Flags; /* for spin lock */
2554 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2555 ("SkGeStats starts now...\n"));
2556 pPnmiStruct = &pAC->PnmiStruct;
2557 memset(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2558 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2559 Size = SK_PNMI_STRUCT_SIZE;
2560 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size);
2561 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2562 pPnmiStat = &pPnmiStruct->Stat[0];
2563 pPnmiConf = &pPnmiStruct->Conf[0];
2565 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2566 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2567 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2568 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2569 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2570 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2571 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2572 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2573 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2574 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2576 /* detailed rx_errors: */
2577 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2578 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2579 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2580 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2581 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2582 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2584 /* detailed tx_errors */
2585 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2586 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2587 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2588 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2589 pAC->stats.tx_window_errors = (SK_U32) 0;
2591 return(&pAC->stats);
2592 } /* SkGeStats */
2595 /*****************************************************************************
2597 * SkGeIoctl - IO-control function
2599 * Description:
2600 * This function is called if an ioctl is issued on the device.
2601 * There are three subfunction for reading, writing and test-writing
2602 * the private MIB data structure (usefull for SysKonnect-internal tools).
2604 * Returns:
2605 * 0, if everything is ok
2606 * !=0, on error
2608 static int SkGeIoctl(struct net_device *dev, struct ifreq *rq, int cmd)
2610 SK_AC *pAC;
2611 SK_GE_IOCTL Ioctl;
2612 unsigned int Err = 0;
2613 int Size;
2615 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2616 ("SkGeIoctl starts now...\n"));
2617 pAC = (SK_AC*) dev->priv;
2619 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2620 return -EFAULT;
2623 switch(cmd) {
2624 case SK_IOCTL_SETMIB:
2625 case SK_IOCTL_PRESETMIB:
2626 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2627 case SK_IOCTL_GETMIB:
2628 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2629 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2630 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2631 return -EFAULT;
2633 Size = SkGeIocMib(pAC, Ioctl.Len, cmd);
2634 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2635 Ioctl.Len<Size? Ioctl.Len : Size)) {
2636 return -EFAULT;
2638 Ioctl.Len = Size;
2639 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2640 return -EFAULT;
2642 break;
2643 default:
2644 Err = -EOPNOTSUPP;
2646 return(Err);
2647 } /* SkGeIoctl */
2650 /*****************************************************************************
2652 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
2654 * Description:
2655 * This function reads/writes the MIB data using PNMI (Private Network
2656 * Management Interface).
2657 * The destination for the data must be provided with the
2658 * ioctl call and is given to the driver in the form of
2659 * a user space address.
2660 * Copying from the user-provided data area into kernel messages
2661 * and back is done by copy_from_user and copy_to_user calls in
2662 * SkGeIoctl.
2664 * Returns:
2665 * returned size from PNMI call
2667 static int SkGeIocMib(
2668 SK_AC *pAC, /* pointer to the adapter context */
2669 unsigned int Size, /* length of ioctl data */
2670 int mode) /* flag for set/preset */
2672 unsigned int Flags; /* for spin lock */
2674 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2675 ("SkGeIocMib starts now...\n"));
2676 /* access MIB */
2677 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2678 switch(mode) {
2679 case SK_IOCTL_GETMIB:
2680 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size);
2681 break;
2682 case SK_IOCTL_PRESETMIB:
2683 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size);
2684 break;
2685 case SK_IOCTL_SETMIB:
2686 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size);
2687 break;
2688 default:
2689 break;
2691 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2692 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2693 ("MIB data access succeeded\n"));
2694 return (Size);
2695 } /* SkGeIocMib */
2698 /*****************************************************************************
2700 * GetConfiguration - read configuration information
2702 * Description:
2703 * This function reads per-adapter configuration information from
2704 * the options provided on the command line.
2706 * Returns:
2707 * none
2709 static void GetConfiguration(
2710 SK_AC *pAC) /* pointer to the adapter context structure */
2712 SK_I32 Port; /* preferred port */
2713 int AutoNeg; /* auto negotiation off (0) or on (1) */
2714 int DuplexCap; /* duplex capabilities (0=both, 1=full, 2=half */
2715 int MSMode; /* master / slave mode selection */
2716 SK_BOOL AutoSet;
2717 SK_BOOL DupSet;
2719 * The two parameters AutoNeg. and DuplexCap. map to one configuration
2720 * parameter. The mapping is described by this table:
2721 * DuplexCap -> | both | full | half |
2722 * AutoNeg | | | |
2723 * -----------------------------------------------------------------
2724 * Off | illegal | Full | Half |
2725 * -----------------------------------------------------------------
2726 * On | AutoBoth | AutoFull | AutoHalf |
2727 * -----------------------------------------------------------------
2728 * Sense | AutoSense | AutoSense | AutoSense |
2730 int Capabilities[3][3] =
2731 { { -1, SK_LMODE_FULL, SK_LMODE_HALF},
2732 {SK_LMODE_AUTOBOTH, SK_LMODE_AUTOFULL, SK_LMODE_AUTOHALF},
2733 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
2734 #define DC_BOTH 0
2735 #define DC_FULL 1
2736 #define DC_HALF 2
2737 #define AN_OFF 0
2738 #define AN_ON 1
2739 #define AN_SENS 2
2741 /* settings for port A */
2742 AutoNeg = AN_SENS; /* default: do auto Sense */
2743 AutoSet = SK_FALSE;
2744 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2745 AutoNeg_A[pAC->Index] != NULL) {
2746 AutoSet = SK_TRUE;
2747 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
2748 AutoSet = SK_FALSE;
2750 else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
2751 AutoNeg = AN_ON;
2753 else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
2754 AutoNeg = AN_OFF;
2756 else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
2757 AutoNeg = AN_SENS;
2759 else printk("%s: Illegal value for AutoNeg_A\n",
2760 pAC->dev->name);
2763 DuplexCap = DC_BOTH;
2764 DupSet = SK_FALSE;
2765 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2766 DupCap_A[pAC->Index] != NULL) {
2767 DupSet = SK_TRUE;
2768 if (strcmp(DupCap_A[pAC->Index],"")==0) {
2769 DupSet = SK_FALSE;
2771 else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
2772 DuplexCap = DC_BOTH;
2774 else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
2775 DuplexCap = DC_FULL;
2777 else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
2778 DuplexCap = DC_HALF;
2780 else printk("%s: Illegal value for DupCap_A\n",
2781 pAC->dev->name);
2784 /* check for illegal combinations */
2785 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
2786 printk("%s, Port A: DuplexCapabilities"
2787 " ignored using Sense mode\n", pAC->dev->name);
2789 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
2790 printk("%s, Port A: Illegal combination"
2791 " of values AutoNeg. and DuplexCap.\n Using "
2792 "Full Duplex\n", pAC->dev->name);
2794 DuplexCap = DC_FULL;
2796 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
2797 DuplexCap = DC_FULL;
2800 if (!AutoSet && DupSet) {
2801 printk("%s, Port A: Duplex setting not"
2802 " possible in\n default AutoNegotiation mode"
2803 " (Sense).\n Using AutoNegotiation On\n",
2804 pAC->dev->name);
2805 AutoNeg = AN_ON;
2808 /* set the desired mode */
2809 pAC->GIni.GP[0].PLinkModeConf =
2810 Capabilities[AutoNeg][DuplexCap];
2812 pAC->GIni.GP[0].PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
2813 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2814 FlowCtrl_A[pAC->Index] != NULL) {
2815 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
2817 else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
2818 pAC->GIni.GP[0].PFlowCtrlMode =
2819 SK_FLOW_MODE_SYM_OR_REM;
2821 else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
2822 pAC->GIni.GP[0].PFlowCtrlMode =
2823 SK_FLOW_MODE_SYMMETRIC;
2825 else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
2826 pAC->GIni.GP[0].PFlowCtrlMode =
2827 SK_FLOW_MODE_LOC_SEND;
2829 else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
2830 pAC->GIni.GP[0].PFlowCtrlMode =
2831 SK_FLOW_MODE_NONE;
2833 else printk("Illegal value for FlowCtrl_A\n");
2835 if (AutoNeg==AN_OFF && pAC->GIni.GP[0].PFlowCtrlMode!=
2836 SK_FLOW_MODE_NONE) {
2837 printk("%s, Port A: FlowControl"
2838 " impossible without AutoNegotiation,"
2839 " disabled\n", pAC->dev->name);
2840 pAC->GIni.GP[0].PFlowCtrlMode = SK_FLOW_MODE_NONE;
2843 MSMode = SK_MS_MODE_AUTO; /* default: do auto select */
2844 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2845 Role_A[pAC->Index] != NULL) {
2846 if (strcmp(Role_A[pAC->Index],"")==0) {
2848 else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
2849 MSMode = SK_MS_MODE_AUTO;
2851 else if (strcmp(Role_A[pAC->Index],"Master")==0) {
2852 MSMode = SK_MS_MODE_MASTER;
2854 else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
2855 MSMode = SK_MS_MODE_SLAVE;
2857 else printk("%s: Illegal value for Role_A\n",
2858 pAC->dev->name);
2860 pAC->GIni.GP[0].PMSMode = MSMode;
2863 /* settings for port B */
2864 AutoNeg = AN_SENS; /* default: do auto Sense */
2865 AutoSet = SK_FALSE;
2866 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2867 AutoNeg_B[pAC->Index] != NULL) {
2868 AutoSet = SK_TRUE;
2869 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
2870 AutoSet = SK_FALSE;
2872 else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
2873 AutoNeg = AN_ON;
2875 else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
2876 AutoNeg = AN_OFF;
2878 else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
2879 AutoNeg = AN_SENS;
2881 else printk("Illegal value for AutoNeg_B\n");
2884 DuplexCap = DC_BOTH;
2885 DupSet = SK_FALSE;
2886 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2887 DupCap_B[pAC->Index] != NULL) {
2888 DupSet = SK_TRUE;
2889 if (strcmp(DupCap_B[pAC->Index],"")==0) {
2890 DupSet = SK_FALSE;
2892 else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
2893 DuplexCap = DC_BOTH;
2895 else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
2896 DuplexCap = DC_FULL;
2898 else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
2899 DuplexCap = DC_HALF;
2901 else printk("Illegal value for DupCap_B\n");
2904 /* check for illegal combinations */
2905 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
2906 printk("%s, Port B: DuplexCapabilities"
2907 " ignored using Sense mode\n", pAC->dev->name);
2909 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
2910 printk("%s, Port B: Illegal combination"
2911 " of values AutoNeg. and DuplexCap.\n Using "
2912 "Full Duplex\n", pAC->dev->name);
2914 DuplexCap = DC_FULL;
2916 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
2917 DuplexCap = DC_FULL;
2920 if (!AutoSet && DupSet) {
2921 printk("%s, Port B: Duplex setting not"
2922 " possible in\n default AutoNegotiation mode"
2923 " (Sense).\n Using AutoNegotiation On\n",
2924 pAC->dev->name);
2925 AutoNeg = AN_ON;
2928 /* set the desired mode */
2929 pAC->GIni.GP[1].PLinkModeConf =
2930 Capabilities[AutoNeg][DuplexCap];
2932 pAC->GIni.GP[1].PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
2933 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2934 FlowCtrl_B[pAC->Index] != NULL) {
2935 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
2937 else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
2938 pAC->GIni.GP[1].PFlowCtrlMode =
2939 SK_FLOW_MODE_SYM_OR_REM;
2941 else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
2942 pAC->GIni.GP[1].PFlowCtrlMode =
2943 SK_FLOW_MODE_SYMMETRIC;
2945 else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
2946 pAC->GIni.GP[1].PFlowCtrlMode =
2947 SK_FLOW_MODE_LOC_SEND;
2949 else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
2950 pAC->GIni.GP[1].PFlowCtrlMode =
2951 SK_FLOW_MODE_NONE;
2953 else printk("Illegal value for FlowCtrl_B\n");
2955 if (AutoNeg==AN_OFF && pAC->GIni.GP[1].PFlowCtrlMode!=
2956 SK_FLOW_MODE_NONE) {
2957 printk("%s, Port B: FlowControl"
2958 " impossible without AutoNegotiation,"
2959 " disabled\n", pAC->dev->name);
2960 pAC->GIni.GP[1].PFlowCtrlMode = SK_FLOW_MODE_NONE;
2963 MSMode = SK_MS_MODE_AUTO; /* default: do auto select */
2964 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2965 Role_B[pAC->Index] != NULL) {
2966 if (strcmp(Role_B[pAC->Index],"")==0) {
2968 else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
2969 MSMode = SK_MS_MODE_AUTO;
2971 else if (strcmp(Role_B[pAC->Index],"Master")==0) {
2972 MSMode = SK_MS_MODE_MASTER;
2974 else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
2975 MSMode = SK_MS_MODE_SLAVE;
2977 else printk("%s: Illegal value for Role_B\n",
2978 pAC->dev->name);
2980 pAC->GIni.GP[1].PMSMode = MSMode;
2983 /* settings for both ports */
2984 pAC->ActivePort = 0;
2985 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
2986 PrefPort[pAC->Index] != NULL) {
2987 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
2988 pAC->ActivePort = 0;
2989 pAC->Rlmt.MacPreferred = -1; /* auto */
2990 pAC->Rlmt.PrefPort = 0;
2992 else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
2994 * do not set ActivePort here, thus a port
2995 * switch is issued after net up.
2997 Port = 0;
2998 pAC->Rlmt.MacPreferred = Port;
2999 pAC->Rlmt.PrefPort = Port;
3001 else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3003 * do not set ActivePort here, thus a port
3004 * switch is issued after net up.
3006 Port = 1;
3007 pAC->Rlmt.MacPreferred = Port;
3008 pAC->Rlmt.PrefPort = Port;
3010 else printk("%s: Illegal value for PrefPort\n",
3011 pAC->dev->name);
3014 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3015 RlmtMode[pAC->Index] != NULL) {
3016 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3017 pAC->RlmtMode = 0;
3019 else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3020 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3022 else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3023 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3024 SK_RLMT_CHECK_LOC_LINK;
3026 else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3027 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3028 SK_RLMT_CHECK_LOC_LINK |
3029 SK_RLMT_CHECK_SEG;
3031 else {
3032 printk("%s: Illegal value for"
3033 " RlmtMode, using default\n", pAC->dev->name);
3034 pAC->RlmtMode = 0;
3037 else {
3038 pAC->RlmtMode = 0;
3040 } /* GetConfiguration */
3043 /*****************************************************************************
3045 * ProductStr - return a adapter identification string from vpd
3047 * Description:
3048 * This function reads the product name string from the vpd area
3049 * and puts it the field pAC->DeviceString.
3051 * Returns: N/A
3053 static void ProductStr(
3054 SK_AC *pAC /* pointer to adapter context */
3057 int StrLen = 80; /* length of the string, defined in SK_AC */
3058 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3059 int ReturnCode; /* return code from vpd_read */
3060 unsigned int Flags;
3062 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3063 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3064 &StrLen);
3065 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3066 if (ReturnCode != 0) {
3067 /* there was an error reading the vpd data */
3068 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3069 ("Error reading VPD data: %d\n", ReturnCode));
3070 pAC->DeviceStr[0] = '\0';
3072 } /* ProductStr */
3077 /****************************************************************************/
3078 /* functions for common modules *********************************************/
3079 /****************************************************************************/
3082 /*****************************************************************************
3084 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3086 * Description:
3087 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3088 * is embedded into a socket buff data area.
3090 * Context:
3091 * runtime
3093 * Returns:
3094 * NULL or pointer to Mbuf.
3096 SK_MBUF *SkDrvAllocRlmtMbuf(
3097 SK_AC *pAC, /* pointer to adapter context */
3098 SK_IOC IoC, /* the IO-context */
3099 unsigned BufferSize) /* size of the requested buffer */
3101 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3102 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3104 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3105 if (pMsgBlock == NULL) {
3106 return (NULL);
3108 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3109 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3110 pRlmtMbuf->pNext = NULL;
3111 pRlmtMbuf->pOs = pMsgBlock;
3112 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3113 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3114 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3115 return (pRlmtMbuf);
3117 } /* SkDrvAllocRlmtMbuf */
3120 /*****************************************************************************
3122 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3124 * Description:
3125 * This routine frees one or more RLMT mbuf(s).
3127 * Context:
3128 * runtime
3130 * Returns:
3131 * Nothing
3133 void SkDrvFreeRlmtMbuf(
3134 SK_AC *pAC, /* pointer to adapter context */
3135 SK_IOC IoC, /* the IO-context */
3136 SK_MBUF *pMbuf) /* size of the requested buffer */
3138 SK_MBUF *pFreeMbuf;
3139 SK_MBUF *pNextMbuf;
3141 pFreeMbuf = pMbuf;
3142 do {
3143 pNextMbuf = pFreeMbuf->pNext;
3144 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3145 pFreeMbuf = pNextMbuf;
3146 } while ( pFreeMbuf != NULL );
3147 } /* SkDrvFreeRlmtMbuf */
3150 /*****************************************************************************
3152 * SkOsGetTime - provide a time value
3154 * Description:
3155 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3156 * It is not used for absolute time, but only for time differences.
3159 * Returns:
3160 * Time value
3162 SK_U64 SkOsGetTime(SK_AC *pAC)
3164 return jiffies;
3165 } /* SkOsGetTime */
3168 /*****************************************************************************
3170 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3172 * Description:
3173 * This routine reads a 32 bit value from the pci configuration
3174 * space.
3176 * Returns:
3177 * 0 - indicate everything worked ok.
3178 * != 0 - error indication
3180 int SkPciReadCfgDWord(
3181 SK_AC *pAC, /* Adapter Control structure pointer */
3182 int PciAddr, /* PCI register address */
3183 SK_U32 *pVal) /* pointer to store the read value */
3185 pci_read_config_dword(&pAC->PciDev, PciAddr, pVal);
3186 return(0);
3187 } /* SkPciReadCfgDWord */
3190 /*****************************************************************************
3192 * SkPciReadCfgWord - read a 16 bit value from pci config space
3194 * Description:
3195 * This routine reads a 16 bit value from the pci configuration
3196 * space.
3198 * Returns:
3199 * 0 - indicate everything worked ok.
3200 * != 0 - error indication
3202 int SkPciReadCfgWord(
3203 SK_AC *pAC, /* Adapter Control structure pointer */
3204 int PciAddr, /* PCI register address */
3205 SK_U16 *pVal) /* pointer to store the read value */
3207 pci_read_config_word(&pAC->PciDev, PciAddr, pVal);
3208 return(0);
3209 } /* SkPciReadCfgWord */
3212 /*****************************************************************************
3214 * SkPciReadCfgByte - read a 8 bit value from pci config space
3216 * Description:
3217 * This routine reads a 8 bit value from the pci configuration
3218 * space.
3220 * Returns:
3221 * 0 - indicate everything worked ok.
3222 * != 0 - error indication
3224 int SkPciReadCfgByte(
3225 SK_AC *pAC, /* Adapter Control structure pointer */
3226 int PciAddr, /* PCI register address */
3227 SK_U8 *pVal) /* pointer to store the read value */
3229 pci_read_config_byte(&pAC->PciDev, PciAddr, pVal);
3230 return(0);
3231 } /* SkPciReadCfgByte */
3234 /*****************************************************************************
3236 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
3238 * Description:
3239 * This routine writes a 32 bit value to the pci configuration
3240 * space.
3242 * Returns:
3243 * 0 - indicate everything worked ok.
3244 * != 0 - error indication
3246 int SkPciWriteCfgDWord(
3247 SK_AC *pAC, /* Adapter Control structure pointer */
3248 int PciAddr, /* PCI register address */
3249 SK_U32 Val) /* pointer to store the read value */
3251 pci_write_config_dword(&pAC->PciDev, PciAddr, Val);
3252 return(0);
3253 } /* SkPciWriteCfgDWord */
3256 /*****************************************************************************
3258 * SkPciWriteCfgWord - write a 16 bit value to pci config space
3260 * Description:
3261 * This routine writes a 16 bit value to the pci configuration
3262 * space. The flag PciConfigUp indicates whether the config space
3263 * is accesible or must be set up first.
3265 * Returns:
3266 * 0 - indicate everything worked ok.
3267 * != 0 - error indication
3269 int SkPciWriteCfgWord(
3270 SK_AC *pAC, /* Adapter Control structure pointer */
3271 int PciAddr, /* PCI register address */
3272 SK_U16 Val) /* pointer to store the read value */
3274 pci_write_config_word(&pAC->PciDev, PciAddr, Val);
3275 return(0);
3276 } /* SkPciWriteCfgWord */
3279 /*****************************************************************************
3281 * SkPciWriteCfgWord - write a 8 bit value to pci config space
3283 * Description:
3284 * This routine writes a 8 bit value to the pci configuration
3285 * space. The flag PciConfigUp indicates whether the config space
3286 * is accesible or must be set up first.
3288 * Returns:
3289 * 0 - indicate everything worked ok.
3290 * != 0 - error indication
3292 int SkPciWriteCfgByte(
3293 SK_AC *pAC, /* Adapter Control structure pointer */
3294 int PciAddr, /* PCI register address */
3295 SK_U8 Val) /* pointer to store the read value */
3297 pci_write_config_byte(&pAC->PciDev, PciAddr, Val);
3298 return(0);
3299 } /* SkPciWriteCfgByte */
3302 /*****************************************************************************
3304 * SkDrvEvent - handle driver events
3306 * Description:
3307 * This function handles events from all modules directed to the driver
3309 * Context:
3310 * Is called under protection of slow path lock.
3312 * Returns:
3313 * 0 if everything ok
3314 * < 0 on error
3317 int SkDrvEvent(
3318 SK_AC *pAC, /* pointer to adapter context */
3319 SK_IOC IoC, /* io-context */
3320 SK_U32 Event, /* event-id */
3321 SK_EVPARA Param) /* event-parameter */
3323 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
3324 struct sk_buff *pMsg; /* pointer to a message block */
3325 int FromPort; /* the port from which we switch away */
3326 int ToPort; /* the port we switch to */
3327 SK_EVPARA NewPara; /* parameter for further events */
3328 int Stat;
3329 unsigned int Flags;
3331 switch (Event) {
3332 case SK_DRV_ADAP_FAIL:
3333 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3334 ("ADAPTER FAIL EVENT\n"));
3335 printk("%s: Adapter failed.\n", pAC->dev->name);
3336 /* disable interrupts */
3337 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
3338 /* cgoos */
3339 break;
3340 case SK_DRV_PORT_FAIL:
3341 FromPort = Param.Para32[0];
3342 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3343 ("PORT FAIL EVENT, Port: %d\n", FromPort));
3344 if (FromPort == 0) {
3345 printk("%s: Port A failed.\n", pAC->dev->name);
3346 } else {
3347 printk("%s: Port B failed.\n", pAC->dev->name);
3349 /* cgoos */
3350 break;
3351 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
3352 /* action list 4 */
3353 FromPort = Param.Para32[0];
3354 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3355 ("PORT RESET EVENT, Port: %d ", FromPort));
3356 NewPara.Para64 = FromPort;
3357 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
3358 spin_lock_irqsave(
3359 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3360 Flags);
3361 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
3362 spin_unlock_irqrestore(
3363 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3364 Flags);
3366 /* clear rx ring from received frames */
3367 ReceiveIrq(pAC, &pAC->RxPort[FromPort]);
3369 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
3370 spin_lock_irqsave(
3371 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3372 Flags);
3373 SkGeInitPort(pAC, IoC, FromPort);
3374 SkAddrMcUpdate(pAC,IoC, FromPort);
3375 PortReInitBmu(pAC, FromPort);
3376 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
3377 ClearAndStartRx(pAC, FromPort);
3378 spin_unlock_irqrestore(
3379 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3380 Flags);
3381 break;
3382 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
3383 /* action list 5 */
3384 FromPort = Param.Para32[0];
3385 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3386 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
3387 printk("%s: network connection up using"
3388 " port %c\n", pAC->dev->name, 'A'+Param.Para32[0]);
3389 printk(" speed: 1000\n");
3390 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
3391 if (Stat == SK_LMODE_STAT_AUTOHALF ||
3392 Stat == SK_LMODE_STAT_AUTOFULL) {
3393 printk(" autonegotiation: yes\n");
3395 else {
3396 printk(" autonegotiation: no\n");
3398 if (Stat == SK_LMODE_STAT_AUTOHALF ||
3399 Stat == SK_LMODE_STAT_HALF) {
3400 printk(" duplex mode: half\n");
3402 else {
3403 printk(" duplex mode: full\n");
3405 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
3406 if (Stat == SK_FLOW_STAT_REM_SEND ) {
3407 printk(" flowctrl: remote send\n");
3409 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
3410 printk(" flowctrl: local send\n");
3412 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
3413 printk(" flowctrl: symmetric\n");
3415 else {
3416 printk(" flowctrl: none\n");
3418 if (pAC->GIni.GP[FromPort].PhyType != SK_PHY_XMAC) {
3419 Stat = pAC->GIni.GP[FromPort].PMSStatus;
3420 if (Stat == SK_MS_STAT_MASTER ) {
3421 printk(" role: master\n");
3423 else if (Stat == SK_MS_STAT_SLAVE ) {
3424 printk(" role: slave\n");
3426 else {
3427 printk(" role: ???\n");
3431 if (Param.Para32[0] != pAC->ActivePort) {
3432 NewPara.Para32[0] = pAC->ActivePort;
3433 NewPara.Para32[1] = Param.Para32[0];
3434 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
3435 NewPara);
3437 break;
3438 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
3439 /* action list 7 */
3440 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3441 ("NET DOWN EVENT "));
3442 printk("%s: network connection down\n", pAC->dev->name);
3443 break;
3444 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3445 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3446 ("PORT SWITCH HARD "));
3447 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3448 /* action list 6 */
3449 printk("%s: switching to port %c\n", pAC->dev->name,
3450 'A'+Param.Para32[1]);
3451 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3452 FromPort = Param.Para32[0];
3453 ToPort = Param.Para32[1];
3454 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3455 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
3456 FromPort, ToPort, pAC->Rlmt.PrefPort));
3457 NewPara.Para64 = FromPort;
3458 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
3459 NewPara.Para64 = ToPort;
3460 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
3461 spin_lock_irqsave(
3462 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3463 Flags);
3464 spin_lock_irqsave(
3465 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
3466 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
3467 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
3468 spin_unlock_irqrestore(
3469 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
3470 spin_unlock_irqrestore(
3471 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3472 Flags);
3474 ReceiveIrq(pAC, &pAC->RxPort[FromPort]); /* clears rx ring */
3475 ReceiveIrq(pAC, &pAC->RxPort[ToPort]); /* clears rx ring */
3477 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
3478 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
3479 spin_lock_irqsave(
3480 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3481 Flags);
3482 spin_lock_irqsave(
3483 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
3484 pAC->ActivePort = ToPort;
3485 SetQueueSizes(pAC);
3486 SkGeInitPort(pAC, IoC, FromPort);
3487 SkGeInitPort(pAC, IoC, ToPort);
3488 if (Event == SK_DRV_SWITCH_SOFT) {
3489 SkXmRxTxEnable(pAC, IoC, FromPort);
3491 SkXmRxTxEnable(pAC, IoC, ToPort);
3492 SkAddrSwap(pAC, IoC, FromPort, ToPort);
3493 SkAddrMcUpdate(pAC, IoC, FromPort);
3494 SkAddrMcUpdate(pAC, IoC, ToPort);
3495 PortReInitBmu(pAC, FromPort);
3496 PortReInitBmu(pAC, ToPort);
3497 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
3498 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
3499 ClearAndStartRx(pAC, FromPort);
3500 ClearAndStartRx(pAC, ToPort);
3501 spin_unlock_irqrestore(
3502 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
3503 spin_unlock_irqrestore(
3504 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3505 Flags);
3506 break;
3507 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
3508 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3509 ("RLS "));
3510 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
3511 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
3512 skb_put(pMsg, pRlmtMbuf->Length);
3513 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
3514 pMsg) <= 0)
3515 DEV_KFREE_SKB(pMsg);
3516 break;
3517 default:
3518 break;
3520 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3521 ("END EVENT "));
3523 return (0);
3524 } /* SkDrvEvent */
3527 /*****************************************************************************
3529 * SkErrorLog - log errors
3531 * Description:
3532 * This function logs errors to the system buffer and to the console
3534 * Returns:
3535 * 0 if everything ok
3536 * < 0 on error
3539 void SkErrorLog(
3540 SK_AC *pAC,
3541 int ErrClass,
3542 int ErrNum,
3543 char *pErrorMsg)
3545 char ClassStr[80];
3547 switch (ErrClass) {
3548 case SK_ERRCL_OTHER:
3549 strcpy(ClassStr, "Other error");
3550 break;
3551 case SK_ERRCL_CONFIG:
3552 strcpy(ClassStr, "Configuration error");
3553 break;
3554 case SK_ERRCL_INIT:
3555 strcpy(ClassStr, "Initialization error");
3556 break;
3557 case SK_ERRCL_NORES:
3558 strcpy(ClassStr, "Out of resources error");
3559 break;
3560 case SK_ERRCL_SW:
3561 strcpy(ClassStr, "internal Software error");
3562 break;
3563 case SK_ERRCL_HW:
3564 strcpy(ClassStr, "Hardware failure");
3565 break;
3566 case SK_ERRCL_COMM:
3567 strcpy(ClassStr, "Communication error");
3568 break;
3570 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
3571 " Nr: 0x%x\n Msg: %s\n", pAC->dev->name,
3572 ClassStr, ErrNum, pErrorMsg);
3574 } /* SkErrorLog */
3576 #ifdef DEBUG /***************************************************************/
3577 /* "debug only" section *****************************************************/
3578 /****************************************************************************/
3581 /*****************************************************************************
3583 * DumpMsg - print a frame
3585 * Description:
3586 * This function prints frames to the system logfile/to the console.
3588 * Returns: N/A
3591 static void DumpMsg(struct sk_buff *skb, char *str)
3593 int msglen;
3595 if (skb == NULL) {
3596 printk("DumpMsg(): NULL-Message\n");
3597 return;
3600 if (skb->data == NULL) {
3601 printk("DumpMsg(): Message empty\n");
3602 return;
3605 msglen = skb->len;
3606 if (msglen > 64)
3607 msglen = 64;
3609 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
3611 DumpData((char *)skb->data, msglen);
3613 printk("------- End of message ---------\n");
3614 } /* DumpMsg */
3618 /*****************************************************************************
3620 * DumpData - print a data area
3622 * Description:
3623 * This function prints a area of data to the system logfile/to the
3624 * console.
3626 * Returns: N/A
3629 static void DumpData(char *p, int size)
3631 register int i;
3632 int haddr, addr;
3633 char hex_buffer[180];
3634 char asc_buffer[180];
3635 char HEXCHAR[] = "0123456789ABCDEF";
3637 addr = 0;
3638 haddr = 0;
3639 hex_buffer[0] = 0;
3640 asc_buffer[0] = 0;
3641 for (i=0; i < size; ) {
3642 if (*p >= '0' && *p <='z')
3643 asc_buffer[addr] = *p;
3644 else
3645 asc_buffer[addr] = '.';
3646 addr++;
3647 asc_buffer[addr] = 0;
3648 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
3649 haddr++;
3650 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
3651 haddr++;
3652 hex_buffer[haddr] = ' ';
3653 haddr++;
3654 hex_buffer[haddr] = 0;
3655 p++;
3656 i++;
3657 if (i%16 == 0) {
3658 printk("%s %s\n", hex_buffer, asc_buffer);
3659 addr = 0;
3660 haddr = 0;
3663 } /* DumpData */
3666 /*****************************************************************************
3668 * DumpLong - print a data area as long values
3670 * Description:
3671 * This function prints a area of data to the system logfile/to the
3672 * console.
3674 * Returns: N/A
3677 static void DumpLong(char *pc, int size)
3679 register int i;
3680 int haddr, addr;
3681 char hex_buffer[180];
3682 char asc_buffer[180];
3683 char HEXCHAR[] = "0123456789ABCDEF";
3684 long *p;
3685 int l;
3687 addr = 0;
3688 haddr = 0;
3689 hex_buffer[0] = 0;
3690 asc_buffer[0] = 0;
3691 p = (long*) pc;
3692 for (i=0; i < size; ) {
3693 l = (long) *p;
3694 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
3695 haddr++;
3696 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
3697 haddr++;
3698 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
3699 haddr++;
3700 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
3701 haddr++;
3702 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
3703 haddr++;
3704 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
3705 haddr++;
3706 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
3707 haddr++;
3708 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
3709 haddr++;
3710 hex_buffer[haddr] = ' ';
3711 haddr++;
3712 hex_buffer[haddr] = 0;
3713 p++;
3714 i++;
3715 if (i%8 == 0) {
3716 printk("%4x %s\n", (i-8)*4, hex_buffer);
3717 haddr = 0;
3720 printk("------------------------\n");
3721 } /* DumpLong */
3723 #endif /* DEBUG */
3726 * Local variables:
3727 * compile-command: "make"
3728 * End: