devices/forcedeth-2.6.19-ethercat.c
changeset 591 2b949dcba32b
parent 586 99df3f4d8d76
child 593 78c838980258
equal deleted inserted replaced
590:5801d4a4ff7d 591:2b949dcba32b
  2383 static void nv_linkchange(struct net_device *dev)
  2383 static void nv_linkchange(struct net_device *dev)
  2384 {
  2384 {
  2385 	struct fe_priv *np = netdev_priv(dev);
  2385 	struct fe_priv *np = netdev_priv(dev);
  2386 
  2386 
  2387     if (np->ecdev) {
  2387     if (np->ecdev) {
  2388         nv_update_linkspeed(dev);
  2388         int link = nv_update_linkspeed(dev);
       
  2389         ecdev_link_state(np->ecdev, link);
  2389         return;
  2390         return;
  2390     }
  2391     }
  2391 
  2392 
  2392 	if (nv_update_linkspeed(dev)) {
  2393 	if (nv_update_linkspeed(dev)) {
  2393 		if (!netif_carrier_ok(dev)) {
  2394 		if (!netif_carrier_ok(dev)) {
  2439 		pci_push(base);
  2440 		pci_push(base);
  2440 		dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
  2441 		dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
  2441 		if (!(events & np->irqmask))
  2442 		if (!(events & np->irqmask))
  2442 			break;
  2443 			break;
  2443 
  2444 
  2444 		spin_lock(&np->lock);
  2445 		if (!np->ecdev) spin_lock(&np->lock);
  2445 		nv_tx_done(dev);
  2446 		nv_tx_done(dev);
  2446 		spin_unlock(&np->lock);
  2447 		if (!np->ecdev) spin_unlock(&np->lock);
  2447 
  2448 
  2448 		if (events & NVREG_IRQ_LINK) {
  2449 		if (events & NVREG_IRQ_LINK) {
  2449 			spin_lock(&np->lock);
  2450 			if (!np->ecdev) spin_lock(&np->lock);
  2450 			nv_link_irq(dev);
  2451 			nv_link_irq(dev);
  2451 			spin_unlock(&np->lock);
  2452 			if (!np->ecdev) spin_unlock(&np->lock);
  2452 		}
  2453 		}
  2453 		if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  2454 		if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  2454 			spin_lock(&np->lock);
  2455 			if (!np->ecdev) spin_lock(&np->lock);
  2455 			nv_linkchange(dev);
  2456 			nv_linkchange(dev);
  2456 			spin_unlock(&np->lock);
  2457 			if (!np->ecdev) spin_unlock(&np->lock);
  2457 			np->link_timeout = jiffies + LINK_TIMEOUT;
  2458 			np->link_timeout = jiffies + LINK_TIMEOUT;
  2458 		}
  2459 		}
  2459 		if (events & (NVREG_IRQ_TX_ERR)) {
  2460 		if (events & (NVREG_IRQ_TX_ERR)) {
  2460 			dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
  2461 			dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
  2461 						dev->name, events);
  2462 						dev->name, events);
  2464 			printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
  2465 			printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
  2465 						dev->name, events);
  2466 						dev->name, events);
  2466 		}
  2467 		}
  2467 #ifdef CONFIG_FORCEDETH_NAPI
  2468 #ifdef CONFIG_FORCEDETH_NAPI
  2468 		if (events & NVREG_IRQ_RX_ALL) {
  2469 		if (events & NVREG_IRQ_RX_ALL) {
  2469 			netif_rx_schedule(dev);
  2470 			if (np->ecdev) {
  2470 
  2471 				nv_rx_process(dev, dev->weight);
  2471 			/* Disable furthur receive irq's */
  2472 			}
  2472 			spin_lock(&np->lock);
  2473 			else {
  2473 			np->irqmask &= ~NVREG_IRQ_RX_ALL;
  2474 				netif_rx_schedule(dev);
  2474 
  2475 
  2475 			if (np->msi_flags & NV_MSI_X_ENABLED)
  2476 				/* Disable furthur receive irq's */
  2476 				writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
  2477 				spin_lock(&np->lock);
  2477 			else
  2478 				np->irqmask &= ~NVREG_IRQ_RX_ALL;
  2478 				writel(np->irqmask, base + NvRegIrqMask);
  2479 
  2479 			spin_unlock(&np->lock);
  2480 				if (np->msi_flags & NV_MSI_X_ENABLED)
       
  2481 					writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
       
  2482 				else
       
  2483 					writel(np->irqmask, base + NvRegIrqMask);
       
  2484 				spin_unlock(&np->lock);
       
  2485 			}
  2480 		}
  2486 		}
  2481 #else
  2487 #else
  2482 		nv_rx_process(dev, dev->weight);
  2488 		nv_rx_process(dev, dev->weight);
  2483 		if (nv_alloc_rx(dev)) {
  2489 		if (nv_alloc_rx(dev) && !np->ecdev) {
  2484 			spin_lock(&np->lock);
  2490 			spin_lock(&np->lock);
  2485 			if (!np->in_shutdown)
  2491 			if (!np->in_shutdown)
  2486 				mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2492 				mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2487 			spin_unlock(&np->lock);
  2493 			spin_unlock(&np->lock);
  2488 		}
  2494 		}
  2489 #endif
  2495 #endif
  2490 		if (i > max_interrupt_work) {
  2496 		if (i > max_interrupt_work) {
  2491 			spin_lock(&np->lock);
  2497 			if (!np->ecdev) {
  2492 			/* disable interrupts on the nic */
  2498 				spin_lock(&np->lock);
  2493 			if (!(np->msi_flags & NV_MSI_X_ENABLED))
  2499 				/* disable interrupts on the nic */
  2494 				writel(0, base + NvRegIrqMask);
  2500 				if (!(np->msi_flags & NV_MSI_X_ENABLED))
  2495 			else
  2501 					writel(0, base + NvRegIrqMask);
  2496 				writel(np->irqmask, base + NvRegIrqMask);
  2502 				else
  2497 			pci_push(base);
  2503 					writel(np->irqmask, base + NvRegIrqMask);
  2498 
  2504 				pci_push(base);
  2499 			if (!np->in_shutdown) {
  2505 
  2500 				np->nic_poll_irq = np->irqmask;
  2506 				if (!np->in_shutdown) {
  2501 				mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  2507 					np->nic_poll_irq = np->irqmask;
       
  2508 					mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
       
  2509 				}
       
  2510 				spin_unlock(&np->lock);
  2502 			}
  2511 			}
  2503 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
  2512 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
  2504 			spin_unlock(&np->lock);
       
  2505 			break;
  2513 			break;
  2506 		}
  2514 		}
  2507 
  2515 
  2508 	}
  2516 	}
  2509 	dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
  2517 	dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
  2516 	struct net_device *dev = (struct net_device *) data;
  2524 	struct net_device *dev = (struct net_device *) data;
  2517 	struct fe_priv *np = netdev_priv(dev);
  2525 	struct fe_priv *np = netdev_priv(dev);
  2518 	u8 __iomem *base = get_hwbase(dev);
  2526 	u8 __iomem *base = get_hwbase(dev);
  2519 	u32 events;
  2527 	u32 events;
  2520 	int i;
  2528 	int i;
  2521 	unsigned long flags;
  2529 	unsigned long flags = 0;
  2522 
  2530 
  2523 	dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
  2531 	dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
  2524 
  2532 
  2525 	for (i=0; ; i++) {
  2533 	for (i=0; ; i++) {
  2526 		events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
  2534 		events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
  2528 		pci_push(base);
  2536 		pci_push(base);
  2529 		dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
  2537 		dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
  2530 		if (!(events & np->irqmask))
  2538 		if (!(events & np->irqmask))
  2531 			break;
  2539 			break;
  2532 
  2540 
  2533 		spin_lock_irqsave(&np->lock, flags);
  2541 		if (!np->ecdev) spin_lock_irqsave(&np->lock, flags);
  2534 		nv_tx_done(dev);
  2542 		nv_tx_done(dev);
  2535 		spin_unlock_irqrestore(&np->lock, flags);
  2543 		if (!np->ecdev) spin_unlock_irqrestore(&np->lock, flags);
  2536 
  2544 
  2537 		if (events & (NVREG_IRQ_TX_ERR)) {
  2545 		if (events & (NVREG_IRQ_TX_ERR)) {
  2538 			dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
  2546 			dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
  2539 						dev->name, events);
  2547 						dev->name, events);
  2540 		}
  2548 		}
  2541 		if (i > max_interrupt_work) {
  2549 		if (i > max_interrupt_work) {
  2542 			spin_lock_irqsave(&np->lock, flags);
  2550 			if (!np->ecdev) { 
  2543 			/* disable interrupts on the nic */
  2551 				spin_lock_irqsave(&np->lock, flags);
  2544 			writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
  2552 				/* disable interrupts on the nic */
  2545 			pci_push(base);
  2553 				writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
  2546 
  2554 				pci_push(base);
  2547 			if (!np->in_shutdown) {
  2555 
  2548 				np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
  2556 				if (!np->in_shutdown) {
  2549 				mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  2557 					np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
       
  2558 					mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
       
  2559 				}
       
  2560 				spin_unlock_irqrestore(&np->lock, flags);
  2550 			}
  2561 			}
  2551 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
  2562 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
  2552 			spin_unlock_irqrestore(&np->lock, flags);
       
  2553 			break;
  2563 			break;
  2554 		}
  2564 		}
  2555 
  2565 
  2556 	}
  2566 	}
  2557 	dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
  2567 	dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
  2599 
  2609 
  2600 #ifdef CONFIG_FORCEDETH_NAPI
  2610 #ifdef CONFIG_FORCEDETH_NAPI
  2601 static irqreturn_t nv_nic_irq_rx(int foo, void *data)
  2611 static irqreturn_t nv_nic_irq_rx(int foo, void *data)
  2602 {
  2612 {
  2603 	struct net_device *dev = (struct net_device *) data;
  2613 	struct net_device *dev = (struct net_device *) data;
       
  2614 	struct fe_priv *np = netdev_priv(dev);
  2604 	u8 __iomem *base = get_hwbase(dev);
  2615 	u8 __iomem *base = get_hwbase(dev);
  2605 	u32 events;
  2616 	u32 events;
  2606 
  2617 
  2607 	events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
  2618 	events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
  2608 	writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
  2619 	writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
  2609 
  2620 
  2610 	if (events) {
  2621 	if (events && !np->ecdev) {
  2611 		netif_rx_schedule(dev);
  2622 		netif_rx_schedule(dev);
  2612 		/* disable receive interrupts on the nic */
  2623 		/* disable receive interrupts on the nic */
  2613 		writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
  2624 		writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
  2614 		pci_push(base);
  2625 		pci_push(base);
  2615 	}
  2626 	}
  2634 		dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
  2645 		dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
  2635 		if (!(events & np->irqmask))
  2646 		if (!(events & np->irqmask))
  2636 			break;
  2647 			break;
  2637 
  2648 
  2638 		nv_rx_process(dev, dev->weight);
  2649 		nv_rx_process(dev, dev->weight);
  2639 		if (nv_alloc_rx(dev)) {
  2650 		if (nv_alloc_rx(dev) && !np->ecdev) {
  2640 			spin_lock_irqsave(&np->lock, flags);
  2651 			spin_lock_irqsave(&np->lock, flags);
  2641 			if (!np->in_shutdown)
  2652 			if (!np->in_shutdown)
  2642 				mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2653 				mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2643 			spin_unlock_irqrestore(&np->lock, flags);
  2654 			spin_unlock_irqrestore(&np->lock, flags);
  2644 		}
  2655 		}
  2645 
  2656 
  2646 		if (i > max_interrupt_work) {
  2657 		if (i > max_interrupt_work) {
  2647 			spin_lock_irqsave(&np->lock, flags);
  2658 			if (!np->ecdev) {
  2648 			/* disable interrupts on the nic */
  2659 				spin_lock_irqsave(&np->lock, flags);
  2649 			writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
  2660 				/* disable interrupts on the nic */
  2650 			pci_push(base);
  2661 				writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
  2651 
  2662 				pci_push(base);
  2652 			if (!np->in_shutdown) {
  2663 
  2653 				np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
  2664 				if (!np->in_shutdown) {
  2654 				mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  2665 					np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
       
  2666 					mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
       
  2667 				}
       
  2668 				spin_unlock_irqrestore(&np->lock, flags);
  2655 			}
  2669 			}
  2656 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
  2670 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
  2657 			spin_unlock_irqrestore(&np->lock, flags);
       
  2658 			break;
  2671 			break;
  2659 		}
  2672 		}
  2660 	}
  2673 	}
  2661 	dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
  2674 	dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
  2662 
  2675 
  2669 	struct net_device *dev = (struct net_device *) data;
  2682 	struct net_device *dev = (struct net_device *) data;
  2670 	struct fe_priv *np = netdev_priv(dev);
  2683 	struct fe_priv *np = netdev_priv(dev);
  2671 	u8 __iomem *base = get_hwbase(dev);
  2684 	u8 __iomem *base = get_hwbase(dev);
  2672 	u32 events;
  2685 	u32 events;
  2673 	int i;
  2686 	int i;
  2674 	unsigned long flags;
  2687 	unsigned long flags = 0;
  2675 
  2688 
  2676 	dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
  2689 	dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
  2677 
  2690 
  2678 	for (i=0; ; i++) {
  2691 	for (i=0; ; i++) {
  2679 		events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
  2692 		events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
  2682 		dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
  2695 		dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
  2683 		if (!(events & np->irqmask))
  2696 		if (!(events & np->irqmask))
  2684 			break;
  2697 			break;
  2685 
  2698 
  2686 		if (events & NVREG_IRQ_LINK) {
  2699 		if (events & NVREG_IRQ_LINK) {
  2687 			spin_lock_irqsave(&np->lock, flags);
  2700 			if (!np->ecdev) spin_lock_irqsave(&np->lock, flags);
  2688 			nv_link_irq(dev);
  2701 			nv_link_irq(dev);
  2689 			spin_unlock_irqrestore(&np->lock, flags);
  2702 			if (!np->ecdev) spin_unlock_irqrestore(&np->lock, flags);
  2690 		}
  2703 		}
  2691 		if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  2704 		if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  2692 			spin_lock_irqsave(&np->lock, flags);
  2705 			if (!np->ecdev) spin_lock_irqsave(&np->lock, flags);
  2693 			nv_linkchange(dev);
  2706 			nv_linkchange(dev);
  2694 			spin_unlock_irqrestore(&np->lock, flags);
  2707 			if (!np->ecdev) spin_unlock_irqrestore(&np->lock, flags);
  2695 			np->link_timeout = jiffies + LINK_TIMEOUT;
  2708 			np->link_timeout = jiffies + LINK_TIMEOUT;
  2696 		}
  2709 		}
  2697 		if (events & (NVREG_IRQ_UNKNOWN)) {
  2710 		if (events & (NVREG_IRQ_UNKNOWN)) {
  2698 			printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
  2711 			printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
  2699 						dev->name, events);
  2712 						dev->name, events);
  2700 		}
  2713 		}
  2701 		if (i > max_interrupt_work) {
  2714 		if (i > max_interrupt_work) {
  2702 			spin_lock_irqsave(&np->lock, flags);
  2715 			if (!np->ecdev) { 
  2703 			/* disable interrupts on the nic */
  2716 				spin_lock_irqsave(&np->lock, flags);
  2704 			writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
  2717 				/* disable interrupts on the nic */
  2705 			pci_push(base);
  2718 				writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
  2706 
  2719 				pci_push(base);
  2707 			if (!np->in_shutdown) {
  2720 
  2708 				np->nic_poll_irq |= NVREG_IRQ_OTHER;
  2721 				if (!np->in_shutdown) {
  2709 				mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  2722 					np->nic_poll_irq |= NVREG_IRQ_OTHER;
       
  2723 					mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
       
  2724 				}
       
  2725 				spin_unlock_irqrestore(&np->lock, flags);
  2710 			}
  2726 			}
  2711 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
  2727 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
  2712 			spin_unlock_irqrestore(&np->lock, flags);
       
  2713 			break;
  2728 			break;
  2714 		}
  2729 		}
  2715 
  2730 
  2716 	}
  2731 	}
  2717 	dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
  2732 	dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
  2891 	}
  2906 	}
  2892 }
  2907 }
  2893 
  2908 
  2894 void ec_poll(struct net_device *dev)
  2909 void ec_poll(struct net_device *dev)
  2895 {
  2910 {
  2896     nv_nic_irq(0, dev);
  2911 	struct fe_priv *np = netdev_priv(dev);
       
  2912 
       
  2913 	if (!using_multi_irqs(dev)) {
       
  2914 		nv_nic_irq(0, dev);
       
  2915 	} else {
       
  2916 		if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
       
  2917 			nv_nic_irq_rx(0, dev);
       
  2918 		}
       
  2919 		if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
       
  2920 			nv_nic_irq_tx(0, dev);
       
  2921 		}
       
  2922 		if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
       
  2923 			nv_nic_irq_other(0, dev);
       
  2924 		}
       
  2925 	}
  2897 }
  2926 }
  2898 
  2927 
  2899 static void nv_do_nic_poll(unsigned long data)
  2928 static void nv_do_nic_poll(unsigned long data)
  2900 {
  2929 {
  2901 	struct net_device *dev = (struct net_device *) data;
  2930 	struct net_device *dev = (struct net_device *) data;
  4156 	pci_push(base);
  4185 	pci_push(base);
  4157 	writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
  4186 	writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
  4158 	writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  4187 	writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  4159 	pci_push(base);
  4188 	pci_push(base);
  4160 
  4189 
  4161 	if (nv_request_irq(dev, 0)) {
  4190 	if (!np->ecdev) {
  4162 		goto out_drain;
  4191 		if (nv_request_irq(dev, 0)) {
  4163 	}
  4192 			goto out_drain;
  4164 
  4193 		}
  4165 	/* ask for interrupts */
  4194 
  4166 	nv_enable_hw_interrupts(dev, np->irqmask);
  4195 		/* ask for interrupts */
  4167 
  4196 		nv_enable_hw_interrupts(dev, np->irqmask);
  4168 	spin_lock_irq(&np->lock);
  4197 
       
  4198 		spin_lock_irq(&np->lock);
       
  4199 	}
       
  4200 
  4169 	writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
  4201 	writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
  4170 	writel(0, base + NvRegMulticastAddrB);
  4202 	writel(0, base + NvRegMulticastAddrB);
  4171 	writel(0, base + NvRegMulticastMaskA);
  4203 	writel(0, base + NvRegMulticastMaskA);
  4172 	writel(0, base + NvRegMulticastMaskB);
  4204 	writel(0, base + NvRegMulticastMaskB);
  4173 	writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
  4205 	writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
  4184 	 * to init hw */
  4216 	 * to init hw */
  4185 	np->linkspeed = 0;
  4217 	np->linkspeed = 0;
  4186 	ret = nv_update_linkspeed(dev);
  4218 	ret = nv_update_linkspeed(dev);
  4187 	nv_start_rx(dev);
  4219 	nv_start_rx(dev);
  4188 	nv_start_tx(dev);
  4220 	nv_start_tx(dev);
  4189 	netif_start_queue(dev);
  4221 
  4190 	netif_poll_enable(dev);
  4222 	if (np->ecdev) {
  4191 
  4223 		ecdev_link_state(np->ecdev, ret);
  4192 	if (ret) {
  4224 	}
  4193 		netif_carrier_on(dev);
  4225 	else {
  4194 	} else {
  4226 		netif_start_queue(dev);
  4195 		printk("%s: no link during initialization.\n", dev->name);
  4227 		netif_poll_enable(dev);
  4196 		netif_carrier_off(dev);
  4228 
  4197 	}
  4229 		if (ret) {
  4198 	if (oom)
  4230 			netif_carrier_on(dev);
  4199 		mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  4231 		} else {
  4200 
  4232 			printk("%s: no link during initialization.\n", dev->name);
  4201 	/* start statistics timer */
  4233 			netif_carrier_off(dev);
  4202 	if (np->driver_data & DEV_HAS_STATISTICS)
  4234 		}
  4203 		mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
  4235 		if (oom)
  4204 
  4236 			mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  4205 	spin_unlock_irq(&np->lock);
  4237 
       
  4238 		/* start statistics timer */
       
  4239 		if (np->driver_data & DEV_HAS_STATISTICS)
       
  4240 			mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
       
  4241 
       
  4242 		spin_unlock_irq(&np->lock);
       
  4243 	}
  4206 
  4244 
  4207 	return 0;
  4245 	return 0;
  4208 out_drain:
  4246 out_drain:
  4209 	drain_ring(dev);
  4247 	drain_ring(dev);
  4210 	return ret;
  4248 	return ret;
  4213 static int nv_close(struct net_device *dev)
  4251 static int nv_close(struct net_device *dev)
  4214 {
  4252 {
  4215 	struct fe_priv *np = netdev_priv(dev);
  4253 	struct fe_priv *np = netdev_priv(dev);
  4216 	u8 __iomem *base;
  4254 	u8 __iomem *base;
  4217 
  4255 
  4218 	spin_lock_irq(&np->lock);
  4256 	if (!np->ecdev) {
  4219 	np->in_shutdown = 1;
  4257 		spin_lock_irq(&np->lock);
  4220 	spin_unlock_irq(&np->lock);
  4258 		np->in_shutdown = 1;
  4221 	netif_poll_disable(dev);
  4259 		spin_unlock_irq(&np->lock);
  4222 	synchronize_irq(dev->irq);
  4260 		netif_poll_disable(dev);
  4223 
  4261 		synchronize_irq(dev->irq);
  4224 	del_timer_sync(&np->oom_kick);
  4262 
  4225 	del_timer_sync(&np->nic_poll);
  4263 		del_timer_sync(&np->oom_kick);
  4226 	del_timer_sync(&np->stats_poll);
  4264 		del_timer_sync(&np->nic_poll);
  4227 
  4265 		del_timer_sync(&np->stats_poll);
  4228 	netif_stop_queue(dev);
  4266 
  4229 	spin_lock_irq(&np->lock);
  4267 		netif_stop_queue(dev);
       
  4268 		spin_lock_irq(&np->lock);
       
  4269 	}
       
  4270 
  4230 	nv_stop_tx(dev);
  4271 	nv_stop_tx(dev);
  4231 	nv_stop_rx(dev);
  4272 	nv_stop_rx(dev);
  4232 	nv_txrx_reset(dev);
  4273 	nv_txrx_reset(dev);
  4233 
  4274 
  4234 	/* disable interrupts on the nic or we will lock up */
  4275 	/* disable interrupts on the nic or we will lock up */
  4235 	base = get_hwbase(dev);
  4276 	base = get_hwbase(dev);
  4236 	nv_disable_hw_interrupts(dev, np->irqmask);
  4277 	if (!np->ecdev) nv_disable_hw_interrupts(dev, np->irqmask);
  4237 	pci_push(base);
  4278 	pci_push(base);
  4238 	dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
  4279 	dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
  4239 
  4280 
  4240 	spin_unlock_irq(&np->lock);
  4281 	if (!np->ecdev) {
  4241 
  4282 		spin_unlock_irq(&np->lock);
  4242 	nv_free_irq(dev);
  4283 
       
  4284 		nv_free_irq(dev);
       
  4285 	}
  4243 
  4286 
  4244 	drain_ring(dev);
  4287 	drain_ring(dev);
  4245 
  4288 
  4246 	if (np->wolenabled)
  4289 	if (np->wolenabled)
  4247 		nv_start_rx(dev);
  4290 		nv_start_rx(dev);
  4583 	np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  4626 	np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  4584 	np->duplex = 0;
  4627 	np->duplex = 0;
  4585 	np->autoneg = 1;
  4628 	np->autoneg = 1;
  4586 
  4629 
  4587 	// offer device to EtherCAT master module
  4630 	// offer device to EtherCAT master module
  4588 	if (ecdev_offer(dev, &np->ecdev, "forcedeth", board_idx,
  4631 	if (ecdev_offer(dev, &np->ecdev, "forcedeth", board_idx, ec_poll,
  4589 				ec_poll, THIS_MODULE)) {
  4632 				THIS_MODULE)) {
  4590 		printk(KERN_ERR "forcedeth: Failed to offer device.\n");
  4633 		printk(KERN_ERR "forcedeth: Failed to offer device.\n");
  4591 		goto out_error;
  4634 		goto out_error;
  4592 	}
  4635 	}
  4593 
  4636 
  4594 	if (!np->ecdev) {
  4637 	if (np->ecdev) {
       
  4638 		if (ecdev_open(np->ecdev)) {
       
  4639 			ecdev_withdraw(np->ecdev);
       
  4640 			goto out_error;
       
  4641 		}
       
  4642 	}
       
  4643 	else {
  4595 		err = register_netdev(dev);
  4644 		err = register_netdev(dev);
  4596 		if (err) {
  4645 		if (err) {
  4597 			printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
  4646 			printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
  4598 			goto out_freering;
  4647 			goto out_freering;
  4599 		}
  4648 		}
  4753 };
  4802 };
  4754 
  4803 
  4755 
  4804 
  4756 static int __init init_nic(void)
  4805 static int __init init_nic(void)
  4757 {
  4806 {
  4758 	printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION);
  4807 	printk(KERN_INFO "forcedeth: EtherCAT-capable nForce ethernet driver."
       
  4808 			" Version %s, master %s.\n",
       
  4809             FORCEDETH_VERSION, EC_MASTER_VERSION);
  4759 	return pci_register_driver(&driver);
  4810 	return pci_register_driver(&driver);
  4760 }
  4811 }
  4761 
  4812 
  4762 static void __exit exit_nic(void)
  4813 static void __exit exit_nic(void)
  4763 {
  4814 {
  4775 module_param(msix, int, 0);
  4826 module_param(msix, int, 0);
  4776 MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
  4827 MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
  4777 module_param(dma_64bit, int, 0);
  4828 module_param(dma_64bit, int, 0);
  4778 MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
  4829 MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
  4779 
  4830 
  4780 MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
  4831 MODULE_AUTHOR("Dipl.-Ing. (FH) Florian Pose <fp@igh-essen.com>");
  4781 MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
  4832 MODULE_DESCRIPTION("EtherCAT-capable nForce ethernet driver");
  4782 MODULE_LICENSE("GPL");
  4833 MODULE_LICENSE("GPL");
  4783 
  4834 
  4784 //MODULE_DEVICE_TABLE(pci, pci_tbl); // prevent auto-loading
  4835 //MODULE_DEVICE_TABLE(pci, pci_tbl); // prevent auto-loading
  4785 
  4836 
  4786 module_init(init_nic);
  4837 module_init(init_nic);