drivers/8139too.c
branchkernel2.6
changeset 24 d417dd9bdc2f
parent 23 39364fbcd069
child 25 7d124bfba3ce
equal deleted inserted replaced
23:39364fbcd069 24:d417dd9bdc2f
   107 		"rtl8139-diag -mmmaaavvveefN" output
   107 		"rtl8139-diag -mmmaaavvveefN" output
   108 		enable RTL8139_DEBUG below, and look at 'dmesg' or kernel log
   108 		enable RTL8139_DEBUG below, and look at 'dmesg' or kernel log
   109 
   109 
   110 */
   110 */
   111 
   111 
   112 #define DRV_NAME	"8139too-ecat"
   112 #define DRV_NAME	"8139too_ecat"
   113 #define DRV_VERSION	"0.9.27"
   113 #define DRV_VERSION	"0.9.27"
   114 
   114 
   115 
   115 
   116 #include <linux/config.h>
   116 #include <linux/config.h>
   117 #include <linux/module.h>
   117 #include <linux/module.h>
   197 static int ec_device_index = -1;
   197 static int ec_device_index = -1;
   198 
   198 
   199 //#define ECAT_DEBUG
   199 //#define ECAT_DEBUG
   200 
   200 
   201 EtherCAT_device_t rtl_ecat_dev;
   201 EtherCAT_device_t rtl_ecat_dev;
   202 
       
   203 EXPORT_SYMBOL(rtl_ecat_dev);
       
   204 
   202 
   205 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
   203 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
   206 
   204 
   207 /*
   205 /*
   208  * Receive ring size 
   206  * Receive ring size 
  1448           netif_start_queue (dev);
  1446           netif_start_queue (dev);
  1449         }
  1447         }
  1450 
  1448 
  1451         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1449         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1452 
  1450 
       
  1451 	//FIXME muß das hier raus ??
  1453 	if (netif_msg_ifup(tp))
  1452 	if (netif_msg_ifup(tp))
  1454 		printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#lx IRQ %d"
  1453 		printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#lx IRQ %d"
  1455 			" GP Pins %2.2x %s-duplex.\n",
  1454 			" GP Pins %2.2x %s-duplex.\n",
  1456 			dev->name, pci_resource_start (tp->pci_dev, 1),
  1455 			dev->name, pci_resource_start (tp->pci_dev, 1),
  1457 			dev->irq, RTL_R8 (MediaStatus),
  1456 			dev->irq, RTL_R8 (MediaStatus),
  1883           if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb);
  1882           if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb);
  1884           tp->stats.tx_dropped++;
  1883           tp->stats.tx_dropped++;
  1885           return 0;
  1884           return 0;
  1886 	}
  1885 	}
  1887 
  1886 
       
  1887 	if (dev != rtl_ecat_dev.dev)  //CHANGED HM spinlock falsch
       
  1888 	    spin_lock_irq(&tp->lock);
       
  1889 
  1888 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1890 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1889 
       
  1890         spin_lock_irq(&tp->lock);
       
  1891 	RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  1891 	RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  1892 		   tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
  1892 		   tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
  1893 
  1893 
  1894 	dev->trans_start = jiffies;
  1894 	dev->trans_start = jiffies;
  1895 
  1895 
  1930 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1930 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1931 
  1931 
  1932 	if (dev == rtl_ecat_dev.dev)
  1932 	if (dev == rtl_ecat_dev.dev)
  1933         {
  1933         {
  1934           rtl_ecat_dev.tx_intr_cnt++;
  1934           rtl_ecat_dev.tx_intr_cnt++;
       
  1935 	  //printk("ECAT tx interrupt\n"); // HM
  1935           rdtscl(rtl_ecat_dev.tx_time); // Get CPU cycles
  1936           rdtscl(rtl_ecat_dev.tx_time); // Get CPU cycles
  1936 	}
  1937 	}
  1937 
  1938 
  1938         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1939         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1939 
  1940 
  2153 		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  2154 		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  2154 
  2155 
  2155     /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2156     /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2156 
  2157 
  2157 	if (dev == rtl_ecat_dev.dev)
  2158 	if (dev == rtl_ecat_dev.dev)
  2158     {
  2159 	{
  2159       rtl_ecat_dev.rx_intr_cnt++;
  2160 	    rtl_ecat_dev.rx_intr_cnt++;
  2160       rdtscl(rtl_ecat_dev.rx_time); // Get CPU cycles
  2161 	    rdtscl(rtl_ecat_dev.rx_time); // Get CPU cycles
  2161 	}
  2162 	}
  2162 
  2163 
  2163 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2164 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2164 
  2165 
  2165 	while (netif_running(dev) && received < budget
  2166 	while ((dev == rtl_ecat_dev.dev || netif_running(dev)) //HM
       
  2167 	       && received < budget 
  2166 	       && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  2168 	       && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  2167 		u32 ring_offset = cur_rx % RX_BUF_LEN;
  2169 		u32 ring_offset = cur_rx % RX_BUF_LEN;
  2168 		u32 rx_status;
  2170 		u32 rx_status;
  2169 		unsigned int pkt_size;
  2171 		unsigned int pkt_size;
  2170 		struct sk_buff *skb;
  2172 		struct sk_buff *skb;
  2177 		pkt_size = rx_size - 4;
  2179 		pkt_size = rx_size - 4;
  2178 
  2180 
  2179         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2181         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2180 
  2182 
  2181 		if (dev != rtl_ecat_dev.dev && netif_msg_rx_status(tp))
  2183 		if (dev != rtl_ecat_dev.dev && netif_msg_rx_status(tp))
  2182           printk(KERN_DEBUG "%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  2184 		    printk(KERN_DEBUG "%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  2183                  " cur %4.4x.\n", dev->name, rx_status,
  2185 			   " cur %4.4x.\n", dev->name, rx_status,
  2184                  rx_size, cur_rx);
  2186 			   rx_size, cur_rx);
  2185 
  2187 
  2186         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2188         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2187 
  2189 
  2188 #if RTL8139_DEBUG > 2
  2190 #if RTL8139_DEBUG > 2
  2189 		{
  2191 		{
  2385 	if (done) {
  2387 	if (done) {
  2386 		/*
  2388 		/*
  2387 		 * Order is important since data can get interrupted
  2389 		 * Order is important since data can get interrupted
  2388 		 * again when we think we are done.
  2390 		 * again when we think we are done.
  2389 		 */
  2391 		 */
       
  2392 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2393 	    if (dev != rtl_ecat_dev.dev) {
       
  2394 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2390 		local_irq_disable();
  2395 		local_irq_disable();
  2391 		RTL_W16_F(IntrMask, rtl8139_intr_mask);
  2396 		RTL_W16_F(IntrMask, rtl8139_intr_mask);  //Interrupts werden nicht enabled ?? HM
  2392 		__netif_rx_complete(dev);
  2397 		__netif_rx_complete(dev);
  2393 		local_irq_enable();
  2398 		local_irq_enable();
       
  2399 	    }
       
  2400 //	    else
       
  2401 
  2394 	}
  2402 	}
  2395 	spin_unlock(&tp->rx_lock);
  2403 	spin_unlock(&tp->rx_lock);
  2396 
  2404 
  2397 	return !done;
  2405 	return !done;
  2398 }
  2406 }
  2412         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2420         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2413 
  2421 
  2414 	if (dev == rtl_ecat_dev.dev)
  2422 	if (dev == rtl_ecat_dev.dev)
  2415         {
  2423         {
  2416           rtl_ecat_dev.intr_cnt++;
  2424           rtl_ecat_dev.intr_cnt++;
       
  2425 
  2417 	}
  2426 	}
  2418 	else
  2427 	else
  2419         {
  2428         {
  2420           spin_lock(&tp->lock);
  2429           spin_lock(&tp->lock);
  2421         }
  2430         }
  2423         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2432         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2424 
  2433 
  2425 	status = RTL_R16 (IntrStatus);
  2434 	status = RTL_R16 (IntrStatus);
  2426 
  2435 
  2427         /* shared irq? */
  2436         /* shared irq? */
  2428 	if (unlikely((status & rtl8139_intr_mask) == 0))
  2437         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2438 	if (dev != rtl_ecat_dev.dev)
       
  2439 	    if (unlikely((status & rtl8139_intr_mask) == 0))
  2429 		goto out;
  2440 		goto out;
       
  2441         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2430 
  2442 
  2431 	handled = 1;
  2443 	handled = 1;
  2432 
  2444 
  2433 	/* h/w no longer present (hotplug?) or major error, bail */
  2445 	/* h/w no longer present (hotplug?) or major error, bail */
  2434 	if (unlikely(status == 0xFFFF))
  2446 	if (unlikely(status == 0xFFFF))
  2435 		goto out;
  2447 		goto out;
  2436 
  2448 
  2437 	/* close possible race's with dev_close */
  2449 	/* close possible race's with dev_close */
  2438 	if (unlikely(!netif_running(dev))) {
  2450         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2451 	if (dev != rtl_ecat_dev.dev) {
       
  2452 	    if (unlikely(!netif_running(dev))) {
  2439 		RTL_W16 (IntrMask, 0);
  2453 		RTL_W16 (IntrMask, 0);
  2440 		goto out;
  2454 		goto out;
  2441 	}
  2455 	    }
  2442 
  2456 	}
       
  2457         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2443 	/* Acknowledge all of the current interrupt sources ASAP, but
  2458 	/* Acknowledge all of the current interrupt sources ASAP, but
  2444 	   an first get an additional status bit from CSCR. */
  2459 	   an first get an additional status bit from CSCR. */
  2445 	if (unlikely(status & RxUnderrun))
  2460 	if (unlikely(status & RxUnderrun))
  2446 		link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  2461 		link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  2447 
  2462 
  2448 	ackstat = status & ~(RxAckBits | TxErr);
  2463 	ackstat = status & ~(RxAckBits | TxErr);
  2449 	if (ackstat)
  2464 	if (ackstat) {
  2450 		RTL_W16 (IntrStatus, ackstat);
  2465 		RTL_W16 (IntrStatus, ackstat);
       
  2466 		//printk("ECAT-NIC ack\n"); //HM
       
  2467 	}
  2451 
  2468 
  2452 	/* Receive packets are processed by poll routine.
  2469 	/* Receive packets are processed by poll routine.
  2453 	   If not running start it now. */
  2470 	   If not running start it now. */
       
  2471 
       
  2472         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2454 	if (status & RxAckBits){
  2473 	if (status & RxAckBits){
       
  2474 	    // printk("ECAT-NIC RX-Intr Flag\n"); // HM
       
  2475 	    if (dev != rtl_ecat_dev.dev) {
  2455 		if (netif_rx_schedule_prep(dev)) {
  2476 		if (netif_rx_schedule_prep(dev)) {
  2456 			RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  2477 		    RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  2457 			__netif_rx_schedule (dev);
  2478 		    __netif_rx_schedule (dev);
  2458 		}
  2479 		}
       
  2480 	    }
       
  2481 //	    else
       
  2482 
  2459 	}
  2483 	}
  2460 
  2484 
  2461 	/* Check uncommon events with one test. */
  2485 	/* Check uncommon events with one test. */
  2462 	if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr)))
  2486 	if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr)))
  2463 		rtl8139_weird_interrupt (dev, tp, ioaddr,
  2487 		rtl8139_weird_interrupt (dev, tp, ioaddr,
  2506         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2530         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2507 
  2531 
  2508         if (dev != rtl_ecat_dev.dev)
  2532         if (dev != rtl_ecat_dev.dev)
  2509         {
  2533         {
  2510 	    netif_stop_queue(dev);
  2534 	    netif_stop_queue(dev);
  2511         }
  2535 	    if (tp->thr_pid >= 0) {
  2512 
       
  2513         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2514 
       
  2515         if (tp->thr_pid >= 0) {
       
  2516 		tp->time_to_die = 1;
  2536 		tp->time_to_die = 1;
  2517 		wmb();
  2537 		wmb();
  2518 		ret = kill_proc (tp->thr_pid, SIGTERM, 1);
  2538 		ret = kill_proc (tp->thr_pid, SIGTERM, 1);
  2519 		if (ret) {
  2539 		if (ret) {
  2520 			printk (KERN_ERR "%s: unable to signal thread\n", dev->name);
  2540 		    printk (KERN_ERR "%s: unable to signal thread\n", dev->name);
  2521 			return ret;
  2541 		    return ret;
  2522 		}
  2542 		}
  2523 		wait_for_completion (&tp->thr_exited);
  2543 		wait_for_completion (&tp->thr_exited);
  2524         }
  2544 	    }
       
  2545 	}
  2525 
  2546 
  2526         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2547         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2527 
  2548 
  2528         if (dev != rtl_ecat_dev.dev)
  2549         if (dev != rtl_ecat_dev.dev)
  2529         {
  2550         {
  2532                    dev->name, RTL_R16 (IntrStatus));
  2553                    dev->name, RTL_R16 (IntrStatus));
  2533         }
  2554         }
  2534 
  2555 
  2535         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2556         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2536 
  2557 
  2537         spin_lock_irqsave (&tp->lock, flags);
  2558         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2559         if (dev != rtl_ecat_dev.dev)
       
  2560         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2561 	    spin_lock_irqsave (&tp->lock, flags);
  2538 
  2562 
  2539 	/* Stop the chip's Tx and Rx DMA processes. */
  2563 	/* Stop the chip's Tx and Rx DMA processes. */
  2540 	RTL_W8 (ChipCmd, 0);
  2564 	RTL_W8 (ChipCmd, 0);
  2541 
  2565 
  2542 	/* Disable interrupts by clearing the interrupt mask. */
  2566 	/* Disable interrupts by clearing the interrupt mask. */
  2544 
  2568 
  2545 	/* Update the error counts. */
  2569 	/* Update the error counts. */
  2546 	tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  2570 	tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  2547 	RTL_W32 (RxMissed, 0);
  2571 	RTL_W32 (RxMissed, 0);
  2548 
  2572 
  2549         spin_unlock_irqrestore (&tp->lock, flags);
  2573         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2574         if (dev != rtl_ecat_dev.dev)
       
  2575         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2576 	    spin_unlock_irqrestore (&tp->lock, flags);
  2550 
  2577 
  2551         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2578         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2552 
  2579 
  2553         if (dev != rtl_ecat_dev.dev)
  2580         if (dev != rtl_ecat_dev.dev)
  2554         {
  2581         {
  2972 }
  2999 }
  2973 
  3000 
  2974 
  3001 
  2975 module_init(rtl8139_init_module);
  3002 module_init(rtl8139_init_module);
  2976 module_exit(rtl8139_cleanup_module);
  3003 module_exit(rtl8139_cleanup_module);
       
  3004 
       
  3005 EXPORT_SYMBOL(rtl_ecat_dev);