master/ethernet.c
changeset 1484 1c9151455b65
parent 1363 11c0b2caa253
child 1485 5ddc3a455059
equal deleted inserted replaced
1483:43adf48aa157 1484:1c9151455b65
   249         // complete size in 32 bit blocks, rounded up.
   249         // complete size in 32 bit blocks, rounded up.
   250         complete_offset = remaining_size / 32 + 1;
   250         complete_offset = remaining_size / 32 + 1;
   251     }
   251     }
   252 
   252 
   253 #if EOE_DEBUG_LEVEL > 0
   253 #if EOE_DEBUG_LEVEL > 0
   254     EC_INFO("EoE %s TX sending fragment %u%s with %u octets (%u)."
   254     EC_DBG("EoE %s TX sending fragment %u%s with %u octets (%u)."
   255            " %u frames queued.\n", eoe->dev->name, eoe->tx_fragment_number,
   255            " %u frames queued.\n", eoe->dev->name, eoe->tx_fragment_number,
   256            last_fragment ? "" : "+", current_size, complete_offset,
   256            last_fragment ? "" : "+", current_size, complete_offset,
   257            eoe->tx_queued_frames);
   257            eoe->tx_queued_frames);
   258 #endif
   258 #endif
   259 
   259 
   260 #if EOE_DEBUG_LEVEL > 1
   260 #if EOE_DEBUG_LEVEL > 1
   261     EC_INFO("");
   261     EC_DBG("");
   262     for (i = 0; i < current_size; i++) {
   262     for (i = 0; i < current_size; i++) {
   263         printk("%02X ", eoe->tx_frame->skb->data[eoe->tx_offset + i]);
   263         printk("%02X ", eoe->tx_frame->skb->data[eoe->tx_offset + i]);
   264         if ((i + 1) % 16 == 0) {
   264         if ((i + 1) % 16 == 0) {
   265             printk("\n");
   265             printk("\n");
   266             EC_INFO("");
   266             EC_DBG("");
   267         }
   267         }
   268     }
   268     }
   269     printk("\n");
   269     printk("\n");
   270 #endif
   270 #endif
   271 
   271 
   294    Runs the EoE state machine.
   294    Runs the EoE state machine.
   295 */
   295 */
   296 
   296 
   297 void ec_eoe_run(ec_eoe_t *eoe /**< EoE handler */)
   297 void ec_eoe_run(ec_eoe_t *eoe /**< EoE handler */)
   298 {
   298 {
   299     if (!eoe->opened) return;
   299     if (!eoe->opened)
       
   300         return;
   300 
   301 
   301     // if the datagram was not sent, or is not yet received, skip this cycle
   302     // if the datagram was not sent, or is not yet received, skip this cycle
   302     if (eoe->queue_datagram || eoe->datagram.state == EC_DATAGRAM_SENT)
   303     if (eoe->queue_datagram || eoe->datagram.state == EC_DATAGRAM_SENT)
   303         return;
   304         return;
   304 
   305 
   429 
   430 
   430     frame_type = EC_READ_U16(data) & 0x000F;
   431     frame_type = EC_READ_U16(data) & 0x000F;
   431 
   432 
   432     if (frame_type != 0x00) {
   433     if (frame_type != 0x00) {
   433 #if EOE_DEBUG_LEVEL > 0
   434 #if EOE_DEBUG_LEVEL > 0
   434         EC_INFO("EoE %s: Other frame received.\n", eoe->dev->name);
   435         EC_DBG("EoE %s: Other frame received.\n", eoe->dev->name);
   435 #endif
   436 #endif
   436         eoe->stats.rx_dropped++;
   437         eoe->stats.rx_dropped++;
   437         eoe->state = ec_eoe_state_tx_start;
   438         eoe->state = ec_eoe_state_tx_start;
   438         return;
   439         return;
   439     }
   440     }
   445     fragment_number = EC_READ_U16(data + 2) & 0x003F;
   446     fragment_number = EC_READ_U16(data + 2) & 0x003F;
   446     fragment_offset = (EC_READ_U16(data + 2) >> 6) & 0x003F;
   447     fragment_offset = (EC_READ_U16(data + 2) >> 6) & 0x003F;
   447     frame_number = (EC_READ_U16(data + 2) >> 12) & 0x000F;
   448     frame_number = (EC_READ_U16(data + 2) >> 12) & 0x000F;
   448 
   449 
   449 #if EOE_DEBUG_LEVEL > 0
   450 #if EOE_DEBUG_LEVEL > 0
   450     EC_INFO("EoE %s RX fragment %u%s, offset %u, frame %u%s,"
   451     EC_DBG("EoE %s RX fragment %u%s, offset %u, frame %u%s,"
   451            " %u octets\n", eoe->dev->name, fragment_number,
   452            " %u octets\n", eoe->dev->name, fragment_number,
   452            last_fragment ? "" : "+", fragment_offset, frame_number, 
   453            last_fragment ? "" : "+", fragment_offset, frame_number, 
   453            time_appended ? ", + timestamp" : "",
   454            time_appended ? ", + timestamp" : "",
   454            time_appended ? rec_size - 8 : rec_size - 4);
   455            time_appended ? rec_size - 8 : rec_size - 4);
   455 #endif
   456 #endif
   456 
   457 
   457 #if EOE_DEBUG_LEVEL > 1
   458 #if EOE_DEBUG_LEVEL > 1
   458     EC_INFO("");
   459     EC_DBG("");
   459     for (i = 0; i < rec_size - 4; i++) {
   460     for (i = 0; i < rec_size - 4; i++) {
   460         printk("%02X ", data[i + 4]);
   461         printk("%02X ", data[i + 4]);
   461         if ((i + 1) % 16 == 0) {
   462         if ((i + 1) % 16 == 0) {
   462             printk("\n");
   463             printk("\n");
   463             EC_INFO("");
   464             EC_DBG("");
   464         }
   465         }
   465     }
   466     }
   466     printk("\n");
   467     printk("\n");
   467 #endif
   468 #endif
   468 
   469 
   515         eoe->stats.rx_packets++;
   516         eoe->stats.rx_packets++;
   516         eoe->stats.rx_bytes += eoe->rx_skb->len;
   517         eoe->stats.rx_bytes += eoe->rx_skb->len;
   517         eoe->rx_counter += eoe->rx_skb->len;
   518         eoe->rx_counter += eoe->rx_skb->len;
   518 
   519 
   519 #if EOE_DEBUG_LEVEL > 0
   520 #if EOE_DEBUG_LEVEL > 0
   520         EC_INFO("EoE %s RX frame completed with %u octets.\n",
   521         EC_DBG("EoE %s RX frame completed with %u octets.\n",
   521                eoe->dev->name, eoe->rx_skb->len);
   522                eoe->dev->name, eoe->rx_skb->len);
   522 #endif
   523 #endif
   523 
   524 
   524         // pass socket buffer to network stack
   525         // pass socket buffer to network stack
   525         eoe->rx_skb->dev = eoe->dev;
   526         eoe->rx_skb->dev = eoe->dev;
   533         eoe->state = ec_eoe_state_tx_start;
   534         eoe->state = ec_eoe_state_tx_start;
   534     }
   535     }
   535     else {
   536     else {
   536         eoe->rx_expected_fragment++;
   537         eoe->rx_expected_fragment++;
   537 #if EOE_DEBUG_LEVEL > 0
   538 #if EOE_DEBUG_LEVEL > 0
   538         EC_INFO("EoE %s RX expecting fragment %u\n",
   539         EC_DBG("EoE %s RX expecting fragment %u\n",
   539                eoe->dev->name, eoe->rx_expected_fragment);
   540                eoe->dev->name, eoe->rx_expected_fragment);
   540 #endif
   541 #endif
   541         eoe->state = ec_eoe_state_rx_start;
   542         eoe->state = ec_eoe_state_rx_start;
   542     }
   543     }
   543 }
   544 }
   597         eoe->state = ec_eoe_state_rx_start;
   598         eoe->state = ec_eoe_state_rx_start;
   598         return;
   599         return;
   599     }
   600     }
   600 
   601 
   601 #if EOE_DEBUG_LEVEL > 0
   602 #if EOE_DEBUG_LEVEL > 0
   602     if (wakeup) EC_INFO("EoE %s waking up TX queue...\n", eoe->dev->name);
   603     if (wakeup)
       
   604         EC_DBG("EoE %s waking up TX queue...\n", eoe->dev->name);
   603 #endif
   605 #endif
   604 
   606 
   605     eoe->state = ec_eoe_state_tx_sent;
   607     eoe->state = ec_eoe_state_tx_sent;
   606 }
   608 }
   607 
   609 
   661     ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev));
   663     ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev));
   662     ec_eoe_flush(eoe);
   664     ec_eoe_flush(eoe);
   663     eoe->opened = 1;
   665     eoe->opened = 1;
   664     netif_start_queue(dev);
   666     netif_start_queue(dev);
   665     eoe->tx_queue_active = 1;
   667     eoe->tx_queue_active = 1;
   666     EC_INFO("%s opened.\n", dev->name);
   668     EC_DBG("%s opened.\n", dev->name);
   667     ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
   669     ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
   668     return 0;
   670     return 0;
   669 }
   671 }
   670 
   672 
   671 /*****************************************************************************/
   673 /*****************************************************************************/
   679     ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev));
   681     ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev));
   680     netif_stop_queue(dev);
   682     netif_stop_queue(dev);
   681     eoe->tx_queue_active = 0;
   683     eoe->tx_queue_active = 0;
   682     eoe->opened = 0;
   684     eoe->opened = 0;
   683     ec_eoe_flush(eoe);
   685     ec_eoe_flush(eoe);
   684     EC_INFO("%s stopped.\n", dev->name);
   686     EC_DBG("%s stopped.\n", dev->name);
   685     ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_PREOP);
   687     ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_PREOP);
   686     return 0;
   688     return 0;
   687 }
   689 }
   688 
   690 
   689 /*****************************************************************************/
   691 /*****************************************************************************/
   725         eoe->tx_queue_active = 0;
   727         eoe->tx_queue_active = 0;
   726     }
   728     }
   727     spin_unlock_bh(&eoe->tx_queue_lock);
   729     spin_unlock_bh(&eoe->tx_queue_lock);
   728 
   730 
   729 #if EOE_DEBUG_LEVEL > 0
   731 #if EOE_DEBUG_LEVEL > 0
   730     EC_INFO("EoE %s TX queued frame with %u octets (%u frames queued).\n",
   732     EC_DBG("EoE %s TX queued frame with %u octets (%u frames queued).\n",
   731            eoe->dev->name, skb->len, eoe->tx_queued_frames);
   733            eoe->dev->name, skb->len, eoe->tx_queued_frames);
   732     if (!eoe->tx_queue_active)
   734     if (!eoe->tx_queue_active)
   733         EC_WARN("EoE TX queue is now full.\n");
   735         EC_WARN("EoE TX queue is now full.\n");
   734 #endif
   736 #endif
   735 
   737