diff -r 1a7067207637 -r 7bc131b92039 master/ethernet.c --- a/master/ethernet.c Fri Aug 10 15:08:44 2007 +0000 +++ b/master/ethernet.c Fri Aug 10 15:27:08 2007 +0000 @@ -48,16 +48,21 @@ #include "mailbox.h" #include "ethernet.h" -/** - Defines the debug level of EoE processing - - 0 = No debug messages. - 1 = Output actions. - 2 = Output actions and frame data. -*/ +/*****************************************************************************/ + +/** + * Defines the debug level of EoE processing. + * + * 0 = No debug messages. + * 1 = Output actions. + * 2 = Output actions and frame data. + */ #define EOE_DEBUG_LEVEL 0 +/** size of the EoE tx queue */ +#define EC_EOE_TX_QUEUE_SIZE 100 + /*****************************************************************************/ void ec_eoe_flush(ec_eoe_t *); @@ -78,16 +83,21 @@ /*****************************************************************************/ /** - EoE constructor. - Initializes the EoE handler, creates a net_device and registeres it. -*/ - -int ec_eoe_init(ec_eoe_t *eoe /**< EoE handler */) + * EoE constructor. + * Initializes the EoE handler, creates a net_device and registers it. + */ + +int ec_eoe_init( + ec_eoe_t *eoe, /**< EoE handler */ + ec_slave_t *slave /**< EtherCAT slave */ + ) { ec_eoe_t **priv; int result, i; - - eoe->slave = NULL; + char name[20]; + + eoe->slave = slave; + ec_datagram_init(&eoe->datagram); eoe->state = ec_eoe_state_rx_start; eoe->opened = 0; @@ -107,8 +117,11 @@ eoe->tx_rate = 0; eoe->rate_jiffies = 0; - if (!(eoe->dev = - alloc_netdev(sizeof(ec_eoe_t *), "eoe%d", ether_setup))) { + /* device name eoes, because system tools don't like + * hyphens etc. in interface names. */ + sprintf(name, "eoe%us%u", slave->master->index, slave->ring_position); + + if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) { EC_ERR("Unable to allocate net_device for EoE handler!\n"); goto out_return; } @@ -142,7 +155,6 @@ // make the last address octet unique eoe->dev->dev_addr[ETH_ALEN - 1] = (uint8_t) eoe->dev->ifindex; - return 0; out_free: @@ -300,9 +312,9 @@ \return 1 if the device is "up", 0 if it is "down" */ -int ec_eoe_active(const ec_eoe_t *eoe /**< EoE handler */) -{ - return eoe->slave && eoe->opened; +int ec_eoe_is_open(const ec_eoe_t *eoe /**< EoE handler */) +{ + return eoe->opened; } /****************************************************************************** @@ -317,7 +329,8 @@ void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */) { - if (!eoe->slave->online || !eoe->slave->master->device->link_state) + if (eoe->slave->online_state == EC_SLAVE_OFFLINE || + !eoe->slave->master->main_device.link_state) return; ec_slave_mbox_prepare_check(eoe->slave, &eoe->datagram); @@ -382,7 +395,7 @@ return; } - if (mbox_prot != 0x02) { // EoE + if (mbox_prot != 0x02) { // EoE FIXME mailbox handler necessary eoe->stats.rx_errors++; eoe->state = ec_eoe_state_tx_start; return; @@ -518,7 +531,8 @@ unsigned int wakeup = 0; #endif - if (!eoe->slave->online || !eoe->slave->master->device->link_state) + if (eoe->slave->online_state == EC_SLAVE_OFFLINE || + !eoe->slave->master->main_device.link_state) return; spin_lock_bh(&eoe->tx_queue_lock); @@ -626,11 +640,7 @@ netif_start_queue(dev); eoe->tx_queue_active = 1; EC_INFO("%s opened.\n", dev->name); - if (!eoe->slave) - EC_WARN("Device %s is not coupled to any EoE slave!\n", dev->name); - else { - ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP); - } + ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP); return 0; } @@ -648,8 +658,7 @@ eoe->opened = 0; ec_eoe_flush(eoe); EC_INFO("%s stopped.\n", dev->name); - if (eoe->slave) - ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_PREOP); + ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_PREOP); return 0; }