Link-State im Device.
authorFlorian Pose <fp@igh-essen.com>
Thu, 02 Mar 2006 11:19:27 +0000
changeset 96 080b46eb6e2d
parent 95 0066de7a456d
child 97 e6264685dd7b
Link-State im Device.
devices/8139too.c
include/EtherCAT_dev.h
master/device.c
master/device.h
master/domain.c
master/frame.c
--- a/devices/8139too.c	Tue Feb 28 13:07:05 2006 +0000
+++ b/devices/8139too.c	Thu Mar 02 11:19:27 2006 +0000
@@ -1471,7 +1471,12 @@
 {
 	struct rtl8139_private *tp = netdev_priv(dev);
 
-	if (tp->phys[0] >= 0) {
+        if (EtherCAT_dev_is_ec(rtl_ec_dev, dev)) {
+            void __iomem *ioaddr = tp->mmio_addr;
+            uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS;
+            EtherCAT_dev_link_state(rtl_ec_dev, state ? 1 : 0);
+        }
+        else if (tp->phys[0] >= 0) {
 		mii_check_media(&tp->mii, netif_msg_link(tp), init_media);
 	}
 }
@@ -2400,9 +2405,6 @@
 
 	if (EtherCAT_dev_is_ec(rtl_ec_dev, dev))
         {
-#if 0 // FIXME
-                rtl_ec_dev.intr_cnt++;
-#endif
                 status = RTL_R16 (IntrStatus);
 	}
 	else
--- a/include/EtherCAT_dev.h	Tue Feb 28 13:07:05 2006 +0000
+++ b/include/EtherCAT_dev.h	Thu Mar 02 11:19:27 2006 +0000
@@ -40,6 +40,7 @@
 int EtherCAT_dev_is_ec(const ec_device_t *, const struct net_device *);
 void EtherCAT_dev_state(ec_device_t *, ec_device_state_t);
 void EtherCAT_dev_receive(ec_device_t *, const void *, size_t);
+void EtherCAT_dev_link_state(ec_device_t *, uint8_t);
 
 /*****************************************************************************/
 
--- a/master/device.c	Tue Feb 28 13:07:05 2006 +0000
+++ b/master/device.c	Thu Mar 02 11:19:27 2006 +0000
@@ -39,6 +39,7 @@
     device->isr = NULL;
     device->module = NULL;
     device->error_reported = 0;
+    device->link_state = 0; // down
 
     if ((device->tx_skb = dev_alloc_skb(ETH_HLEN + EC_MAX_FRAME_SIZE)) == NULL) {
         EC_ERR("Error allocating device socket buffer!\n");
@@ -101,6 +102,7 @@
 
     // Reset old device state
     device->state = EC_DEVICE_STATE_READY;
+    device->link_state = 0;
 
     if (device->dev->open(device->dev) == 0) device->open = 1;
 
@@ -166,6 +168,10 @@
 {
     struct ethhdr *eth;
 
+    if (unlikely(!device->link_state)) { // Link down
+        return;
+    }
+
     // Framegröße auf (jetzt bekannte) Länge abschneiden
     skb_trim(device->tx_skb, length);
 
@@ -375,9 +381,26 @@
 
 /*****************************************************************************/
 
+/**
+   Setzt einen neuen Verbindungszustand.
+*/
+
+void EtherCAT_dev_link_state(ec_device_t *device, /**< EtherCAT-Gerät */
+                             uint8_t state /**< Verbindungszustand */
+                             )
+{
+    if (state != device->link_state) {
+        device->link_state = state;
+        EC_INFO("Link state changed to %s.\n", (state ? "UP" : "DOWN"));
+    }
+}
+
+/*****************************************************************************/
+
 EXPORT_SYMBOL(EtherCAT_dev_is_ec);
 EXPORT_SYMBOL(EtherCAT_dev_state);
 EXPORT_SYMBOL(EtherCAT_dev_receive);
+EXPORT_SYMBOL(EtherCAT_dev_link_state);
 
 /*****************************************************************************/
 
--- a/master/device.h	Tue Feb 28 13:07:05 2006 +0000
+++ b/master/device.h	Thu Mar 02 11:19:27 2006 +0000
@@ -43,6 +43,7 @@
                               Verfügung stellt. */
     uint8_t error_reported; /**< Zeigt an, ob ein Fehler im zyklischen Code
                                bereits gemeldet wurde. */
+    uint8_t link_state; /**< Verbindungszustand */
 };
 
 /*****************************************************************************/
--- a/master/domain.c	Tue Feb 28 13:07:05 2006 +0000
+++ b/master/domain.c	Thu Mar 02 11:19:27 2006 +0000
@@ -294,7 +294,13 @@
                           domain->data + offset);
 
         if (unlikely(ec_frame_send(frame) < 0)) {
-            EC_ERR("Could not send process data command!\n");
+            master->device.state = EC_DEVICE_STATE_READY;
+            master->frames_lost++;
+            ec_cyclic_output(master);
+
+            // Falls Link down...
+            ec_device_call_isr(&master->device);
+
             return -1;
         }
 
--- a/master/frame.c	Tue Feb 28 13:07:05 2006 +0000
+++ b/master/frame.c	Thu Mar 02 11:19:27 2006 +0000
@@ -253,6 +253,9 @@
     unsigned int command_size, frame_size, i;
     uint8_t *data;
 
+    if (unlikely(!frame->master->device.link_state))
+        return -1;
+
     if (unlikely(frame->master->debug_level > 0)) {
         EC_DBG("ec_frame_send\n");
     }