145 } |
145 } |
146 |
146 |
147 snprintf(eoe->datagram.name, EC_DATAGRAM_NAME_SIZE, name); |
147 snprintf(eoe->datagram.name, EC_DATAGRAM_NAME_SIZE, name); |
148 |
148 |
149 if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) { |
149 if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) { |
150 EC_ERR("Unable to allocate net_device %s for EoE handler!\n", name); |
150 EC_SLAVE_ERR(slave, "Unable to allocate net_device %s" |
|
151 " for EoE handler!\n", name); |
151 ret = -ENODEV; |
152 ret = -ENODEV; |
152 goto out_return; |
153 goto out_return; |
153 } |
154 } |
154 |
155 |
155 // initialize net_device |
156 // initialize net_device |
271 // complete size in 32 bit blocks, rounded up. |
273 // complete size in 32 bit blocks, rounded up. |
272 complete_offset = remaining_size / 32 + 1; |
274 complete_offset = remaining_size / 32 + 1; |
273 } |
275 } |
274 |
276 |
275 #if EOE_DEBUG_LEVEL >= 2 |
277 #if EOE_DEBUG_LEVEL >= 2 |
276 EC_DBG("EoE %s TX sending fragment %u%s with %u octets (%u)." |
278 EC_SLAVE_DBG(slave, 0, "EoE %s TX sending fragment %u%s" |
277 " %u frames queued.\n", eoe->dev->name, eoe->tx_fragment_number, |
279 " with %u octets (%u). %u frames queued.\n", |
278 last_fragment ? "" : "+", current_size, complete_offset, |
280 eoe->dev->name, eoe->tx_fragment_number, |
279 eoe->tx_queued_frames); |
281 last_fragment ? "" : "+", current_size, complete_offset, |
|
282 eoe->tx_queued_frames); |
280 #endif |
283 #endif |
281 |
284 |
282 #if EOE_DEBUG_LEVEL >= 3 |
285 #if EOE_DEBUG_LEVEL >= 3 |
283 EC_DBG(""); |
286 EC_SLAVE_DBG(master, 0, ""); |
284 for (i = 0; i < current_size; i++) { |
287 for (i = 0; i < current_size; i++) { |
285 printk("%02X ", eoe->tx_frame->skb->data[eoe->tx_offset + i]); |
288 printk("%02X ", eoe->tx_frame->skb->data[eoe->tx_offset + i]); |
286 if ((i + 1) % 16 == 0) { |
289 if ((i + 1) % 16 == 0) { |
287 printk("\n"); |
290 printk("\n"); |
288 EC_DBG(""); |
291 EC_SLAVE_DBG(master, 0, ""); |
289 } |
292 } |
290 } |
293 } |
291 printk("\n"); |
294 printk("\n"); |
292 #endif |
295 #endif |
293 |
296 |
406 void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */) |
409 void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */) |
407 { |
410 { |
408 if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { |
411 if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { |
409 eoe->stats.rx_errors++; |
412 eoe->stats.rx_errors++; |
410 #if EOE_DEBUG_LEVEL >= 1 |
413 #if EOE_DEBUG_LEVEL >= 1 |
411 EC_WARN("Failed to receive mbox check datagram for %s.\n", |
414 EC_SLAVE_WARN(eoe->slave, "Failed to receive mbox" |
412 eoe->dev->name); |
415 " check datagram for %s.\n", eoe->dev->name); |
413 #endif |
416 #endif |
414 eoe->state = ec_eoe_state_tx_start; |
417 eoe->state = ec_eoe_state_tx_start; |
415 return; |
418 return; |
416 } |
419 } |
417 |
420 |
445 #endif |
448 #endif |
446 |
449 |
447 if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { |
450 if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) { |
448 eoe->stats.rx_errors++; |
451 eoe->stats.rx_errors++; |
449 #if EOE_DEBUG_LEVEL >= 1 |
452 #if EOE_DEBUG_LEVEL >= 1 |
450 EC_WARN("Failed to receive mbox fetch datagram for %s.\n", |
453 EC_SLAVE_WARN(eoe->slave, "Failed to receive mbox" |
451 eoe->dev->name); |
454 " fetch datagram for %s.\n", eoe->dev->name); |
452 #endif |
455 #endif |
453 eoe->state = ec_eoe_state_tx_start; |
456 eoe->state = ec_eoe_state_tx_start; |
454 return; |
457 return; |
455 } |
458 } |
456 |
459 |
457 data = ec_slave_mbox_fetch(eoe->slave, &eoe->datagram, |
460 data = ec_slave_mbox_fetch(eoe->slave, &eoe->datagram, |
458 &mbox_prot, &rec_size); |
461 &mbox_prot, &rec_size); |
459 if (IS_ERR(data)) { |
462 if (IS_ERR(data)) { |
460 eoe->stats.rx_errors++; |
463 eoe->stats.rx_errors++; |
461 #if EOE_DEBUG_LEVEL >= 1 |
464 #if EOE_DEBUG_LEVEL >= 1 |
462 EC_WARN("Invalid mailbox response for %s.\n", |
465 EC_SLAVE_WARN(eoe->slave, "Invalid mailbox response for %s.\n", |
463 eoe->dev->name); |
466 eoe->dev->name); |
464 #endif |
467 #endif |
465 eoe->state = ec_eoe_state_tx_start; |
468 eoe->state = ec_eoe_state_tx_start; |
466 return; |
469 return; |
467 } |
470 } |
468 |
471 |
469 if (mbox_prot != 0x02) { // EoE FIXME mailbox handler necessary |
472 if (mbox_prot != 0x02) { // EoE FIXME mailbox handler necessary |
470 eoe->stats.rx_errors++; |
473 eoe->stats.rx_errors++; |
471 #if EOE_DEBUG_LEVEL >= 1 |
474 #if EOE_DEBUG_LEVEL >= 1 |
472 EC_WARN("Other mailbox protocol response for %s.\n", |
475 EC_SLAVE_WARN(eoe->slave, "Other mailbox protocol response for %s.\n", |
473 eoe->dev->name); |
476 eoe->dev->name); |
474 #endif |
477 #endif |
475 eoe->state = ec_eoe_state_tx_start; |
478 eoe->state = ec_eoe_state_tx_start; |
476 return; |
479 return; |
477 } |
480 } |
478 |
481 |
479 frame_type = EC_READ_U16(data) & 0x000F; |
482 frame_type = EC_READ_U16(data) & 0x000F; |
480 |
483 |
481 if (frame_type != 0x00) { |
484 if (frame_type != 0x00) { |
482 #if EOE_DEBUG_LEVEL >= 1 |
485 #if EOE_DEBUG_LEVEL >= 1 |
483 EC_WARN("%s: Other frame received. Dropping.\n", eoe->dev->name); |
486 EC_SLAVE_WARN(eoe->slave, "%s: Other frame received." |
|
487 " Dropping.\n", eoe->dev->name); |
484 #endif |
488 #endif |
485 eoe->stats.rx_dropped++; |
489 eoe->stats.rx_dropped++; |
486 eoe->state = ec_eoe_state_tx_start; |
490 eoe->state = ec_eoe_state_tx_start; |
487 return; |
491 return; |
488 } |
492 } |
494 fragment_number = EC_READ_U16(data + 2) & 0x003F; |
498 fragment_number = EC_READ_U16(data + 2) & 0x003F; |
495 fragment_offset = (EC_READ_U16(data + 2) >> 6) & 0x003F; |
499 fragment_offset = (EC_READ_U16(data + 2) >> 6) & 0x003F; |
496 frame_number = (EC_READ_U16(data + 2) >> 12) & 0x000F; |
500 frame_number = (EC_READ_U16(data + 2) >> 12) & 0x000F; |
497 |
501 |
498 #if EOE_DEBUG_LEVEL >= 2 |
502 #if EOE_DEBUG_LEVEL >= 2 |
499 EC_DBG("EoE %s RX fragment %u%s, offset %u, frame %u%s," |
503 EC_SLAVE_DBG(eoe->slave, 0, "EoE %s RX fragment %u%s, offset %u," |
500 " %u octets\n", eoe->dev->name, fragment_number, |
504 " frame %u%s, %u octets\n", eoe->dev->name, fragment_number, |
501 last_fragment ? "" : "+", fragment_offset, frame_number, |
505 last_fragment ? "" : "+", fragment_offset, frame_number, |
502 time_appended ? ", + timestamp" : "", |
506 time_appended ? ", + timestamp" : "", |
503 time_appended ? rec_size - 8 : rec_size - 4); |
507 time_appended ? rec_size - 8 : rec_size - 4); |
504 #endif |
508 #endif |
505 |
509 |
506 #if EOE_DEBUG_LEVEL >= 3 |
510 #if EOE_DEBUG_LEVEL >= 3 |
507 EC_DBG(""); |
511 EC_SLAVE_DBG(eoe->slave, 0, ""); |
508 for (i = 0; i < rec_size - 4; i++) { |
512 for (i = 0; i < rec_size - 4; i++) { |
509 printk("%02X ", data[i + 4]); |
513 printk("%02X ", data[i + 4]); |
510 if ((i + 1) % 16 == 0) { |
514 if ((i + 1) % 16 == 0) { |
511 printk("\n"); |
515 printk("\n"); |
512 EC_DBG(""); |
516 EC_SLAVE_DBG(eoe->slave, 0, ""); |
513 } |
517 } |
514 } |
518 } |
515 printk("\n"); |
519 printk("\n"); |
516 #endif |
520 #endif |
517 |
521 |
518 data_size = time_appended ? rec_size - 8 : rec_size - 4; |
522 data_size = time_appended ? rec_size - 8 : rec_size - 4; |
519 |
523 |
520 if (!fragment_number) { |
524 if (!fragment_number) { |
521 if (eoe->rx_skb) { |
525 if (eoe->rx_skb) { |
522 EC_WARN("EoE RX freeing old socket buffer...\n"); |
526 EC_SLAVE_WARN(eoe->slave, "EoE RX freeing old socket buffer.\n"); |
523 dev_kfree_skb(eoe->rx_skb); |
527 dev_kfree_skb(eoe->rx_skb); |
524 } |
528 } |
525 |
529 |
526 // new socket buffer |
530 // new socket buffer |
527 if (!(eoe->rx_skb = dev_alloc_skb(fragment_offset * 32))) { |
531 if (!(eoe->rx_skb = dev_alloc_skb(fragment_offset * 32))) { |
528 if (printk_ratelimit()) |
532 if (printk_ratelimit()) |
529 EC_WARN("EoE RX low on mem. frame dropped.\n"); |
533 EC_SLAVE_WARN(eoe->slave, "EoE RX low on mem," |
|
534 " frame dropped.\n"); |
530 eoe->stats.rx_dropped++; |
535 eoe->stats.rx_dropped++; |
531 eoe->state = ec_eoe_state_tx_start; |
536 eoe->state = ec_eoe_state_tx_start; |
532 return; |
537 return; |
533 } |
538 } |
534 |
539 |
549 fragment_number != eoe->rx_expected_fragment) { |
554 fragment_number != eoe->rx_expected_fragment) { |
550 dev_kfree_skb(eoe->rx_skb); |
555 dev_kfree_skb(eoe->rx_skb); |
551 eoe->rx_skb = NULL; |
556 eoe->rx_skb = NULL; |
552 eoe->stats.rx_errors++; |
557 eoe->stats.rx_errors++; |
553 #if EOE_DEBUG_LEVEL >= 1 |
558 #if EOE_DEBUG_LEVEL >= 1 |
554 EC_WARN("Fragmenting error at %s.\n", eoe->dev->name); |
559 EC_SLAVE_WARN(eoe->slave, "Fragmenting error at %s.\n", |
|
560 eoe->dev->name); |
555 #endif |
561 #endif |
556 eoe->state = ec_eoe_state_tx_start; |
562 eoe->state = ec_eoe_state_tx_start; |
557 return; |
563 return; |
558 } |
564 } |
559 } |
565 } |
567 eoe->stats.rx_packets++; |
573 eoe->stats.rx_packets++; |
568 eoe->stats.rx_bytes += eoe->rx_skb->len; |
574 eoe->stats.rx_bytes += eoe->rx_skb->len; |
569 eoe->rx_counter += eoe->rx_skb->len; |
575 eoe->rx_counter += eoe->rx_skb->len; |
570 |
576 |
571 #if EOE_DEBUG_LEVEL >= 2 |
577 #if EOE_DEBUG_LEVEL >= 2 |
572 EC_DBG("EoE %s RX frame completed with %u octets.\n", |
578 EC_SLAVE_DBG(eoe->slave, 0, "EoE %s RX frame completed" |
573 eoe->dev->name, eoe->rx_skb->len); |
579 " with %u octets.\n", eoe->dev->name, eoe->rx_skb->len); |
574 #endif |
580 #endif |
575 |
581 |
576 // pass socket buffer to network stack |
582 // pass socket buffer to network stack |
577 eoe->rx_skb->dev = eoe->dev; |
583 eoe->rx_skb->dev = eoe->dev; |
578 eoe->rx_skb->protocol = eth_type_trans(eoe->rx_skb, eoe->dev); |
584 eoe->rx_skb->protocol = eth_type_trans(eoe->rx_skb, eoe->dev); |
579 eoe->rx_skb->ip_summed = CHECKSUM_UNNECESSARY; |
585 eoe->rx_skb->ip_summed = CHECKSUM_UNNECESSARY; |
580 if (netif_rx(eoe->rx_skb)) { |
586 if (netif_rx(eoe->rx_skb)) { |
581 EC_WARN("EoE RX netif_rx failed.\n"); |
587 EC_SLAVE_WARN(eoe->slave, "EoE RX netif_rx failed.\n"); |
582 } |
588 } |
583 eoe->rx_skb = NULL; |
589 eoe->rx_skb = NULL; |
584 |
590 |
585 eoe->state = ec_eoe_state_tx_start; |
591 eoe->state = ec_eoe_state_tx_start; |
586 } |
592 } |
587 else { |
593 else { |
588 eoe->rx_expected_fragment++; |
594 eoe->rx_expected_fragment++; |
589 #if EOE_DEBUG_LEVEL >= 2 |
595 #if EOE_DEBUG_LEVEL >= 2 |
590 EC_DBG("EoE %s RX expecting fragment %u\n", |
596 EC_SLAVE_DBG(eoe->slave, 0, "EoE %s RX expecting fragment %u\n", |
591 eoe->dev->name, eoe->rx_expected_fragment); |
597 eoe->dev->name, eoe->rx_expected_fragment); |
592 #endif |
598 #endif |
593 eoe->state = ec_eoe_state_rx_start; |
599 eoe->state = ec_eoe_state_rx_start; |
594 } |
600 } |
595 } |
601 } |
652 kfree(eoe->tx_frame); |
658 kfree(eoe->tx_frame); |
653 eoe->tx_frame = NULL; |
659 eoe->tx_frame = NULL; |
654 eoe->stats.tx_errors++; |
660 eoe->stats.tx_errors++; |
655 eoe->state = ec_eoe_state_rx_start; |
661 eoe->state = ec_eoe_state_rx_start; |
656 #if EOE_DEBUG_LEVEL >= 1 |
662 #if EOE_DEBUG_LEVEL >= 1 |
657 EC_WARN("Send error at %s.\n", eoe->dev->name); |
663 EC_SLAVE_WARN(eoe->slave, "Send error at %s.\n", eoe->dev->name); |
658 #endif |
664 #endif |
659 return; |
665 return; |
660 } |
666 } |
661 |
667 |
662 #if EOE_DEBUG_LEVEL >= 2 |
668 #if EOE_DEBUG_LEVEL >= 2 |
663 if (wakeup) |
669 if (wakeup) |
664 EC_DBG("EoE %s waking up TX queue...\n", eoe->dev->name); |
670 EC_SLAVE_DBG(eoe->slave, 0, "EoE %s waking up TX queue...\n", |
|
671 eoe->dev->name); |
665 #endif |
672 #endif |
666 |
673 |
667 eoe->tries = EC_EOE_TRIES; |
674 eoe->tries = EC_EOE_TRIES; |
668 eoe->state = ec_eoe_state_tx_sent; |
675 eoe->state = ec_eoe_state_tx_sent; |
669 } |
676 } |
682 eoe->tries--; // try again |
689 eoe->tries--; // try again |
683 eoe->queue_datagram = 1; |
690 eoe->queue_datagram = 1; |
684 } else { |
691 } else { |
685 eoe->stats.tx_errors++; |
692 eoe->stats.tx_errors++; |
686 #if EOE_DEBUG_LEVEL >= 1 |
693 #if EOE_DEBUG_LEVEL >= 1 |
687 EC_WARN("Failed to receive send datagram for %s after %u tries.\n", |
694 EC_SLAVE_WARN(eoe->slave, "Failed to receive send" |
|
695 " datagram for %s after %u tries.\n", |
688 eoe->dev->name, EC_EOE_TRIES); |
696 eoe->dev->name, EC_EOE_TRIES); |
689 #endif |
697 #endif |
690 eoe->state = ec_eoe_state_rx_start; |
698 eoe->state = ec_eoe_state_rx_start; |
691 } |
699 } |
692 return; |
700 return; |
697 eoe->tries--; // try again |
705 eoe->tries--; // try again |
698 eoe->queue_datagram = 1; |
706 eoe->queue_datagram = 1; |
699 } else { |
707 } else { |
700 eoe->stats.tx_errors++; |
708 eoe->stats.tx_errors++; |
701 #if EOE_DEBUG_LEVEL >= 1 |
709 #if EOE_DEBUG_LEVEL >= 1 |
702 EC_WARN("No sending response for %s after %u tries.\n", |
710 EC_SLAVE_WARN(eoe->slave, "No sending response" |
|
711 " for %s after %u tries.\n", |
703 eoe->dev->name, EC_EOE_TRIES); |
712 eoe->dev->name, EC_EOE_TRIES); |
704 #endif |
713 #endif |
705 eoe->state = ec_eoe_state_rx_start; |
714 eoe->state = ec_eoe_state_rx_start; |
706 } |
715 } |
707 return; |
716 return; |
722 dev_kfree_skb(eoe->tx_frame->skb); |
731 dev_kfree_skb(eoe->tx_frame->skb); |
723 kfree(eoe->tx_frame); |
732 kfree(eoe->tx_frame); |
724 eoe->tx_frame = NULL; |
733 eoe->tx_frame = NULL; |
725 eoe->stats.tx_errors++; |
734 eoe->stats.tx_errors++; |
726 #if EOE_DEBUG_LEVEL >= 1 |
735 #if EOE_DEBUG_LEVEL >= 1 |
727 EC_WARN("Send error at %s.\n", eoe->dev->name); |
736 EC_SLAVE_WARN(eoe->slave, "Send error at %s.\n", eoe->dev->name); |
728 #endif |
737 #endif |
729 eoe->state = ec_eoe_state_rx_start; |
738 eoe->state = ec_eoe_state_rx_start; |
730 } |
739 } |
731 } |
740 } |
732 } |
741 } |
784 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
793 ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev)); |
785 ec_eoe_frame_t *frame; |
794 ec_eoe_frame_t *frame; |
786 |
795 |
787 #if 0 |
796 #if 0 |
788 if (skb->len > eoe->slave->configured_tx_mailbox_size - 10) { |
797 if (skb->len > eoe->slave->configured_tx_mailbox_size - 10) { |
789 EC_WARN("EoE TX frame (%u octets) exceeds MTU. dropping.\n", skb->len); |
798 EC_SLAVE_WARN(eoe->slave, "EoE TX frame (%u octets)" |
|
799 " exceeds MTU. dropping.\n", skb->len); |
790 dev_kfree_skb(skb); |
800 dev_kfree_skb(skb); |
791 eoe->stats.tx_dropped++; |
801 eoe->stats.tx_dropped++; |
792 return 0; |
802 return 0; |
793 } |
803 } |
794 #endif |
804 #endif |
795 |
805 |
796 if (!(frame = |
806 if (!(frame = |
797 (ec_eoe_frame_t *) kmalloc(sizeof(ec_eoe_frame_t), GFP_ATOMIC))) { |
807 (ec_eoe_frame_t *) kmalloc(sizeof(ec_eoe_frame_t), GFP_ATOMIC))) { |
798 if (printk_ratelimit()) |
808 if (printk_ratelimit()) |
799 EC_WARN("EoE TX: low on mem. frame dropped.\n"); |
809 EC_SLAVE_WARN(eoe->slave, "EoE TX: low on mem. frame dropped.\n"); |
800 return 1; |
810 return 1; |
801 } |
811 } |
802 |
812 |
803 frame->skb = skb; |
813 frame->skb = skb; |
804 |
814 |
810 eoe->tx_queue_active = 0; |
820 eoe->tx_queue_active = 0; |
811 } |
821 } |
812 up(&eoe->tx_queue_sem); |
822 up(&eoe->tx_queue_sem); |
813 |
823 |
814 #if EOE_DEBUG_LEVEL >= 2 |
824 #if EOE_DEBUG_LEVEL >= 2 |
815 EC_DBG("EoE %s TX queued frame with %u octets (%u frames queued).\n", |
825 EC_SLAVE_DBG(eoe->slave, 0, "EoE %s TX queued frame" |
816 eoe->dev->name, skb->len, eoe->tx_queued_frames); |
826 " with %u octets (%u frames queued).\n", |
|
827 eoe->dev->name, skb->len, eoe->tx_queued_frames); |
817 if (!eoe->tx_queue_active) |
828 if (!eoe->tx_queue_active) |
818 EC_WARN("EoE TX queue is now full.\n"); |
829 EC_SLAVE_WARN(eoe->slave, "EoE TX queue is now full.\n"); |
819 #endif |
830 #endif |
820 |
831 |
821 return 0; |
832 return 0; |
822 } |
833 } |
823 |
834 |