drv_enet.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (c) 2021-2022 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef DRV_ENET_H
  8. #define DRV_ENET_H
  9. #include <netif/ethernetif.h>
  10. #include "hpm_enet_drv.h"
  11. #include "board.h"
  12. typedef enum {
  13. ENET_MAC_ADDR_PARA_ERROR = -1,
  14. ENET_MAC_ADDR_FROM_OTP_MAC,
  15. ENET_MAC_ADDR_FROM_OTP_UUID,
  16. ENET_MAC_ADDR_FROM_MACRO
  17. } enet_mac_addr_t;
  18. typedef struct {
  19. uint8_t mac_addr0;
  20. uint8_t mac_addr1;
  21. uint8_t mac_addr2;
  22. uint8_t mac_addr3;
  23. uint8_t mac_addr4;
  24. uint8_t mac_addr5;
  25. } mac_init_t;
  26. typedef struct {
  27. ENET_Type * instance;
  28. enet_desc_t desc;
  29. enet_mac_config_t mac_config;
  30. uint8_t media_interface;
  31. uint32_t irq_number;
  32. bool int_refclk;
  33. uint8_t tx_delay;
  34. uint8_t rx_delay;
  35. enet_int_config_t int_config;
  36. #if __USE_ENET_PTP
  37. bool ptp_enable;
  38. uint32_t ptp_clk_src;
  39. enet_ptp_config_t ptp_config;
  40. enet_ptp_ts_update_t ptp_timestamp;
  41. #endif
  42. } enet_device;
  43. typedef struct _hpm_enet
  44. {
  45. const char *name;
  46. ENET_Type *base;
  47. clock_name_t clock_name;
  48. int32_t irq_num;
  49. uint8_t inf;
  50. struct eth_device *eth_dev;
  51. enet_device *enet_dev;
  52. enet_buff_config_t *rx_buff_cfg;
  53. enet_buff_config_t *tx_buff_cfg;
  54. volatile enet_rx_desc_t *dma_rx_desc_tab;
  55. volatile enet_tx_desc_t *dma_tx_desc_tab;
  56. uint8_t tx_delay;
  57. uint8_t rx_delay;
  58. bool int_refclk;
  59. #if __USE_ENET_PTP
  60. bool ptp_enable;
  61. uint32_t ptp_clk_src;
  62. enet_ptp_config_t *ptp_config;
  63. enet_ptp_ts_update_t *ptp_timestamp;
  64. #endif
  65. } hpm_enet_t;
  66. #define IS_UUID_INVALID(UUID) (UUID[0] == 0 && \
  67. UUID[1] == 0 && \
  68. UUID[2] == 0 && \
  69. UUID[3] == 0)
  70. #define IS_MAC_INVALID(MAC) (MAC[0] == 0 && \
  71. MAC[1] == 0 && \
  72. MAC[2] == 0 && \
  73. MAC[3] == 0 && \
  74. MAC[4] == 0 && \
  75. MAC[5] == 0)
  76. #if ENET_SOC_RGMII_EN
  77. #ifndef ENET0_TX_BUFF_COUNT
  78. #define ENET0_TX_BUFF_COUNT (50U)
  79. #endif
  80. #ifndef ENET0_RX_BUFF_COUNT
  81. #define ENET0_RX_BUFF_COUNT (60U)
  82. #endif
  83. #else
  84. #ifndef ENET0_TX_BUFF_COUNT
  85. #define ENET0_TX_BUFF_COUNT (10U)
  86. #endif
  87. #ifndef ENET0_RX_BUFF_COUNT
  88. #define ENET0_RX_BUFF_COUNT (20U)
  89. #endif
  90. #endif
  91. #ifndef ENET0_RX_BUFF_SIZE
  92. #define ENET0_RX_BUFF_SIZE ENET_MAX_FRAME_SIZE
  93. #endif
  94. #ifndef ENET0_TX_BUFF_SIZE
  95. #define ENET0_TX_BUFF_SIZE ENET_MAX_FRAME_SIZE
  96. #endif
  97. #ifndef ENET1_TX_BUFF_COUNT
  98. #define ENET1_TX_BUFF_COUNT (10U)
  99. #endif
  100. #ifndef ENET1_RX_BUFF_COUNT
  101. #define ENET1_RX_BUFF_COUNT (30U)
  102. #endif
  103. #ifndef ENET1_RX_BUFF_SIZE
  104. #define ENET1_RX_BUFF_SIZE ENET_MAX_FRAME_SIZE
  105. #endif
  106. #ifndef ENET1_TX_BUFF_SIZE
  107. #define ENET1_TX_BUFF_SIZE ENET_MAX_FRAME_SIZE
  108. #endif
  109. #ifndef MAC0_ADDR0
  110. #define MAC0_ADDR0 (0x98U)
  111. #endif
  112. #ifndef MAC0_ADDR1
  113. #define MAC0_ADDR1 (0x2CU)
  114. #endif
  115. #ifndef MAC0_ADDR2
  116. #define MAC0_ADDR2 (0xBCU)
  117. #endif
  118. #ifndef MAC0_ADDR3
  119. #define MAC0_ADDR3 (0xB1U)
  120. #endif
  121. #ifndef MAC0_ADDR4
  122. #define MAC0_ADDR4 (0x9FU)
  123. #endif
  124. #ifndef MAC0_ADDR5
  125. #define MAC0_ADDR5 (0x17U)
  126. #endif
  127. #ifndef MAC1_ADDR0
  128. #define MAC1_ADDR0 (0x98U)
  129. #endif
  130. #ifndef MAC1_ADDR1
  131. #define MAC1_ADDR1 (0x2CU)
  132. #endif
  133. #ifndef MAC1_ADDR2
  134. #define MAC1_ADDR2 (0xBCU)
  135. #endif
  136. #ifndef MAC1_ADDR3
  137. #define MAC1_ADDR3 (0xB1U)
  138. #endif
  139. #ifndef MAC1_ADDR4
  140. #define MAC1_ADDR4 (0x9FU)
  141. #endif
  142. #ifndef MAC1_ADDR5
  143. #define MAC1_ADDR5 (0x27U)
  144. #endif
  145. int rt_hw_eth_init(void);
  146. #endif /* DRV_ENET_H */
  147. /* DRV_GPIO_H */