diff -r 19732da2cf86 -r 3001f6523e63 master/ethernet.c --- a/master/ethernet.c Fri May 13 15:33:16 2011 +0200 +++ b/master/ethernet.c Fri May 13 15:34:20 2011 +0200 @@ -111,6 +111,7 @@ eoe->slave = slave; ec_datagram_init(&eoe->datagram); + ec_mbox_init(&eoe->mbox,&eoe->datagram); eoe->queue_datagram = 0; eoe->state = ec_eoe_state_rx_start; eoe->opened = 0; @@ -122,7 +123,7 @@ eoe->tx_queue_size = EC_EOE_TX_QUEUE_SIZE; eoe->tx_queued_frames = 0; - sema_init(&eoe->tx_queue_sem, 1); + ec_mutex_init(&eoe->tx_queue_mutex); eoe->tx_frame_number = 0xFF; memset(&eoe->stats, 0, sizeof(struct net_device_stats)); @@ -220,6 +221,7 @@ free_netdev(eoe->dev); + ec_mbox_clear(&eoe->mbox); ec_datagram_clear(&eoe->datagram); } @@ -231,7 +233,7 @@ { ec_eoe_frame_t *frame, *next; - down(&eoe->tx_queue_sem); + ec_mutex_lock(&eoe->tx_queue_mutex); list_for_each_entry_safe(frame, next, &eoe->tx_queue, queue) { list_del(&frame->queue); @@ -240,7 +242,7 @@ } eoe->tx_queued_frames = 0; - up(&eoe->tx_queue_sem); + ec_mutex_unlock(&eoe->tx_queue_mutex); } /*****************************************************************************/ @@ -294,7 +296,7 @@ printk("\n"); #endif - data = ec_slave_mbox_prepare_send(eoe->slave, &eoe->datagram, + data = ec_slave_mbox_prepare_send(eoe->slave, &eoe->mbox, 0x02, current_size + 4); if (IS_ERR(data)) return PTR_ERR(data); @@ -323,7 +325,9 @@ return; // if the datagram was not sent, or is not yet received, skip this cycle - if (eoe->queue_datagram || eoe->datagram.state == EC_DATAGRAM_SENT) + if (eoe->queue_datagram || + ec_mbox_is_datagram_state(&eoe->mbox,EC_DATAGRAM_QUEUED) || + ec_mbox_is_datagram_state(&eoe->mbox,EC_DATAGRAM_SENT)) return; // call state function @@ -348,7 +352,7 @@ void ec_eoe_queue(ec_eoe_t *eoe /**< EoE handler */) { if (eoe->queue_datagram) { - ec_master_queue_datagram_ext(eoe->slave->master, &eoe->datagram); + ec_master_mbox_queue_datagrams(eoe->slave->master, &eoe->mbox); eoe->queue_datagram = 0; } } @@ -394,7 +398,7 @@ return; } - ec_slave_mbox_prepare_check(eoe->slave, &eoe->datagram); + ec_slave_mbox_prepare_check(eoe->slave, &eoe->mbox); eoe->queue_datagram = 1; eoe->state = ec_eoe_state_rx_check; } @@ -408,7 +412,7 @@ */ void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */) { - if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { + if (!ec_mbox_is_datagram_state(&eoe->mbox,EC_DATAGRAM_RECEIVED)) { eoe->stats.rx_errors++; #if EOE_DEBUG_LEVEL >= 1 EC_SLAVE_WARN(eoe->slave, "Failed to receive mbox" @@ -418,14 +422,14 @@ return; } - if (!ec_slave_mbox_check(&eoe->datagram)) { + if (!ec_slave_mbox_check(&eoe->mbox)) { eoe->rx_idle = 1; eoe->state = ec_eoe_state_tx_start; return; } eoe->rx_idle = 0; - ec_slave_mbox_prepare_fetch(eoe->slave, &eoe->datagram); + ec_slave_mbox_prepare_fetch(eoe->slave, &eoe->mbox); eoe->queue_datagram = 1; eoe->state = ec_eoe_state_rx_fetch; } @@ -447,7 +451,7 @@ unsigned int i; #endif - if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { + if (!ec_mbox_is_datagram_state(&eoe->mbox,EC_DATAGRAM_RECEIVED)) { eoe->stats.rx_errors++; #if EOE_DEBUG_LEVEL >= 1 EC_SLAVE_WARN(eoe->slave, "Failed to receive mbox" @@ -457,7 +461,7 @@ return; } - data = ec_slave_mbox_fetch(eoe->slave, &eoe->datagram, + data = ec_slave_mbox_fetch(eoe->slave, &eoe->mbox, &mbox_prot, &rec_size); if (IS_ERR(data)) { eoe->stats.rx_errors++; @@ -620,10 +624,10 @@ return; } - down(&eoe->tx_queue_sem); + ec_mutex_lock(&eoe->tx_queue_mutex); if (!eoe->tx_queued_frames || list_empty(&eoe->tx_queue)) { - up(&eoe->tx_queue_sem); + ec_mutex_unlock(&eoe->tx_queue_mutex); eoe->tx_idle = 1; // no data available. // start a new receive immediately. @@ -644,7 +648,7 @@ } eoe->tx_queued_frames--; - up(&eoe->tx_queue_sem); + ec_mutex_unlock(&eoe->tx_queue_mutex); eoe->tx_idle = 0; @@ -684,7 +688,7 @@ */ void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */) { - if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { + if (!ec_mbox_is_datagram_state(&eoe->mbox,EC_DATAGRAM_RECEIVED)) { if (eoe->tries) { eoe->tries--; // try again eoe->queue_datagram = 1; @@ -700,7 +704,7 @@ return; } - if (eoe->datagram.working_counter != 1) { + if (!ec_mbox_is_datagram_wc(&eoe->mbox,1)) { if (eoe->tries) { eoe->tries--; // try again eoe->queue_datagram = 1; @@ -812,14 +816,14 @@ frame->skb = skb; - down(&eoe->tx_queue_sem); + ec_mutex_lock(&eoe->tx_queue_mutex); list_add_tail(&frame->queue, &eoe->tx_queue); eoe->tx_queued_frames++; if (eoe->tx_queued_frames == eoe->tx_queue_size) { netif_stop_queue(dev); eoe->tx_queue_active = 0; } - up(&eoe->tx_queue_sem); + ec_mutex_unlock(&eoe->tx_queue_mutex); #if EOE_DEBUG_LEVEL >= 2 EC_SLAVE_DBG(eoe->slave, 0, "EoE %s TX queued frame"