ec_netdev.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. typedef struct ec_netdev {
  11. ec_master_t *master;
  12. struct chry_phy_device phydev;
  13. ec_netdev_index_t index;
  14. char name[20];
  15. uint8_t mac_addr[6];
  16. bool link_state;
  17. uint8_t tx_frame_index;
  18. unsigned long jiffies_poll;
  19. // Frame statistics
  20. uint64_t tx_count; /**< Number of frames sent. */
  21. uint64_t last_tx_count; /**< Number of frames sent of last statistics cycle.*/
  22. uint64_t rx_count; /**< Number of frames received. */
  23. uint64_t last_rx_count; /**< Number of frames received of last statistics cycle.*/
  24. uint64_t tx_bytes; /**< Number of bytes sent. */
  25. uint64_t last_tx_bytes; /**< Number of bytes sent of last statistics cycle.*/
  26. uint64_t rx_bytes; /**< Number of bytes received. */
  27. uint64_t last_rx_bytes; /**< Number of bytes received of last statistics cycle.*/
  28. uint64_t tx_errors; /**< Number of transmit errors. */
  29. int32_t tx_frame_rates[EC_RATE_COUNT]; /**< Transmit rates in frames/s for different statistics cycle periods.*/
  30. int32_t rx_frame_rates[EC_RATE_COUNT]; /**< Receive rates in frames/s for different statistics cycle periods.*/
  31. int32_t tx_byte_rates[EC_RATE_COUNT]; /**< Transmit rates in byte/s for different statistics cycle periods.*/
  32. int32_t rx_byte_rates[EC_RATE_COUNT]; /**< Receive rates in byte/s for different statistics cycle periods.*/
  33. } ec_netdev_t;
  34. void ec_netdev_clear_stats(ec_netdev_t *netdev);
  35. void ec_netdev_update_stats(ec_netdev_t *netdev);
  36. ec_netdev_t *ec_netdev_init(uint8_t netdev_index);
  37. void ec_netdev_poll_link_state(ec_netdev_t *netdev);
  38. uint8_t *ec_netdev_get_txbuf(ec_netdev_t *netdev);
  39. int ec_netdev_send(ec_netdev_t *netdev, uint32_t size);
  40. void ec_netdev_receive(ec_netdev_t *netdev, uint8_t *frame, uint32_t size);
  41. #endif