Driver_ETH_MAC.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Copyright (c) 2013-2020 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * $Date: 24. January 2020
  19. * $Revision: V2.2
  20. *
  21. * Project: Ethernet MAC (Media Access Control) Driver definitions
  22. */
  23. /* History:
  24. * Version 2.2
  25. * Removed volatile from ARM_ETH_LINK_INFO
  26. * Version 2.1
  27. * Added ARM_ETH_MAC_SLEEP Control
  28. * Version 2.0
  29. * Changed MAC Address handling:
  30. * moved from ARM_ETH_MAC_Initialize
  31. * to new functions ARM_ETH_MAC_GetMacAddress and ARM_ETH_MAC_SetMacAddress
  32. * Replaced ARM_ETH_MAC_SetMulticastAddr function with ARM_ETH_MAC_SetAddressFilter
  33. * Extended ARM_ETH_MAC_SendFrame function with flags
  34. * Added ARM_ETH_MAC_Control function:
  35. * more control options (Broadcast, Multicast, Checksum offload, VLAN, ...)
  36. * replaces ARM_ETH_MAC_SetMode
  37. * replaces ARM_ETH_MAC_EnableTx, ARM_ETH_MAC_EnableRx
  38. * Added optional event on transmitted frame
  39. * Added support for PTP (Precision Time Protocol) through new functions:
  40. * ARM_ETH_MAC_ControlTimer
  41. * ARM_ETH_MAC_GetRxFrameTime
  42. * ARM_ETH_MAC_GetTxFrameTime
  43. * Changed prefix ARM_DRV -> ARM_DRIVER
  44. * Changed return values of some functions to int32_t
  45. * Version 1.10
  46. * Name space prefix ARM_ added
  47. * Version 1.01
  48. * Renamed capabilities items for checksum offload
  49. * Version 1.00
  50. * Initial release
  51. */
  52. #ifndef DRIVER_ETH_MAC_H_
  53. #define DRIVER_ETH_MAC_H_
  54. #ifdef __cplusplus
  55. extern "C"
  56. {
  57. #endif
  58. #include "Driver_ETH.h"
  59. #define ARM_ETH_MAC_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,2) /* API version */
  60. #define _ARM_Driver_ETH_MAC_(n) Driver_ETH_MAC##n
  61. #define ARM_Driver_ETH_MAC_(n) _ARM_Driver_ETH_MAC_(n)
  62. /****** Ethernet MAC Control Codes *****/
  63. #define ARM_ETH_MAC_CONFIGURE (0x01UL) ///< Configure MAC; arg = configuration
  64. #define ARM_ETH_MAC_CONTROL_TX (0x02UL) ///< Transmitter; arg: 0=disabled (default), 1=enabled
  65. #define ARM_ETH_MAC_CONTROL_RX (0x03UL) ///< Receiver; arg: 0=disabled (default), 1=enabled
  66. #define ARM_ETH_MAC_FLUSH (0x04UL) ///< Flush buffer; arg = ARM_ETH_MAC_FLUSH_...
  67. #define ARM_ETH_MAC_SLEEP (0x05UL) ///< Sleep mode; arg: 1=enter and wait for Magic packet, 0=exit
  68. #define ARM_ETH_MAC_VLAN_FILTER (0x06UL) ///< VLAN Filter for received frames; arg15..0: VLAN Tag; arg16: optional ARM_ETH_MAC_VLAN_FILTER_ID_ONLY; 0=disabled (default)
  69. /*----- Ethernet MAC Configuration -----*/
  70. #define ARM_ETH_MAC_SPEED_Pos 0
  71. #define ARM_ETH_MAC_SPEED_Msk (3UL << ARM_ETH_MAC_SPEED_Pos)
  72. #define ARM_ETH_MAC_SPEED_10M (ARM_ETH_SPEED_10M << ARM_ETH_MAC_SPEED_Pos) ///< 10 Mbps link speed
  73. #define ARM_ETH_MAC_SPEED_100M (ARM_ETH_SPEED_100M << ARM_ETH_MAC_SPEED_Pos) ///< 100 Mbps link speed
  74. #define ARM_ETH_MAC_SPEED_1G (ARM_ETH_SPEED_1G << ARM_ETH_MAC_SPEED_Pos) ///< 1 Gpbs link speed
  75. #define ARM_ETH_MAC_DUPLEX_Pos 2
  76. #define ARM_ETH_MAC_DUPLEX_Msk (1UL << ARM_ETH_MAC_DUPLEX_Pos)
  77. #define ARM_ETH_MAC_DUPLEX_HALF (ARM_ETH_DUPLEX_HALF << ARM_ETH_MAC_DUPLEX_Pos) ///< Half duplex link
  78. #define ARM_ETH_MAC_DUPLEX_FULL (ARM_ETH_DUPLEX_FULL << ARM_ETH_MAC_DUPLEX_Pos) ///< Full duplex link
  79. #define ARM_ETH_MAC_LOOPBACK (1UL << 4) ///< Loop-back test mode
  80. #define ARM_ETH_MAC_CHECKSUM_OFFLOAD_RX (1UL << 5) ///< Receiver Checksum offload
  81. #define ARM_ETH_MAC_CHECKSUM_OFFLOAD_TX (1UL << 6) ///< Transmitter Checksum offload
  82. #define ARM_ETH_MAC_ADDRESS_BROADCAST (1UL << 7) ///< Accept frames with Broadcast address
  83. #define ARM_ETH_MAC_ADDRESS_MULTICAST (1UL << 8) ///< Accept frames with any Multicast address
  84. #define ARM_ETH_MAC_ADDRESS_ALL (1UL << 9) ///< Accept frames with any address (Promiscuous Mode)
  85. /*----- Ethernet MAC Flush Flags -----*/
  86. #define ARM_ETH_MAC_FLUSH_RX (1UL << 0) ///< Flush Receive buffer
  87. #define ARM_ETH_MAC_FLUSH_TX (1UL << 1) ///< Flush Transmit buffer
  88. /*----- Ethernet MAC VLAN Filter Flag -----*/
  89. #define ARM_ETH_MAC_VLAN_FILTER_ID_ONLY (1UL << 16) ///< Compare only the VLAN Identifier (12-bit)
  90. /****** Ethernet MAC Frame Transmit Flags *****/
  91. #define ARM_ETH_MAC_TX_FRAME_FRAGMENT (1UL << 0) ///< Indicate frame fragment
  92. #define ARM_ETH_MAC_TX_FRAME_EVENT (1UL << 1) ///< Generate event when frame is transmitted
  93. #define ARM_ETH_MAC_TX_FRAME_TIMESTAMP (1UL << 2) ///< Capture frame time stamp
  94. /****** Ethernet MAC Timer Control Codes *****/
  95. #define ARM_ETH_MAC_TIMER_GET_TIME (0x01UL) ///< Get current time
  96. #define ARM_ETH_MAC_TIMER_SET_TIME (0x02UL) ///< Set new time
  97. #define ARM_ETH_MAC_TIMER_INC_TIME (0x03UL) ///< Increment current time
  98. #define ARM_ETH_MAC_TIMER_DEC_TIME (0x04UL) ///< Decrement current time
  99. #define ARM_ETH_MAC_TIMER_SET_ALARM (0x05UL) ///< Set alarm time
  100. #define ARM_ETH_MAC_TIMER_ADJUST_CLOCK (0x06UL) ///< Adjust clock frequency; time->ns: correction factor * 2^31
  101. /**
  102. \brief Ethernet MAC Time
  103. */
  104. typedef struct _ARM_ETH_MAC_TIME {
  105. uint32_t ns; ///< Nano seconds
  106. uint32_t sec; ///< Seconds
  107. } ARM_ETH_MAC_TIME;
  108. /****** Ethernet MAC Event *****/
  109. #define ARM_ETH_MAC_EVENT_RX_FRAME (1UL << 0) ///< Frame Received
  110. #define ARM_ETH_MAC_EVENT_TX_FRAME (1UL << 1) ///< Frame Transmitted
  111. #define ARM_ETH_MAC_EVENT_WAKEUP (1UL << 2) ///< Wake-up (on Magic Packet)
  112. #define ARM_ETH_MAC_EVENT_TIMER_ALARM (1UL << 3) ///< Timer Alarm
  113. // Function documentation
  114. /**
  115. \fn ARM_DRIVER_VERSION ARM_ETH_MAC_GetVersion (void)
  116. \brief Get driver version.
  117. \return \ref ARM_DRIVER_VERSION
  118. */
  119. /**
  120. \fn ARM_ETH_MAC_CAPABILITIES ARM_ETH_MAC_GetCapabilities (void)
  121. \brief Get driver capabilities.
  122. \return \ref ARM_ETH_MAC_CAPABILITIES
  123. */
  124. /**
  125. \fn int32_t ARM_ETH_MAC_Initialize (ARM_ETH_MAC_SignalEvent_t cb_event)
  126. \brief Initialize Ethernet MAC Device.
  127. \param[in] cb_event Pointer to \ref ARM_ETH_MAC_SignalEvent
  128. \return \ref execution_status
  129. */
  130. /**
  131. \fn int32_t ARM_ETH_MAC_Uninitialize (void)
  132. \brief De-initialize Ethernet MAC Device.
  133. \return \ref execution_status
  134. */
  135. /**
  136. \fn int32_t ARM_ETH_MAC_PowerControl (ARM_POWER_STATE state)
  137. \brief Control Ethernet MAC Device Power.
  138. \param[in] state Power state
  139. \return \ref execution_status
  140. */
  141. /**
  142. \fn int32_t ARM_ETH_MAC_GetMacAddress (ARM_ETH_MAC_ADDR *ptr_addr)
  143. \brief Get Ethernet MAC Address.
  144. \param[in] ptr_addr Pointer to address
  145. \return \ref execution_status
  146. */
  147. /**
  148. \fn int32_t ARM_ETH_MAC_SetMacAddress (const ARM_ETH_MAC_ADDR *ptr_addr)
  149. \brief Set Ethernet MAC Address.
  150. \param[in] ptr_addr Pointer to address
  151. \return \ref execution_status
  152. */
  153. /**
  154. \fn int32_t ARM_ETH_MAC_SetAddressFilter (const ARM_ETH_MAC_ADDR *ptr_addr,
  155. uint32_t num_addr)
  156. \brief Configure Address Filter.
  157. \param[in] ptr_addr Pointer to addresses
  158. \param[in] num_addr Number of addresses to configure
  159. \return \ref execution_status
  160. */
  161. /**
  162. \fn int32_t ARM_ETH_MAC_SendFrame (const uint8_t *frame, uint32_t len, uint32_t flags)
  163. \brief Send Ethernet frame.
  164. \param[in] frame Pointer to frame buffer with data to send
  165. \param[in] len Frame buffer length in bytes
  166. \param[in] flags Frame transmit flags (see ARM_ETH_MAC_TX_FRAME_...)
  167. \return \ref execution_status
  168. */
  169. /**
  170. \fn int32_t ARM_ETH_MAC_ReadFrame (uint8_t *frame, uint32_t len)
  171. \brief Read data of received Ethernet frame.
  172. \param[in] frame Pointer to frame buffer for data to read into
  173. \param[in] len Frame buffer length in bytes
  174. \return number of data bytes read or execution status
  175. - value >= 0: number of data bytes read
  176. - value < 0: error occurred, value is execution status as defined with \ref execution_status
  177. */
  178. /**
  179. \fn uint32_t ARM_ETH_MAC_GetRxFrameSize (void)
  180. \brief Get size of received Ethernet frame.
  181. \return number of bytes in received frame
  182. */
  183. /**
  184. \fn int32_t ARM_ETH_MAC_GetRxFrameTime (ARM_ETH_MAC_TIME *time)
  185. \brief Get time of received Ethernet frame.
  186. \param[in] time Pointer to time structure for data to read into
  187. \return \ref execution_status
  188. */
  189. /**
  190. \fn int32_t ARM_ETH_MAC_GetTxFrameTime (ARM_ETH_MAC_TIME *time)
  191. \brief Get time of transmitted Ethernet frame.
  192. \param[in] time Pointer to time structure for data to read into
  193. \return \ref execution_status
  194. */
  195. /**
  196. \fn int32_t ARM_ETH_MAC_Control (uint32_t control, uint32_t arg)
  197. \brief Control Ethernet Interface.
  198. \param[in] control Operation
  199. \param[in] arg Argument of operation (optional)
  200. \return \ref execution_status
  201. */
  202. /**
  203. \fn int32_t ARM_ETH_MAC_ControlTimer (uint32_t control, ARM_ETH_MAC_TIME *time)
  204. \brief Control Precision Timer.
  205. \param[in] control Operation
  206. \param[in] time Pointer to time structure
  207. \return \ref execution_status
  208. */
  209. /**
  210. \fn int32_t ARM_ETH_MAC_PHY_Read (uint8_t phy_addr, uint8_t reg_addr, uint16_t *data)
  211. \brief Read Ethernet PHY Register through Management Interface.
  212. \param[in] phy_addr 5-bit device address
  213. \param[in] reg_addr 5-bit register address
  214. \param[out] data Pointer where the result is written to
  215. \return \ref execution_status
  216. */
  217. /**
  218. \fn int32_t ARM_ETH_MAC_PHY_Write (uint8_t phy_addr, uint8_t reg_addr, uint16_t data)
  219. \brief Write Ethernet PHY Register through Management Interface.
  220. \param[in] phy_addr 5-bit device address
  221. \param[in] reg_addr 5-bit register address
  222. \param[in] data 16-bit data to write
  223. \return \ref execution_status
  224. */
  225. /**
  226. \fn void ARM_ETH_MAC_SignalEvent (uint32_t event)
  227. \brief Callback function that signals a Ethernet Event.
  228. \param[in] event event notification mask
  229. \return none
  230. */
  231. typedef void (*ARM_ETH_MAC_SignalEvent_t) (uint32_t event); ///< Pointer to \ref ARM_ETH_MAC_SignalEvent : Signal Ethernet Event.
  232. /**
  233. \brief Ethernet MAC Capabilities
  234. */
  235. typedef struct _ARM_ETH_MAC_CAPABILITIES {
  236. uint32_t checksum_offload_rx_ip4 : 1; ///< 1 = IPv4 header checksum verified on receive
  237. uint32_t checksum_offload_rx_ip6 : 1; ///< 1 = IPv6 checksum verification supported on receive
  238. uint32_t checksum_offload_rx_udp : 1; ///< 1 = UDP payload checksum verified on receive
  239. uint32_t checksum_offload_rx_tcp : 1; ///< 1 = TCP payload checksum verified on receive
  240. uint32_t checksum_offload_rx_icmp : 1; ///< 1 = ICMP payload checksum verified on receive
  241. uint32_t checksum_offload_tx_ip4 : 1; ///< 1 = IPv4 header checksum generated on transmit
  242. uint32_t checksum_offload_tx_ip6 : 1; ///< 1 = IPv6 checksum generation supported on transmit
  243. uint32_t checksum_offload_tx_udp : 1; ///< 1 = UDP payload checksum generated on transmit
  244. uint32_t checksum_offload_tx_tcp : 1; ///< 1 = TCP payload checksum generated on transmit
  245. uint32_t checksum_offload_tx_icmp : 1; ///< 1 = ICMP payload checksum generated on transmit
  246. uint32_t media_interface : 2; ///< Ethernet Media Interface type
  247. uint32_t mac_address : 1; ///< 1 = driver provides initial valid MAC address
  248. uint32_t event_rx_frame : 1; ///< 1 = callback event \ref ARM_ETH_MAC_EVENT_RX_FRAME generated
  249. uint32_t event_tx_frame : 1; ///< 1 = callback event \ref ARM_ETH_MAC_EVENT_TX_FRAME generated
  250. uint32_t event_wakeup : 1; ///< 1 = wakeup event \ref ARM_ETH_MAC_EVENT_WAKEUP generated
  251. uint32_t precision_timer : 1; ///< 1 = Precision Timer supported
  252. uint32_t reserved : 15; ///< Reserved (must be zero)
  253. } ARM_ETH_MAC_CAPABILITIES;
  254. /**
  255. \brief Access structure of the Ethernet MAC Driver
  256. */
  257. typedef struct _ARM_DRIVER_ETH_MAC {
  258. ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_ETH_MAC_GetVersion : Get driver version.
  259. ARM_ETH_MAC_CAPABILITIES (*GetCapabilities) (void); ///< Pointer to \ref ARM_ETH_MAC_GetCapabilities : Get driver capabilities.
  260. int32_t (*Initialize) (ARM_ETH_MAC_SignalEvent_t cb_event); ///< Pointer to \ref ARM_ETH_MAC_Initialize : Initialize Ethernet MAC Device.
  261. int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_ETH_MAC_Uninitialize : De-initialize Ethernet MAC Device.
  262. int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_ETH_MAC_PowerControl : Control Ethernet MAC Device Power.
  263. int32_t (*GetMacAddress) ( ARM_ETH_MAC_ADDR *ptr_addr); ///< Pointer to \ref ARM_ETH_MAC_GetMacAddress : Get Ethernet MAC Address.
  264. int32_t (*SetMacAddress) (const ARM_ETH_MAC_ADDR *ptr_addr); ///< Pointer to \ref ARM_ETH_MAC_SetMacAddress : Set Ethernet MAC Address.
  265. int32_t (*SetAddressFilter)(const ARM_ETH_MAC_ADDR *ptr_addr, uint32_t num_addr); ///< Pointer to \ref ARM_ETH_MAC_SetAddressFilter : Configure Address Filter.
  266. int32_t (*SendFrame) (const uint8_t *frame, uint32_t len, uint32_t flags); ///< Pointer to \ref ARM_ETH_MAC_SendFrame : Send Ethernet frame.
  267. int32_t (*ReadFrame) ( uint8_t *frame, uint32_t len); ///< Pointer to \ref ARM_ETH_MAC_ReadFrame : Read data of received Ethernet frame.
  268. uint32_t (*GetRxFrameSize) (void); ///< Pointer to \ref ARM_ETH_MAC_GetRxFrameSize : Get size of received Ethernet frame.
  269. int32_t (*GetRxFrameTime) (ARM_ETH_MAC_TIME *time); ///< Pointer to \ref ARM_ETH_MAC_GetRxFrameTime : Get time of received Ethernet frame.
  270. int32_t (*GetTxFrameTime) (ARM_ETH_MAC_TIME *time); ///< Pointer to \ref ARM_ETH_MAC_GetTxFrameTime : Get time of transmitted Ethernet frame.
  271. int32_t (*ControlTimer) (uint32_t control, ARM_ETH_MAC_TIME *time); ///< Pointer to \ref ARM_ETH_MAC_ControlTimer : Control Precision Timer.
  272. int32_t (*Control) (uint32_t control, uint32_t arg); ///< Pointer to \ref ARM_ETH_MAC_Control : Control Ethernet Interface.
  273. int32_t (*PHY_Read) (uint8_t phy_addr, uint8_t reg_addr, uint16_t *data); ///< Pointer to \ref ARM_ETH_MAC_PHY_Read : Read Ethernet PHY Register through Management Interface.
  274. int32_t (*PHY_Write) (uint8_t phy_addr, uint8_t reg_addr, uint16_t data); ///< Pointer to \ref ARM_ETH_MAC_PHY_Write : Write Ethernet PHY Register through Management Interface.
  275. } const ARM_DRIVER_ETH_MAC;
  276. #ifdef __cplusplus
  277. }
  278. #endif
  279. #endif /* DRIVER_ETH_MAC_H_ */