master/ethernet.c
changeset 293 14aeb79aa992
parent 291 0b1f877cf3f1
child 294 feea8d850c65
equal deleted inserted replaced
292:2cf6ae0a2419 293:14aeb79aa992
    85 {
    85 {
    86     ec_eoe_t **priv;
    86     ec_eoe_t **priv;
    87     int result, i;
    87     int result, i;
    88 
    88 
    89     eoe->slave = NULL;
    89     eoe->slave = NULL;
    90     ec_command_init(&eoe->command);
    90     ec_datagram_init(&eoe->datagram);
    91     eoe->state = ec_eoe_state_rx_start;
    91     eoe->state = ec_eoe_state_rx_start;
    92     eoe->opened = 0;
    92     eoe->opened = 0;
    93     eoe->rx_skb = NULL;
    93     eoe->rx_skb = NULL;
    94     eoe->rx_expected_fragment = 0;
    94     eoe->rx_expected_fragment = 0;
    95     INIT_LIST_HEAD(&eoe->tx_queue);
    95     INIT_LIST_HEAD(&eoe->tx_queue);
   167         kfree(eoe->tx_frame);
   167         kfree(eoe->tx_frame);
   168     }
   168     }
   169 
   169 
   170     if (eoe->rx_skb) dev_kfree_skb(eoe->rx_skb);
   170     if (eoe->rx_skb) dev_kfree_skb(eoe->rx_skb);
   171 
   171 
   172     ec_command_clear(&eoe->command);
   172     ec_datagram_clear(&eoe->datagram);
   173 }
   173 }
   174 
   174 
   175 /*****************************************************************************/
   175 /*****************************************************************************/
   176 
   176 
   177 /**
   177 /**
   244         }
   244         }
   245     }
   245     }
   246     printk("\n");
   246     printk("\n");
   247 #endif
   247 #endif
   248 
   248 
   249     if (!(data = ec_slave_mbox_prepare_send(eoe->slave, &eoe->command,
   249     if (!(data = ec_slave_mbox_prepare_send(eoe->slave, &eoe->datagram,
   250                                             0x02, current_size + 4)))
   250                                             0x02, current_size + 4)))
   251         return -1;
   251         return -1;
   252 
   252 
   253     EC_WRITE_U8 (data,     0x00); // eoe fragment req.
   253     EC_WRITE_U8 (data,     0x00); // eoe fragment req.
   254     EC_WRITE_U8 (data + 1, last_fragment);
   254     EC_WRITE_U8 (data + 1, last_fragment);
   255     EC_WRITE_U16(data + 2, ((eoe->tx_fragment_number & 0x3F) |
   255     EC_WRITE_U16(data + 2, ((eoe->tx_fragment_number & 0x3F) |
   256                             (complete_offset & 0x3F) << 6 |
   256                             (complete_offset & 0x3F) << 6 |
   257                             (eoe->tx_frame_number & 0x0F) << 12));
   257                             (eoe->tx_frame_number & 0x0F) << 12));
   258 
   258 
   259     memcpy(data + 4, eoe->tx_frame->skb->data + eoe->tx_offset, current_size);
   259     memcpy(data + 4, eoe->tx_frame->skb->data + eoe->tx_offset, current_size);
   260     ec_master_queue_command(eoe->slave->master, &eoe->command);
   260     ec_master_queue_datagram(eoe->slave->master, &eoe->datagram);
   261 
   261 
   262     eoe->tx_offset += current_size;
   262     eoe->tx_offset += current_size;
   263     eoe->tx_fragment_number++;
   263     eoe->tx_fragment_number++;
   264     return 0;
   264     return 0;
   265 }
   265 }
   310  *  STATE PROCESSING FUNCTIONS
   310  *  STATE PROCESSING FUNCTIONS
   311  *****************************************************************************/
   311  *****************************************************************************/
   312 
   312 
   313 /**
   313 /**
   314    State: RX_START.
   314    State: RX_START.
   315    Starts a new receiving sequence by queueing a command that checks the
   315    Starts a new receiving sequence by queueing a datagram that checks the
   316    slave's mailbox for a new EoE command.
   316    slave's mailbox for a new EoE datagram.
   317 */
   317 */
   318 
   318 
   319 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */)
   319 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */)
   320 {
   320 {
   321     if (!eoe->slave->online || !eoe->slave->master->device->link_state)
   321     if (!eoe->slave->online || !eoe->slave->master->device->link_state)
   322         return;
   322         return;
   323 
   323 
   324     ec_slave_mbox_prepare_check(eoe->slave, &eoe->command);
   324     ec_slave_mbox_prepare_check(eoe->slave, &eoe->datagram);
   325     ec_master_queue_command(eoe->slave->master, &eoe->command);
   325     ec_master_queue_datagram(eoe->slave->master, &eoe->datagram);
   326     eoe->state = ec_eoe_state_rx_check;
   326     eoe->state = ec_eoe_state_rx_check;
   327 }
   327 }
   328 
   328 
   329 /*****************************************************************************/
   329 /*****************************************************************************/
   330 
   330 
   331 /**
   331 /**
   332    State: RX_CHECK.
   332    State: RX_CHECK.
   333    Processes the checking command sent in RX_START and issues a receive
   333    Processes the checking datagram sent in RX_START and issues a receive
   334    command, if new data is available.
   334    datagram, if new data is available.
   335 */
   335 */
   336 
   336 
   337 void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */)
   337 void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */)
   338 {
   338 {
   339     if (eoe->command.state != EC_CMD_RECEIVED) {
   339     if (eoe->datagram.state != EC_CMD_RECEIVED) {
   340         eoe->stats.rx_errors++;
   340         eoe->stats.rx_errors++;
   341         eoe->state = ec_eoe_state_tx_start;
   341         eoe->state = ec_eoe_state_tx_start;
   342         return;
   342         return;
   343     }
   343     }
   344 
   344 
   345     if (!ec_slave_mbox_check(&eoe->command)) {
   345     if (!ec_slave_mbox_check(&eoe->datagram)) {
   346         eoe->state = ec_eoe_state_tx_start;
   346         eoe->state = ec_eoe_state_tx_start;
   347         return;
   347         return;
   348     }
   348     }
   349 
   349 
   350     ec_slave_mbox_prepare_fetch(eoe->slave, &eoe->command);
   350     ec_slave_mbox_prepare_fetch(eoe->slave, &eoe->datagram);
   351     ec_master_queue_command(eoe->slave->master, &eoe->command);
   351     ec_master_queue_datagram(eoe->slave->master, &eoe->datagram);
   352     eoe->state = ec_eoe_state_rx_fetch;
   352     eoe->state = ec_eoe_state_rx_fetch;
   353 }
   353 }
   354 
   354 
   355 /*****************************************************************************/
   355 /*****************************************************************************/
   356 
   356 
   357 /**
   357 /**
   358    State: RX_FETCH.
   358    State: RX_FETCH.
   359    Checks if the requested data of RX_CHECK was received and processes the
   359    Checks if the requested data of RX_CHECK was received and processes the
   360    EoE command.
   360    EoE datagram.
   361 */
   361 */
   362 
   362 
   363 void ec_eoe_state_rx_fetch(ec_eoe_t *eoe /**< EoE handler */)
   363 void ec_eoe_state_rx_fetch(ec_eoe_t *eoe /**< EoE handler */)
   364 {
   364 {
   365     size_t rec_size, data_size;
   365     size_t rec_size, data_size;
   366     uint8_t *data, frame_type, last_fragment, time_appended;
   366     uint8_t *data, frame_type, last_fragment, time_appended;
   367     uint8_t frame_number, fragment_offset, fragment_number;
   367     uint8_t frame_number, fragment_offset, fragment_number;
   368     off_t offset;
   368     off_t offset;
   369 
   369 
   370     if (eoe->command.state != EC_CMD_RECEIVED) {
   370     if (eoe->datagram.state != EC_CMD_RECEIVED) {
   371         eoe->stats.rx_errors++;
   371         eoe->stats.rx_errors++;
   372         eoe->state = ec_eoe_state_tx_start;
   372         eoe->state = ec_eoe_state_tx_start;
   373         return;
   373         return;
   374     }
   374     }
   375 
   375 
   376     if (!(data = ec_slave_mbox_fetch(eoe->slave, &eoe->command,
   376     if (!(data = ec_slave_mbox_fetch(eoe->slave, &eoe->datagram,
   377                                      0x02, &rec_size))) {
   377                                      0x02, &rec_size))) {
   378         eoe->stats.rx_errors++;
   378         eoe->stats.rx_errors++;
   379         eoe->state = ec_eoe_state_tx_start;
   379         eoe->state = ec_eoe_state_tx_start;
   380         return;
   380         return;
   381     }
   381     }
   558 
   558 
   559 /*****************************************************************************/
   559 /*****************************************************************************/
   560 
   560 
   561 /**
   561 /**
   562    State: TX SENT.
   562    State: TX SENT.
   563    Checks is the previous transmit command succeded and sends the next
   563    Checks is the previous transmit datagram succeded and sends the next
   564    fragment, if necessary.
   564    fragment, if necessary.
   565 */
   565 */
   566 
   566 
   567 void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */)
   567 void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */)
   568 {
   568 {
   569     if (eoe->command.state != EC_CMD_RECEIVED) {
   569     if (eoe->datagram.state != EC_CMD_RECEIVED) {
   570         eoe->stats.tx_errors++;
   570         eoe->stats.tx_errors++;
   571         eoe->state = ec_eoe_state_rx_start;
   571         eoe->state = ec_eoe_state_rx_start;
   572         return;
   572         return;
   573     }
   573     }
   574 
   574 
   575     if (eoe->command.working_counter != 1) {
   575     if (eoe->datagram.working_counter != 1) {
   576         eoe->stats.tx_errors++;
   576         eoe->stats.tx_errors++;
   577         eoe->state = ec_eoe_state_rx_start;
   577         eoe->state = ec_eoe_state_rx_start;
   578         return;
   578         return;
   579     }
   579     }
   580 
   580