ethernet_mgmt.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Copyright (c) 2018 Intel Corporation.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief Ethernet Management interface public header
  9. */
  10. #ifndef ZEPHYR_INCLUDE_NET_ETHERNET_MGMT_H_
  11. #define ZEPHYR_INCLUDE_NET_ETHERNET_MGMT_H_
  12. #include <net/ethernet.h>
  13. #include <net/net_mgmt.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @brief Ethernet library
  19. * @defgroup ethernet_mgmt Ethernet Library
  20. * @ingroup networking
  21. * @{
  22. */
  23. /** @cond INTERNAL_HIDDEN */
  24. #define _NET_ETHERNET_LAYER NET_MGMT_LAYER_L2
  25. #define _NET_ETHERNET_CODE 0x208
  26. #define _NET_ETHERNET_BASE (NET_MGMT_IFACE_BIT | \
  27. NET_MGMT_LAYER(_NET_ETHERNET_LAYER) | \
  28. NET_MGMT_LAYER_CODE(_NET_ETHERNET_CODE))
  29. #define _NET_ETHERNET_EVENT (_NET_ETHERNET_BASE | NET_MGMT_EVENT_BIT)
  30. enum net_request_ethernet_cmd {
  31. NET_REQUEST_ETHERNET_CMD_SET_AUTO_NEGOTIATION = 1,
  32. NET_REQUEST_ETHERNET_CMD_SET_LINK,
  33. NET_REQUEST_ETHERNET_CMD_SET_DUPLEX,
  34. NET_REQUEST_ETHERNET_CMD_SET_MAC_ADDRESS,
  35. NET_REQUEST_ETHERNET_CMD_SET_QAV_PARAM,
  36. NET_REQUEST_ETHERNET_CMD_SET_QBV_PARAM,
  37. NET_REQUEST_ETHERNET_CMD_SET_QBU_PARAM,
  38. NET_REQUEST_ETHERNET_CMD_SET_TXTIME_PARAM,
  39. NET_REQUEST_ETHERNET_CMD_SET_PROMISC_MODE,
  40. NET_REQUEST_ETHERNET_CMD_GET_PRIORITY_QUEUES_NUM,
  41. NET_REQUEST_ETHERNET_CMD_GET_QAV_PARAM,
  42. NET_REQUEST_ETHERNET_CMD_GET_PORTS_NUM,
  43. NET_REQUEST_ETHERNET_CMD_GET_QBV_PARAM,
  44. NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM,
  45. NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM,
  46. };
  47. #define NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION \
  48. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_AUTO_NEGOTIATION)
  49. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION);
  50. #define NET_REQUEST_ETHERNET_SET_LINK \
  51. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_LINK)
  52. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_LINK);
  53. #define NET_REQUEST_ETHERNET_SET_DUPLEX \
  54. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_DUPLEX)
  55. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_DUPLEX);
  56. #define NET_REQUEST_ETHERNET_SET_MAC_ADDRESS \
  57. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_MAC_ADDRESS)
  58. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS);
  59. #define NET_REQUEST_ETHERNET_SET_QAV_PARAM \
  60. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QAV_PARAM)
  61. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QAV_PARAM);
  62. #define NET_REQUEST_ETHERNET_GET_PORTS_NUM \
  63. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_PORTS_NUM)
  64. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_PORTS_NUM);
  65. #define NET_REQUEST_ETHERNET_SET_QBV_PARAM \
  66. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QBV_PARAM)
  67. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QBV_PARAM);
  68. #define NET_REQUEST_ETHERNET_SET_QBU_PARAM \
  69. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QBU_PARAM)
  70. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QBU_PARAM);
  71. #define NET_REQUEST_ETHERNET_SET_TXTIME_PARAM \
  72. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_TXTIME_PARAM)
  73. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXTIME_PARAM);
  74. #define NET_REQUEST_ETHERNET_SET_PROMISC_MODE \
  75. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_PROMISC_MODE)
  76. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_PROMISC_MODE);
  77. #define NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM \
  78. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_PRIORITY_QUEUES_NUM)
  79. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM);
  80. #define NET_REQUEST_ETHERNET_GET_QAV_PARAM \
  81. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QAV_PARAM)
  82. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QAV_PARAM);
  83. #define NET_REQUEST_ETHERNET_GET_QBV_PARAM \
  84. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QBV_PARAM)
  85. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBV_PARAM);
  86. #define NET_REQUEST_ETHERNET_GET_QBU_PARAM \
  87. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM)
  88. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBU_PARAM);
  89. #define NET_REQUEST_ETHERNET_GET_TXTIME_PARAM \
  90. (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM)
  91. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM);
  92. struct net_eth_addr;
  93. struct ethernet_qav_param;
  94. struct ethernet_qbv_param;
  95. struct ethernet_qbu_param;
  96. struct ethernet_txtime_param;
  97. struct ethernet_req_params {
  98. union {
  99. bool auto_negotiation;
  100. bool full_duplex;
  101. bool promisc_mode;
  102. struct {
  103. bool link_10bt;
  104. bool link_100bt;
  105. bool link_1000bt;
  106. } l;
  107. struct net_eth_addr mac_address;
  108. struct ethernet_qav_param qav_param;
  109. struct ethernet_qbv_param qbv_param;
  110. struct ethernet_qbu_param qbu_param;
  111. struct ethernet_txtime_param txtime_param;
  112. int priority_queues_num;
  113. int ports_num;
  114. };
  115. };
  116. enum net_event_ethernet_cmd {
  117. NET_EVENT_ETHERNET_CMD_CARRIER_ON = 1,
  118. NET_EVENT_ETHERNET_CMD_CARRIER_OFF,
  119. NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED,
  120. NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED,
  121. };
  122. #define NET_EVENT_ETHERNET_CARRIER_ON \
  123. (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_CARRIER_ON)
  124. #define NET_EVENT_ETHERNET_CARRIER_OFF \
  125. (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_CARRIER_OFF)
  126. #define NET_EVENT_ETHERNET_VLAN_TAG_ENABLED \
  127. (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED)
  128. #define NET_EVENT_ETHERNET_VLAN_TAG_DISABLED \
  129. (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED)
  130. struct net_if;
  131. /** @endcond */
  132. /**
  133. * @brief Raise CARRIER_ON event when Ethernet is connected.
  134. *
  135. * @param iface Ethernet network interface.
  136. */
  137. #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
  138. void ethernet_mgmt_raise_carrier_on_event(struct net_if *iface);
  139. #else
  140. static inline void ethernet_mgmt_raise_carrier_on_event(struct net_if *iface)
  141. {
  142. ARG_UNUSED(iface);
  143. }
  144. #endif
  145. /**
  146. * @brief Raise CARRIER_OFF event when Ethernet is disconnected.
  147. *
  148. * @param iface Ethernet network interface.
  149. */
  150. #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
  151. void ethernet_mgmt_raise_carrier_off_event(struct net_if *iface);
  152. #else
  153. static inline void ethernet_mgmt_raise_carrier_off_event(struct net_if *iface)
  154. {
  155. ARG_UNUSED(iface);
  156. }
  157. #endif
  158. /**
  159. * @brief Raise VLAN_ENABLED event when VLAN is enabled.
  160. *
  161. * @param iface Ethernet network interface.
  162. * @param tag VLAN tag which is enabled.
  163. */
  164. #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
  165. void ethernet_mgmt_raise_vlan_enabled_event(struct net_if *iface, uint16_t tag);
  166. #else
  167. static inline void ethernet_mgmt_raise_vlan_enabled_event(struct net_if *iface,
  168. uint16_t tag)
  169. {
  170. ARG_UNUSED(iface);
  171. ARG_UNUSED(tag);
  172. }
  173. #endif
  174. /**
  175. * @brief Raise VLAN_DISABLED event when VLAN is disabled.
  176. *
  177. * @param iface Ethernet network interface.
  178. * @param tag VLAN tag which is disabled.
  179. */
  180. #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
  181. void ethernet_mgmt_raise_vlan_disabled_event(struct net_if *iface,
  182. uint16_t tag);
  183. #else
  184. static inline void ethernet_mgmt_raise_vlan_disabled_event(struct net_if *iface,
  185. uint16_t tag)
  186. {
  187. ARG_UNUSED(iface);
  188. ARG_UNUSED(tag);
  189. }
  190. #endif
  191. /**
  192. * @}
  193. */
  194. #ifdef __cplusplus
  195. }
  196. #endif
  197. #endif /* ZEPHYR_INCLUDE_NET_ETHERNET_MGMT_H_ */