2 * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
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
10 * www.apache.org/licenses/LICENSE-2.0
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.
19 #include "Driver_ETH_MAC.h"
21 #define ARM_ETH_MAC_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1, 0) /* driver version */
24 static const ARM_DRIVER_VERSION DriverVersion = {
25 ARM_ETH_MAC_API_VERSION,
26 ARM_ETH_MAC_DRV_VERSION
29 /* Driver Capabilities */
30 static const ARM_ETH_MAC_CAPABILITIES DriverCapabilities = {
31 0, /* 1 = IPv4 header checksum verified on receive */
32 0, /* 1 = IPv6 checksum verification supported on receive */
33 0, /* 1 = UDP payload checksum verified on receive */
34 0, /* 1 = TCP payload checksum verified on receive */
35 0, /* 1 = ICMP payload checksum verified on receive */
36 0, /* 1 = IPv4 header checksum generated on transmit */
37 0, /* 1 = IPv6 checksum generation supported on transmit */
38 0, /* 1 = UDP payload checksum generated on transmit */
39 0, /* 1 = TCP payload checksum generated on transmit */
40 0, /* 1 = ICMP payload checksum generated on transmit */
41 0, /* Ethernet Media Interface type */
42 0, /* 1 = driver provides initial valid MAC address */
43 0, /* 1 = callback event \ref ARM_ETH_MAC_EVENT_RX_FRAME generated */
44 0, /* 1 = callback event \ref ARM_ETH_MAC_EVENT_TX_FRAME generated */
45 0, /* 1 = wakeup event \ref ARM_ETH_MAC_EVENT_WAKEUP generated */
46 0, /* 1 = Precision Timer supported */
47 0 /* Reserved (must be zero) */
54 static ARM_DRIVER_VERSION ARM_ETH_MAC_GetVersion(void)
59 static ARM_ETH_MAC_CAPABILITIES ARM_ETH_MAC_GetCapabilities(void)
61 return DriverCapabilities;
64 static int32_t ARM_ETH_MAC_Initialize(ARM_ETH_MAC_SignalEvent_t cb_event)
68 static int32_t ARM_ETH_MAC_Uninitialize(void)
72 static int32_t ARM_ETH_MAC_PowerControl(ARM_POWER_STATE state)
88 static int32_t ARM_ETH_MAC_GetMacAddress(ARM_ETH_MAC_ADDR *ptr_addr)
92 static int32_t ARM_ETH_MAC_SetMacAddress(const ARM_ETH_MAC_ADDR *ptr_addr)
96 static int32_t ARM_ETH_MAC_SetAddressFilter(const ARM_ETH_MAC_ADDR *ptr_addr, uint32_t num_addr)
100 static int32_t ARM_ETH_MAC_SendFrame(const uint8_t *frame, uint32_t len, uint32_t flags)
104 static int32_t ARM_ETH_MAC_ReadFrame(uint8_t *frame, uint32_t len)
108 static uint32_t ARM_ETH_MAC_GetRxFrameSize(void)
112 static int32_t ARM_ETH_MAC_GetRxFrameTime(ARM_ETH_MAC_TIME *time)
116 static int32_t ARM_ETH_MAC_GetTxFrameTime(ARM_ETH_MAC_TIME *time)
120 static int32_t ARM_ETH_MAC_Control(uint32_t control, uint32_t arg)
124 case ARM_ETH_MAC_CONFIGURE:
126 switch (arg & ARM_ETH_MAC_SPEED_Msk)
128 case ARM_ETH_MAC_SPEED_10M:
130 case ARM_ETH_SPEED_100M:
133 return ARM_DRIVER_ERROR_UNSUPPORTED;
136 switch (arg & ARM_ETH_MAC_DUPLEX_Msk)
138 case ARM_ETH_MAC_DUPLEX_FULL:
142 if (arg & ARM_ETH_MAC_LOOPBACK)
146 if ((arg & ARM_ETH_MAC_CHECKSUM_OFFLOAD_RX) ||
147 (arg & ARM_ETH_MAC_CHECKSUM_OFFLOAD_TX))
149 return ARM_DRIVER_ERROR_UNSUPPORTED;
152 if (!(arg & ARM_ETH_MAC_ADDRESS_BROADCAST))
156 if (arg & ARM_ETH_MAC_ADDRESS_MULTICAST)
160 if (arg & ARM_ETH_MAC_ADDRESS_ALL)
166 case ARM_ETH_MAC_CONTROL_TX:
169 case ARM_ETH_MAC_CONTROL_RX:
172 case ARM_ETH_MAC_FLUSH:
173 if (arg & ARM_ETH_MAC_FLUSH_RX)
176 if (arg & ARM_ETH_MAC_FLUSH_TX)
181 case ARM_ETH_MAC_SLEEP:
184 case ARM_ETH_MAC_VLAN_FILTER:
188 return ARM_DRIVER_ERROR_UNSUPPORTED;
192 static int32_t ARM_ETH_MAC_ControlTimer(uint32_t control, ARM_ETH_MAC_TIME *time)
196 static int32_t ARM_ETH_MAC_PHY_Read(uint8_t phy_addr, uint8_t reg_addr, uint16_t *data)
200 static int32_t ARM_ETH_MAC_PHY_Write(uint8_t phy_addr, uint8_t reg_addr, uint16_t data)
204 static void ARM_ETH_MAC_SignalEvent(uint32_t event)
208 // End ETH MAC Interface
211 ARM_DRIVER_ETH_MAC Driver_ETH_MAC0;
212 ARM_DRIVER_ETH_MAC Driver_ETH_MAC0 =
214 ARM_ETH_MAC_GetVersion,
215 ARM_ETH_MAC_GetCapabilities,
216 ARM_ETH_MAC_Initialize,
217 ARM_ETH_MAC_Uninitialize,
218 ARM_ETH_MAC_PowerControl,
219 ARM_ETH_MAC_GetMacAddress,
220 ARM_ETH_MAC_SetMacAddress,
221 ARM_ETH_MAC_SetAddressFilter,
222 ARM_ETH_MAC_SendFrame,
223 ARM_ETH_MAC_ReadFrame,
224 ARM_ETH_MAC_GetRxFrameSize,
225 ARM_ETH_MAC_GetRxFrameTime,
226 ARM_ETH_MAC_GetTxFrameTime,
227 ARM_ETH_MAC_ControlTimer,
229 ARM_ETH_MAC_PHY_Read,
230 ARM_ETH_MAC_PHY_Write