From 0ffbd968a669cf754c0b6015109a48f6b6ed0fa4 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Thu, 2 Mar 2006 11:19:27 +0000 Subject: [PATCH] Link-State im Device. --- devices/8139too.c | 10 ++++++---- include/EtherCAT_dev.h | 1 + master/device.c | 23 +++++++++++++++++++++++ master/device.h | 1 + master/domain.c | 8 +++++++- master/frame.c | 3 +++ 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/devices/8139too.c b/devices/8139too.c index 02c44788..eaa32e4a 100644 --- a/devices/8139too.c +++ b/devices/8139too.c @@ -1471,7 +1471,12 @@ static void rtl_check_media (struct net_device *dev, unsigned int init_media) { 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 @@ irqreturn_t rtl8139_interrupt (int irq, void *dev_instance, if (EtherCAT_dev_is_ec(rtl_ec_dev, dev)) { -#if 0 // FIXME - rtl_ec_dev.intr_cnt++; -#endif status = RTL_R16 (IntrStatus); } else diff --git a/include/EtherCAT_dev.h b/include/EtherCAT_dev.h index 7f397242..6bd682ba 100644 --- a/include/EtherCAT_dev.h +++ b/include/EtherCAT_dev.h @@ -40,6 +40,7 @@ void EtherCAT_dev_unregister(unsigned int, ec_device_t *); 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); /*****************************************************************************/ diff --git a/master/device.c b/master/device.c index 7018dd12..8c7306a4 100644 --- a/master/device.c +++ b/master/device.c @@ -39,6 +39,7 @@ int ec_device_init(ec_device_t *device, /**< EtherCAT-Ger 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 @@ int ec_device_open(ec_device_t *device /**< EtherCAT-Ger // 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 @@ void ec_device_send(ec_device_t *device, /**< EtherCAT-Ger { 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 @@ void EtherCAT_dev_receive(ec_device_t *device, /**< EtherCAT-Ger /*****************************************************************************/ +/** + 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); /*****************************************************************************/ diff --git a/master/device.h b/master/device.h index 26bade5d..d93699c9 100644 --- a/master/device.h +++ b/master/device.h @@ -43,6 +43,7 @@ struct ec_device Verfügung stellt. */ uint8_t error_reported; /**< Zeigt an, ob ein Fehler im zyklischen Code bereits gemeldet wurde. */ + uint8_t link_state; /**< Verbindungszustand */ }; /*****************************************************************************/ diff --git a/master/domain.c b/master/domain.c index 4600fca6..889b1d62 100644 --- a/master/domain.c +++ b/master/domain.c @@ -294,7 +294,13 @@ int EtherCAT_rt_domain_xio(ec_domain_t *domain /**< Dom 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; } diff --git a/master/frame.c b/master/frame.c index 7d1a4baa..9b301e99 100644 --- a/master/frame.c +++ b/master/frame.c @@ -253,6 +253,9 @@ int ec_frame_send(ec_frame_t *frame /**< Rahmen zum Senden */) 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"); }