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