master/ethernet.c
branchstable-1.0
changeset 1621 4bbe090553f7
parent 1619 0d4119024f55
child 1623 05622513f627
equal deleted inserted replaced
1620:9d7453c16ade 1621:4bbe090553f7
    77 {
    77 {
    78     ec_eoe_t **priv;
    78     ec_eoe_t **priv;
    79     int result, i;
    79     int result, i;
    80 
    80 
    81     eoe->slave = NULL;
    81     eoe->slave = NULL;
       
    82     ec_command_init(&eoe->command);
    82     eoe->state = ec_eoe_state_rx_start;
    83     eoe->state = ec_eoe_state_rx_start;
    83     eoe->opened = 0;
    84     eoe->opened = 0;
    84     eoe->rx_skb = NULL;
    85     eoe->rx_skb = NULL;
    85     eoe->rx_expected_fragment = 0;
    86     eoe->rx_expected_fragment = 0;
    86     INIT_LIST_HEAD(&eoe->tx_queue);
    87     INIT_LIST_HEAD(&eoe->tx_queue);
   157         dev_kfree_skb(eoe->tx_frame->skb);
   158         dev_kfree_skb(eoe->tx_frame->skb);
   158         kfree(eoe->tx_frame);
   159         kfree(eoe->tx_frame);
   159     }
   160     }
   160 
   161 
   161     if (eoe->rx_skb) dev_kfree_skb(eoe->rx_skb);
   162     if (eoe->rx_skb) dev_kfree_skb(eoe->rx_skb);
       
   163 
       
   164     ec_command_clear(&eoe->command);
   162 }
   165 }
   163 
   166 
   164 /*****************************************************************************/
   167 /*****************************************************************************/
   165 
   168 
   166 /**
   169 /**
   233         }
   236         }
   234     }
   237     }
   235     printk("\n");
   238     printk("\n");
   236 #endif
   239 #endif
   237 
   240 
   238     if (!(data = ec_slave_mbox_prepare_send(eoe->slave, 0x02,
   241     if (!(data = ec_slave_mbox_prepare_send(eoe->slave, &eoe->command,
   239                                             current_size + 4)))
   242                                             0x02, current_size + 4)))
   240         return -1;
   243         return -1;
   241 
   244 
   242     EC_WRITE_U8 (data,     0x00); // eoe fragment req.
   245     EC_WRITE_U8 (data,     0x00); // eoe fragment req.
   243     EC_WRITE_U8 (data + 1, last_fragment);
   246     EC_WRITE_U8 (data + 1, last_fragment);
   244     EC_WRITE_U16(data + 2, ((eoe->tx_fragment_number & 0x3F) |
   247     EC_WRITE_U16(data + 2, ((eoe->tx_fragment_number & 0x3F) |
   245                             (complete_offset & 0x3F) << 6 |
   248                             (complete_offset & 0x3F) << 6 |
   246                             (eoe->tx_frame_number & 0x0F) << 12));
   249                             (eoe->tx_frame_number & 0x0F) << 12));
   247 
   250 
   248     memcpy(data + 4, eoe->tx_frame->skb->data + eoe->tx_offset, current_size);
   251     memcpy(data + 4, eoe->tx_frame->skb->data + eoe->tx_offset, current_size);
   249     ec_master_queue_command(eoe->slave->master, &eoe->slave->mbox_command);
   252     ec_master_queue_command(eoe->slave->master, &eoe->command);
   250 
   253 
   251     eoe->tx_offset += current_size;
   254     eoe->tx_offset += current_size;
   252     eoe->tx_fragment_number++;
   255     eoe->tx_fragment_number++;
   253     return 0;
   256     return 0;
   254 }
   257 }
   308 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */)
   311 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */)
   309 {
   312 {
   310     if (!eoe->slave->online || !eoe->slave->master->device->link_state)
   313     if (!eoe->slave->online || !eoe->slave->master->device->link_state)
   311         return;
   314         return;
   312 
   315 
   313     ec_slave_mbox_prepare_check(eoe->slave);
   316     ec_slave_mbox_prepare_check(eoe->slave, &eoe->command);
   314     ec_master_queue_command(eoe->slave->master, &eoe->slave->mbox_command);
   317     ec_master_queue_command(eoe->slave->master, &eoe->command);
   315     eoe->state = ec_eoe_state_rx_check;
   318     eoe->state = ec_eoe_state_rx_check;
   316 }
   319 }
   317 
   320 
   318 /*****************************************************************************/
   321 /*****************************************************************************/
   319 
   322 
   323    command, if new data is available.
   326    command, if new data is available.
   324 */
   327 */
   325 
   328 
   326 void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */)
   329 void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */)
   327 {
   330 {
   328     if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) {
   331     if (eoe->command.state != EC_CMD_RECEIVED) {
   329         eoe->stats.rx_errors++;
   332         eoe->stats.rx_errors++;
   330         eoe->state = ec_eoe_state_tx_start;
   333         eoe->state = ec_eoe_state_tx_start;
   331         return;
   334         return;
   332     }
   335     }
   333 
   336 
   334     if (!ec_slave_mbox_check(eoe->slave)) {
   337     if (!ec_slave_mbox_check(&eoe->command)) {
   335         eoe->state = ec_eoe_state_tx_start;
   338         eoe->state = ec_eoe_state_tx_start;
   336         return;
   339         return;
   337     }
   340     }
   338 
   341 
   339     ec_slave_mbox_prepare_fetch(eoe->slave);
   342     ec_slave_mbox_prepare_fetch(eoe->slave, &eoe->command);
   340     ec_master_queue_command(eoe->slave->master, &eoe->slave->mbox_command);
   343     ec_master_queue_command(eoe->slave->master, &eoe->command);
   341     eoe->state = ec_eoe_state_rx_fetch;
   344     eoe->state = ec_eoe_state_rx_fetch;
   342 }
   345 }
   343 
   346 
   344 /*****************************************************************************/
   347 /*****************************************************************************/
   345 
   348 
   354     size_t rec_size, data_size;
   357     size_t rec_size, data_size;
   355     uint8_t *data, frame_type, last_fragment, time_appended;
   358     uint8_t *data, frame_type, last_fragment, time_appended;
   356     uint8_t frame_number, fragment_offset, fragment_number;
   359     uint8_t frame_number, fragment_offset, fragment_number;
   357     off_t offset;
   360     off_t offset;
   358 
   361 
   359     if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) {
   362     if (eoe->command.state != EC_CMD_RECEIVED) {
   360         eoe->stats.rx_errors++;
   363         eoe->stats.rx_errors++;
   361         eoe->state = ec_eoe_state_tx_start;
   364         eoe->state = ec_eoe_state_tx_start;
   362         return;
   365         return;
   363     }
   366     }
   364 
   367 
   365     if (!(data = ec_slave_mbox_fetch(eoe->slave, 0x02, &rec_size))) {
   368     if (!(data = ec_slave_mbox_fetch(eoe->slave, &eoe->command,
       
   369                                      0x02, &rec_size))) {
   366         eoe->stats.rx_errors++;
   370         eoe->stats.rx_errors++;
   367         eoe->state = ec_eoe_state_tx_start;
   371         eoe->state = ec_eoe_state_tx_start;
   368         return;
   372         return;
   369     }
   373     }
   370 
   374 
   552    fragment, if necessary.
   556    fragment, if necessary.
   553 */
   557 */
   554 
   558 
   555 void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */)
   559 void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */)
   556 {
   560 {
   557     if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) {
   561     if (eoe->command.state != EC_CMD_RECEIVED) {
   558         eoe->stats.tx_errors++;
   562         eoe->stats.tx_errors++;
   559         eoe->state = ec_eoe_state_rx_start;
   563         eoe->state = ec_eoe_state_rx_start;
   560         return;
   564         return;
   561     }
   565     }
   562 
   566 
   563     if (eoe->slave->mbox_command.working_counter != 1) {
   567     if (eoe->command.working_counter != 1) {
   564         eoe->stats.tx_errors++;
   568         eoe->stats.tx_errors++;
   565         eoe->state = ec_eoe_state_rx_start;
   569         eoe->state = ec_eoe_state_rx_start;
   566         return;
   570         return;
   567     }
   571     }
   568 
   572