Driver_ETH_MAC.h 16 KB

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