ec_netdev.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2025, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef EC_NETDEV_H
  7. #define EC_NETDEV_H
  8. #include "phy/chry_phy.h"
  9. typedef struct ec_master ec_master_t;
  10. /** Netdev statistics.
  11. */
  12. typedef struct {
  13. uint64_t tx_count; /**< Number of frames sent. */
  14. uint64_t last_tx_count; /**< Number of frames sent of last statistics cycle. */
  15. uint64_t rx_count; /**< Number of frames received. */
  16. uint64_t last_rx_count; /**< Number of frames received of last statistics cycle. */
  17. uint64_t tx_bytes; /**< Number of bytes sent. */
  18. uint64_t last_tx_bytes; /**< Number of bytes sent of last statistics cycle. */
  19. uint64_t rx_bytes; /**< Number of bytes received. */
  20. uint64_t last_rx_bytes; /**< Number of bytes received of last statistics cycle. */
  21. uint64_t tx_errors; /**< Number of transmit errors. */
  22. uint64_t loss_count; /**< Number of lost frames. */
  23. int32_t tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in frames/s for different statistics cycle periods.*/
  24. int32_t rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in frames/s for different statistics cycle periods.*/
  25. int32_t tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s for different statistics cycle periods. */
  26. int32_t rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s for different statistics cycle periods. */
  27. int32_t loss_rates[EC_RATE_COUNT]; /**< Frame loss rates for different statistics cycle periods. */
  28. uint64_t last_jiffies; /**< Jiffies of last statistic cycle [ns]. */
  29. } ec_netdev_stats_t;
  30. typedef struct ec_netdev {
  31. ec_master_t *master;
  32. struct chry_phy_device phydev;
  33. uint8_t index;
  34. char name[24];
  35. uint8_t mac_addr[6];
  36. bool link_state;
  37. uint8_t tx_frame_index;
  38. ec_netdev_stats_t stats;
  39. } ec_netdev_t;
  40. void ec_netdev_update_stats(ec_netdev_t *netdev);
  41. ec_netdev_t *ec_netdev_init(uint8_t netdev_index);
  42. void ec_netdev_poll_link_state(ec_netdev_t *netdev);
  43. uint8_t *ec_netdev_get_txbuf(ec_netdev_t *netdev);
  44. int ec_netdev_send(ec_netdev_t *netdev, uint32_t size);
  45. void ec_netdev_receive(ec_netdev_t *netdev, uint8_t *frame, uint32_t size);
  46. #endif