devices/forcedeth-2.6.17-ethercat.c
changeset 592 6ca369325cdd
parent 581 99623f8a8493
child 639 aa23c48dca2d
equal deleted inserted replaced
591:2b949dcba32b 592:6ca369325cdd
   605 	/* msi/msi-x fields */
   605 	/* msi/msi-x fields */
   606 	u32 msi_flags;
   606 	u32 msi_flags;
   607 	struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
   607 	struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
   608 
   608 
   609     ec_device_t *ecdev;
   609     ec_device_t *ecdev;
   610 	u8 rx_data[ETH_FRAME_LEN];
       
   611 };
   610 };
   612 
   611 
   613 /*
   612 /*
   614  * Maximum number of loops until we assume that a bit in the irq mask
   613  * Maximum number of loops until we assume that a bit in the irq mask
   615  * is stuck. Overridable with module param.
   614  * is stuck. Overridable with module param.
  1249 
  1248 
  1250 		if ((np->next_tx - np->nic_tx + entries - 1) > TX_LIMIT_STOP) {
  1249 		if ((np->next_tx - np->nic_tx + entries - 1) > TX_LIMIT_STOP) {
  1251 			spin_unlock_irq(&np->lock);
  1250 			spin_unlock_irq(&np->lock);
  1252 			netif_stop_queue(dev);
  1251 			netif_stop_queue(dev);
  1253 			return NETDEV_TX_BUSY;
  1252 			return NETDEV_TX_BUSY;
  1254 		}
  1253         }
  1255 	}
  1254 	}
  1256 
  1255 
  1257 	/* setup the header buffer */
  1256 	/* setup the header buffer */
  1258 	do {
  1257 	do {
  1259 		bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
  1258 		bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
  1590 		 * the performance.
  1589 		 * the performance.
  1591 		 */
  1590 		 */
  1592 		pci_unmap_single(np->pci_dev, np->rx_dma[i],
  1591 		pci_unmap_single(np->pci_dev, np->rx_dma[i],
  1593 				np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
  1592 				np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
  1594 				PCI_DMA_FROMDEVICE);
  1593 				PCI_DMA_FROMDEVICE);
       
  1594 
  1595 		{
  1595 		{
  1596 			int j;
  1596 			int j;
  1597 			dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",Flags);
  1597 			dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",Flags);
  1598 			for (j=0; j<64; j++) {
  1598 			for (j=0; j<64; j++) {
  1599 				if ((j%16) == 0)
  1599 				if ((j%16) == 0)
  1693 			np->rx_skbuff[i] = NULL;
  1693 			np->rx_skbuff[i] = NULL;
  1694 
  1694 
  1695 			skb_put(skb, len);
  1695 			skb_put(skb, len);
  1696 			skb->protocol = eth_type_trans(skb, dev);
  1696 			skb->protocol = eth_type_trans(skb, dev);
  1697 			dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
  1697 			dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
  1698 						dev->name, np->cur_rx, len, skb->protocol);
  1698 					dev->name, np->cur_rx, len, skb->protocol);
  1699 			if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT)) {
  1699 			if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT)) {
  1700 				vlan_hwaccel_rx(skb, np->vlangrp, vlanflags & NV_RX3_VLAN_TAG_MASK);
  1700 				vlan_hwaccel_rx(skb, np->vlangrp, vlanflags & NV_RX3_VLAN_TAG_MASK);
  1701 			} else {
  1701 			} else {
  1702 				netif_rx(skb);
  1702 				netif_rx(skb);
  1703 			}
  1703 			}
  2050 static void nv_linkchange(struct net_device *dev)
  2050 static void nv_linkchange(struct net_device *dev)
  2051 {
  2051 {
  2052 	struct fe_priv *np = netdev_priv(dev);
  2052 	struct fe_priv *np = netdev_priv(dev);
  2053 
  2053 
  2054     if (np->ecdev) {
  2054     if (np->ecdev) {
  2055         nv_update_linkspeed(dev);
  2055         int link = nv_update_linkspeed(dev);
       
  2056         ecdev_link_state(np->ecdev, link);
  2056         return;
  2057         return;
  2057     }
  2058     }
  2058 
  2059 
  2059 	if (nv_update_linkspeed(dev)) {
  2060 	if (nv_update_linkspeed(dev)) {
  2060 		if (!netif_carrier_ok(dev)) {
  2061 		if (!netif_carrier_ok(dev)) {
  2106 		pci_push(base);
  2107 		pci_push(base);
  2107 		dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
  2108 		dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
  2108 		if (!(events & np->irqmask))
  2109 		if (!(events & np->irqmask))
  2109 			break;
  2110 			break;
  2110 
  2111 
  2111 		spin_lock(&np->lock);
  2112 		if (!np->ecdev) spin_lock(&np->lock);
  2112 		nv_tx_done(dev);
  2113 		nv_tx_done(dev);
  2113 		spin_unlock(&np->lock);
  2114 		if (!np->ecdev) spin_unlock(&np->lock);
  2114 		
  2115 		
  2115 		nv_rx_process(dev);
  2116 		nv_rx_process(dev);
  2116 		if (nv_alloc_rx(dev)) {
  2117 		if (nv_alloc_rx(dev)) {
  2117 			spin_lock(&np->lock);
  2118 			spin_lock(&np->lock);
  2118 			if (!np->in_shutdown)
  2119 			if (!np->in_shutdown)
  2119 				mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2120 				mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2120 			spin_unlock(&np->lock);
  2121 			spin_unlock(&np->lock);
  2121 		}
  2122 		}
  2122 		
  2123 		
  2123 		if (events & NVREG_IRQ_LINK) {
  2124 		if (events & NVREG_IRQ_LINK) {
  2124 			spin_lock(&np->lock);
  2125 			if (!np->ecdev) spin_lock(&np->lock);
  2125 			nv_link_irq(dev);
  2126 			nv_link_irq(dev);
  2126 			spin_unlock(&np->lock);
  2127 			if (!np->ecdev) spin_unlock(&np->lock);
  2127 		}
  2128 		}
  2128 		if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  2129 		if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  2129 			spin_lock(&np->lock);
  2130 			if (!np->ecdev) spin_lock(&np->lock);
  2130 			nv_linkchange(dev);
  2131 			nv_linkchange(dev);
  2131 			spin_unlock(&np->lock);
  2132 			if (!np->ecdev) spin_unlock(&np->lock);
  2132 			np->link_timeout = jiffies + LINK_TIMEOUT;
  2133 			np->link_timeout = jiffies + LINK_TIMEOUT;
  2133 		}
  2134 		}
  2134 		if (events & (NVREG_IRQ_TX_ERR)) {
  2135 		if (events & (NVREG_IRQ_TX_ERR)) {
  2135 			dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
  2136 			dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
  2136 						dev->name, events);
  2137 						dev->name, events);
  2138 		if (events & (NVREG_IRQ_UNKNOWN)) {
  2139 		if (events & (NVREG_IRQ_UNKNOWN)) {
  2139 			printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
  2140 			printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
  2140 						dev->name, events);
  2141 						dev->name, events);
  2141 		}
  2142 		}
  2142 		if (i > max_interrupt_work) {
  2143 		if (i > max_interrupt_work) {
  2143 			spin_lock(&np->lock);
  2144 			if (!np->ecdev) {
  2144 			/* disable interrupts on the nic */
  2145 				spin_lock(&np->lock);
  2145 			if (!(np->msi_flags & NV_MSI_X_ENABLED))
  2146 				/* disable interrupts on the nic */
  2146 				writel(0, base + NvRegIrqMask);
  2147 				if (!(np->msi_flags & NV_MSI_X_ENABLED))
  2147 			else
  2148 					writel(0, base + NvRegIrqMask);
  2148 				writel(np->irqmask, base + NvRegIrqMask);
  2149 				else
  2149 			pci_push(base);
  2150 					writel(np->irqmask, base + NvRegIrqMask);
  2150 
  2151 				pci_push(base);
  2151 			if (!np->in_shutdown) {
  2152 
  2152 				np->nic_poll_irq = np->irqmask;
  2153 				if (!np->in_shutdown) {
  2153 				mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  2154 					np->nic_poll_irq = np->irqmask;
       
  2155 					mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
       
  2156 				}
       
  2157 				spin_unlock(&np->lock);
  2154 			}
  2158 			}
  2155 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
  2159 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
  2156 			spin_unlock(&np->lock);
       
  2157 			break;
  2160 			break;
  2158 		}
  2161 		}
  2159 
  2162 
  2160 	}
  2163 	}
  2161 	dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
  2164 	dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
  2179 		pci_push(base);
  2182 		pci_push(base);
  2180 		dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
  2183 		dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
  2181 		if (!(events & np->irqmask))
  2184 		if (!(events & np->irqmask))
  2182 			break;
  2185 			break;
  2183 
  2186 
  2184 		spin_lock_irq(&np->lock);
  2187 		if (!np->ecdev) spin_lock_irq(&np->lock);
  2185 		nv_tx_done(dev);
  2188 		nv_tx_done(dev);
  2186 		spin_unlock_irq(&np->lock);
  2189 		if (!np->ecdev) spin_unlock_irq(&np->lock);
  2187 		
  2190 		
  2188 		if (events & (NVREG_IRQ_TX_ERR)) {
  2191 		if (events & (NVREG_IRQ_TX_ERR)) {
  2189 			dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
  2192 			dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
  2190 						dev->name, events);
  2193 						dev->name, events);
  2191 		}
  2194 		}
  2192 		if (i > max_interrupt_work) {
  2195 		if (i > max_interrupt_work) {
  2193 			spin_lock_irq(&np->lock);
  2196 			if (!np->ecdev) { 
  2194 			/* disable interrupts on the nic */
  2197 				spin_lock_irq(&np->lock);
  2195 			writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
  2198 				/* disable interrupts on the nic */
  2196 			pci_push(base);
  2199 				writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
  2197 
  2200 				pci_push(base);
  2198 			if (!np->in_shutdown) {
  2201 
  2199 				np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
  2202 				if (!np->in_shutdown) {
  2200 				mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  2203 					np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
       
  2204 					mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
       
  2205 				}
       
  2206 				spin_unlock_irq(&np->lock);
  2201 			}
  2207 			}
  2202 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
  2208 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
  2203 			spin_unlock_irq(&np->lock);
       
  2204 			break;
  2209 			break;
  2205 		}
  2210 		}
  2206 
  2211 
  2207 	}
  2212 	}
  2208 	dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
  2213 	dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
  2227 		dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
  2232 		dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
  2228 		if (!(events & np->irqmask))
  2233 		if (!(events & np->irqmask))
  2229 			break;
  2234 			break;
  2230 		
  2235 		
  2231 		nv_rx_process(dev);
  2236 		nv_rx_process(dev);
  2232 		if (nv_alloc_rx(dev)) {
  2237 		if (nv_alloc_rx(dev) && !np->ecdev) {
  2233 			spin_lock_irq(&np->lock);
  2238 			spin_lock_irq(&np->lock);
  2234 			if (!np->in_shutdown)
  2239 			if (!np->in_shutdown)
  2235 				mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2240 				mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2236 			spin_unlock_irq(&np->lock);
  2241 			spin_unlock_irq(&np->lock);
  2237 		}
  2242 		}
  2238 		
  2243 		
  2239 		if (i > max_interrupt_work) {
  2244 		if (i > max_interrupt_work) {
  2240 			spin_lock_irq(&np->lock);
  2245 			if (!np->ecdev) {
  2241 			/* disable interrupts on the nic */
  2246 				spin_lock_irq(&np->lock);
  2242 			writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
  2247 				/* disable interrupts on the nic */
  2243 			pci_push(base);
  2248 				writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
  2244 
  2249 				pci_push(base);
  2245 			if (!np->in_shutdown) {
  2250 
  2246 				np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
  2251 				if (!np->in_shutdown) {
  2247 				mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  2252 					np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
       
  2253 					mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
       
  2254 				}
       
  2255 				spin_unlock_irq(&np->lock);
  2248 			}
  2256 			}
  2249 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
  2257 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
  2250 			spin_unlock_irq(&np->lock);
       
  2251 			break;
  2258 			break;
  2252 		}
  2259 		}
  2253 
  2260 
  2254 	}
  2261 	}
  2255 	dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
  2262 	dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
  2274 		dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
  2281 		dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
  2275 		if (!(events & np->irqmask))
  2282 		if (!(events & np->irqmask))
  2276 			break;
  2283 			break;
  2277 		
  2284 		
  2278 		if (events & NVREG_IRQ_LINK) {
  2285 		if (events & NVREG_IRQ_LINK) {
  2279 			spin_lock_irq(&np->lock);
  2286 			if (!np->ecdev) spin_lock_irq(&np->lock);
  2280 			nv_link_irq(dev);
  2287 			nv_link_irq(dev);
  2281 			spin_unlock_irq(&np->lock);
  2288 			if (!np->ecdev) spin_unlock_irq(&np->lock);
  2282 		}
  2289 		}
  2283 		if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  2290 		if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  2284 			spin_lock_irq(&np->lock);
  2291 			if (!np->ecdev) spin_lock_irq(&np->lock);
  2285 			nv_linkchange(dev);
  2292 			nv_linkchange(dev);
  2286 			spin_unlock_irq(&np->lock);
  2293 			if (!np->ecdev) spin_unlock_irq(&np->lock);
  2287 			np->link_timeout = jiffies + LINK_TIMEOUT;
  2294 			np->link_timeout = jiffies + LINK_TIMEOUT;
  2288 		}
  2295 		}
  2289 		if (events & (NVREG_IRQ_UNKNOWN)) {
  2296 		if (events & (NVREG_IRQ_UNKNOWN)) {
  2290 			printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
  2297 			printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
  2291 						dev->name, events);
  2298 						dev->name, events);
  2292 		}
  2299 		}
  2293 		if (i > max_interrupt_work) {
  2300 		if (i > max_interrupt_work) {
  2294 			spin_lock_irq(&np->lock);
  2301 			if (!np->ecdev) { 
  2295 			/* disable interrupts on the nic */
  2302 				spin_lock_irq(&np->lock);
  2296 			writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
  2303 				/* disable interrupts on the nic */
  2297 			pci_push(base);
  2304 				writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
  2298 
  2305 				pci_push(base);
  2299 			if (!np->in_shutdown) {
  2306 
  2300 				np->nic_poll_irq |= NVREG_IRQ_OTHER;
  2307 				if (!np->in_shutdown) {
  2301 				mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  2308 					np->nic_poll_irq |= NVREG_IRQ_OTHER;
       
  2309 					mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
       
  2310 				}
       
  2311 				spin_unlock_irq(&np->lock);
  2302 			}
  2312 			}
  2303 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
  2313 			printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
  2304 			spin_unlock_irq(&np->lock);
       
  2305 			break;
  2314 			break;
  2306 		}
  2315 		}
  2307 
  2316 
  2308 	}
  2317 	}
  2309 	dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
  2318 	dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
  2311 	return IRQ_RETVAL(i);
  2320 	return IRQ_RETVAL(i);
  2312 }
  2321 }
  2313 
  2322 
  2314 void ec_poll(struct net_device *dev)
  2323 void ec_poll(struct net_device *dev)
  2315 {
  2324 {
  2316     nv_nic_irq((int) 0, dev, (struct pt_regs *) NULL);
  2325 	struct fe_priv *np = netdev_priv(dev);
       
  2326 
       
  2327 	if (!using_multi_irqs(dev)) {
       
  2328 		nv_nic_irq((int) 0, dev, (struct pt_regs *) NULL);
       
  2329 	} else {
       
  2330 		if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
       
  2331 			nv_nic_irq_rx((int) 0, dev, (struct pt_regs *) NULL);
       
  2332 		}
       
  2333 		if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
       
  2334 			nv_nic_irq_tx((int) 0, dev, (struct pt_regs *) NULL);
       
  2335 		}
       
  2336 		if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
       
  2337 			nv_nic_irq_other((int) 0, dev, (struct pt_regs *) NULL);
       
  2338 		}
       
  2339 	}
  2317 }
  2340 }
  2318 
  2341 
  2319 static void nv_do_nic_poll(unsigned long data)
  2342 static void nv_do_nic_poll(unsigned long data)
  2320 {
  2343 {
  2321 	struct net_device *dev = (struct net_device *) data;
  2344 	struct net_device *dev = (struct net_device *) data;
  2927 	pci_push(base);
  2950 	pci_push(base);
  2928 	writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
  2951 	writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
  2929 	writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  2952 	writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  2930 	pci_push(base);
  2953 	pci_push(base);
  2931 
  2954 
  2932 	if (nv_request_irq(dev)) {
  2955 	if (!np->ecdev) {
  2933 		goto out_drain;
  2956 		if (nv_request_irq(dev)) {
  2934 	}
  2957 			goto out_drain;
  2935 
  2958         }
  2936 	/* ask for interrupts */
  2959 
  2937 	nv_enable_hw_interrupts(dev, np->irqmask);
  2960 		/* ask for interrupts */
  2938 
  2961 		nv_enable_hw_interrupts(dev, np->irqmask);
  2939 	spin_lock_irq(&np->lock);
  2962 
       
  2963 		spin_lock_irq(&np->lock);
       
  2964 	}
       
  2965 
  2940 	writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
  2966 	writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
  2941 	writel(0, base + NvRegMulticastAddrB);
  2967 	writel(0, base + NvRegMulticastAddrB);
  2942 	writel(0, base + NvRegMulticastMaskA);
  2968 	writel(0, base + NvRegMulticastMaskA);
  2943 	writel(0, base + NvRegMulticastMaskB);
  2969 	writel(0, base + NvRegMulticastMaskB);
  2944 	writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
  2970 	writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
  2955 	 * to init hw */
  2981 	 * to init hw */
  2956 	np->linkspeed = 0;
  2982 	np->linkspeed = 0;
  2957 	ret = nv_update_linkspeed(dev);
  2983 	ret = nv_update_linkspeed(dev);
  2958 	nv_start_rx(dev);
  2984 	nv_start_rx(dev);
  2959 	nv_start_tx(dev);
  2985 	nv_start_tx(dev);
  2960 	netif_start_queue(dev);
  2986 
  2961 	if (ret) {
  2987 	if (np->ecdev) {
  2962 		netif_carrier_on(dev);
  2988 		ecdev_link_state(np->ecdev, ret);
  2963 	} else {
  2989 	}
  2964 		printk("%s: no link during initialization.\n", dev->name);
  2990 	else {
  2965 		netif_carrier_off(dev);
  2991 		netif_start_queue(dev);
  2966 	}
  2992 		if (ret) {
  2967 	if (oom)
  2993 			netif_carrier_on(dev);
  2968 		mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2994 		} else {
  2969 	spin_unlock_irq(&np->lock);
  2995 			printk("%s: no link during initialization.\n", dev->name);
       
  2996 			netif_carrier_off(dev);
       
  2997 		}
       
  2998 		if (oom)
       
  2999 			mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
       
  3000         spin_unlock_irq(&np->lock);
       
  3001 	}
  2970 
  3002 
  2971 	return 0;
  3003 	return 0;
  2972 out_drain:
  3004 out_drain:
  2973 	drain_ring(dev);
  3005 	drain_ring(dev);
  2974 	return ret;
  3006 	return ret;
  2977 static int nv_close(struct net_device *dev)
  3009 static int nv_close(struct net_device *dev)
  2978 {
  3010 {
  2979 	struct fe_priv *np = netdev_priv(dev);
  3011 	struct fe_priv *np = netdev_priv(dev);
  2980 	u8 __iomem *base;
  3012 	u8 __iomem *base;
  2981 
  3013 
  2982 	spin_lock_irq(&np->lock);
  3014 	if (!np->ecdev) {
  2983 	np->in_shutdown = 1;
  3015 		spin_lock_irq(&np->lock);
  2984 	spin_unlock_irq(&np->lock);
  3016 		np->in_shutdown = 1;
  2985 	synchronize_irq(dev->irq);
  3017 		spin_unlock_irq(&np->lock);
  2986 
  3018 		synchronize_irq(dev->irq);
  2987 	del_timer_sync(&np->oom_kick);
  3019 
  2988 	del_timer_sync(&np->nic_poll);
  3020 		del_timer_sync(&np->oom_kick);
  2989 
  3021 		del_timer_sync(&np->nic_poll);
  2990 	netif_stop_queue(dev);
  3022 
  2991 	spin_lock_irq(&np->lock);
  3023 		netif_stop_queue(dev);
       
  3024 		spin_lock_irq(&np->lock);
       
  3025 	}
       
  3026 
  2992 	nv_stop_tx(dev);
  3027 	nv_stop_tx(dev);
  2993 	nv_stop_rx(dev);
  3028 	nv_stop_rx(dev);
  2994 	nv_txrx_reset(dev);
  3029 	nv_txrx_reset(dev);
  2995 
  3030 
  2996 	/* disable interrupts on the nic or we will lock up */
  3031     base = get_hwbase(dev);
  2997 	base = get_hwbase(dev);
  3032 
  2998 	nv_disable_hw_interrupts(dev, np->irqmask);
  3033 	if (!np->ecdev) {
  2999 	pci_push(base);
  3034 		/* disable interrupts on the nic or we will lock up */
  3000 	dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
  3035 		nv_disable_hw_interrupts(dev, np->irqmask);
  3001 
  3036 		pci_push(base);
  3002 	spin_unlock_irq(&np->lock);
  3037 		dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
  3003 
  3038 
  3004 	nv_free_irq(dev);
  3039 		spin_unlock_irq(&np->lock);
       
  3040 
       
  3041 		nv_free_irq(dev);
       
  3042 	}
  3005 
  3043 
  3006 	drain_ring(dev);
  3044 	drain_ring(dev);
  3007 
  3045 
  3008 	if (np->wolenabled)
  3046 	if (np->wolenabled)
  3009 		nv_start_rx(dev);
  3047 		nv_start_rx(dev);
  3296 	np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  3334 	np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  3297 	np->duplex = 0;
  3335 	np->duplex = 0;
  3298 	np->autoneg = 1;
  3336 	np->autoneg = 1;
  3299 
  3337 
  3300 	// offer device to EtherCAT master module
  3338 	// offer device to EtherCAT master module
  3301 	if (ecdev_offer(dev, &np->ecdev, "forcedeth", board_idx,
  3339 	if (ecdev_offer(dev, &np->ecdev, "forcedeth", board_idx, ec_poll,
  3302 				ec_poll, THIS_MODULE)) {
  3340 				THIS_MODULE)) {
  3303 		printk(KERN_ERR "forcedeth: Failed to offer device.\n");
  3341 		printk(KERN_ERR "forcedeth: Failed to offer device.\n");
  3304 		goto out_freering;
  3342 		goto out_freering;
  3305 	}
  3343 	}
  3306 
  3344 
  3307 	if (!np->ecdev) {
  3345 	if (np->ecdev) {
       
  3346 		if (ecdev_open(np->ecdev)) {
       
  3347 			ecdev_withdraw(np->ecdev);
       
  3348 			goto out_freering;
       
  3349 		}
       
  3350 	}
       
  3351 	else {
  3308 		err = register_netdev(dev);
  3352 		err = register_netdev(dev);
  3309 		if (err) {
  3353 		if (err) {
  3310 			printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
  3354 			printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
  3311 			goto out_freering;
  3355 			goto out_freering;
  3312 		}
  3356 		}
  3434 };
  3478 };
  3435 
  3479 
  3436 
  3480 
  3437 static int __init init_nic(void)
  3481 static int __init init_nic(void)
  3438 {
  3482 {
  3439 	printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION);
  3483 	printk(KERN_INFO "forcedeth: EtherCAT-capable nForce ethernet driver."
       
  3484 			" Version %s, master %s.\n",
       
  3485             FORCEDETH_VERSION, EC_MASTER_VERSION);
  3440 	return pci_module_init(&driver);
  3486 	return pci_module_init(&driver);
  3441 }
  3487 }
  3442 
  3488 
  3443 static void __exit exit_nic(void)
  3489 static void __exit exit_nic(void)
  3444 {
  3490 {
  3454 module_param(disable_msi, int, 0);
  3500 module_param(disable_msi, int, 0);
  3455 MODULE_PARM_DESC(disable_msi, "Disable MSI interrupts by setting to 1.");
  3501 MODULE_PARM_DESC(disable_msi, "Disable MSI interrupts by setting to 1.");
  3456 module_param(disable_msix, int, 0);
  3502 module_param(disable_msix, int, 0);
  3457 MODULE_PARM_DESC(disable_msix, "Disable MSIX interrupts by setting to 1.");
  3503 MODULE_PARM_DESC(disable_msix, "Disable MSIX interrupts by setting to 1.");
  3458 
  3504 
  3459 MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
  3505 MODULE_AUTHOR("Dipl.-Ing. (FH) Florian Pose <fp@igh-essen.com>");
  3460 MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
  3506 MODULE_DESCRIPTION("EtherCAT-capable nForce ethernet driver");
  3461 MODULE_LICENSE("GPL");
  3507 MODULE_LICENSE("GPL");
  3462 
  3508 
  3463 //MODULE_DEVICE_TABLE(pci, pci_tbl); // prevent auto-loading
  3509 //MODULE_DEVICE_TABLE(pci, pci_tbl); // prevent auto-loading
  3464 
  3510 
  3465 module_init(init_nic);
  3511 module_init(init_nic);