Skip to content

Commit

Permalink
Update ETH driver validation, add VLAN filtering test (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
furbanc authored Jan 10, 2025
1 parent a4e044d commit 9fff162
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ARM.CMSIS-Driver_Validation.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@
</files>
</component>

<component Cclass="CMSIS Driver Validation" Cgroup="Ethernet" Cversion="2.0.0" condition="CMSIS Driver Validation ETH">
<component Cclass="CMSIS Driver Validation" Cgroup="Ethernet" Cversion="2.1.0" condition="CMSIS Driver Validation ETH">
<description>Ethernet driver validation</description>
<RTE_Components_h>
#define RTE_CMSIS_DV_ETH /* Driver Validation Ethernet enabled */
</RTE_Components_h>
<files>
<file category="doc" name="Documentation/html/group__dv__eth.html" />
<file category="header" name="Config/DV_ETH_Config.h" attr="config" version = "2.0.0"/>
<file category="header" name="Config/DV_ETH_Config.h" attr="config" version = "2.1.0"/>
<file category="source" name="Source/DV_ETH.c"/>
</files>
</component>
Expand Down
6 changes: 4 additions & 2 deletions Config/DV_ETH_Config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2023 Arm Limited. All rights reserved.
* Copyright (c) 2015-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -17,7 +17,7 @@
*
* -----------------------------------------------------------------------------
*
* $Revision: V2.0.0
* $Revision: V2.1.0
*
* Project: CMSIS-Driver Validation
* Title: Ethernet (ETH) driver validation configuration file
Expand Down Expand Up @@ -70,6 +70,8 @@
#define ETH_MAC_CONTROL_FILTERING_EN 1
// <q> ETH_MAC_SetAddressFilter
#define ETH_MAC_SET_ADDRESS_FILTER_EN 1
// <q> ETH_MAC_VLAN_Filter
#define ETH_MAC_VLAN_FILTER_EN 1
// <q> ETH_MAC_SignalEvent
#define ETH_MAC_SIGNAL_EVENT_EN 1
// <q> ETH_MAC_PTP_ControlTimer
Expand Down
3 changes: 2 additions & 1 deletion Include/cmsis_dv.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2023 Arm Limited. All rights reserved.
* Copyright (c) 2015-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -182,6 +182,7 @@ extern void ETH_MAC_Config_Mode (void);
extern void ETH_MAC_Config_CommonParams (void);
extern void ETH_MAC_Control_Filtering (void);
extern void ETH_MAC_SetAddressFilter (void);
extern void ETH_MAC_VLAN_Filter (void);
extern void ETH_MAC_SignalEvent (void);
extern void ETH_MAC_PTP_ControlTimer (void);
extern void ETH_MAC_CheckInvalidInit (void);
Expand Down
130 changes: 125 additions & 5 deletions Source/DV_ETH.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2023 Arm Limited. All rights reserved.
* Copyright (c) 2015-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -101,14 +101,35 @@ static int32_t ETH_RunTransfer (const uint8_t *out, uint8_t *in, uint32_t len, u
if ((Event & ARM_ETH_MAC_EVENT_RX_FRAME) || !capab.event_rx_frame) {
size = eth_mac->GetRxFrameSize();
if (size > 0) {
if ((size < 14) || (size > 14+ETH_MTU)) {
eth_mac->ReadFrame(NULL, 0U);
return ARM_DRIVER_ERROR;
}
eth_mac->ReadFrame(in, size);
return ARM_DRIVER_OK;
}
}
}
while ((GET_SYSTICK() - tick) < SYSTICK_MICROSEC(ETH_TRANSFER_TIMEOUT*1000));

return ARM_DRIVER_ERROR;
return ARM_DRIVER_ERROR_TIMEOUT;
}

#define ETH_CheckAddressFilter() ETH_CheckFilter(0)
#define ETH_CheckVlanFilter() ETH_CheckFilter(1)

// Check multicast address and VLAN filtering support
static int32_t ETH_CheckFilter (int32_t vlan) {
int32_t retv;

eth_mac->Initialize(cb_event);
eth_mac->PowerControl(ARM_POWER_FULL);
retv = (!vlan) ? eth_mac->SetAddressFilter(NULL, 0) :
eth_mac->Control (ARM_ETH_MAC_VLAN_FILTER, 0);
eth_mac->PowerControl(ARM_POWER_OFF);
eth_mac->Uninitialize();

return retv;
}

// Initialize MAC driver wrapper for RMII interface
Expand Down Expand Up @@ -634,6 +655,12 @@ The internal Ethernet MAC loopback is used for the test.
void ETH_MAC_SetAddressFilter (void) {
uint32_t i,tick;

if (ETH_CheckAddressFilter() == ARM_DRIVER_ERROR_UNSUPPORTED) {
/* Multicast address filtering not supported */
TEST_MESSAGE("[WARNING] Multicast address filtering is not supported");
return;
}

/* Allocate buffers */
buffer_out = (uint8_t *)malloc(64);
TEST_ASSERT(buffer_out != NULL);
Expand Down Expand Up @@ -769,6 +796,98 @@ void ETH_MAC_SetAddressFilter (void) {
free(buffer_in);
}

/*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
/**
\brief Function: ETH_MAC_VLAN_Filter
\details
The function \b ETH_MAC_VLAN_Filter verifies the Ethernet MAC Virtual LAN filtering with the following sequence:
- Buffer allocation
- Initialize
- Power on
- Transfer VLAN packets
- Receive VLAN packets
- Power off
- Uninitialize
\note
The internal Ethernet MAC loopback is used for the test.
*/
void ETH_MAC_VLAN_Filter (void) {
const uint8_t IP_frame[] = {
0x01,0x00,0x5e,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,
0x08,0x00,0x45,0x00,0x00,0x1c,0x65,0x51,0x00,0x00,0x01,0x02,0xb2,0xe3,0xc0,0xa8,
0x01,0x02,0xe0,0x00,0x00,0x01,0x11,0x64,0xee,0x9b,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const uint16_t test_id[] = { 1,2,100,500,1000,1005,1006,1500,2000,4000,4093 };
const uint16_t vlan_id[] = { 1,20,100,1000,2000,4093 };
uint32_t i,j;

if (ETH_CheckVlanFilter() == ARM_DRIVER_ERROR_UNSUPPORTED) {
/* VLAN tagged frame filtering not supported */
TEST_MESSAGE("[WARNING] VLAN filtering is not supported");
return;
}

/* Allocate buffers */
buffer_out = (uint8_t *)malloc(64);
TEST_ASSERT(buffer_out != NULL);
if (buffer_out == NULL) return;
buffer_in = (uint8_t *)malloc(64);
TEST_ASSERT(buffer_in != NULL);
if (buffer_in == NULL) { free(buffer_out); return; }

/* Initialize, power on and configure MAC and PHY */
TEST_ASSERT(eth_mac->Initialize(cb_event) == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->PowerControl(ARM_POWER_FULL) == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->SetMacAddress(&mac_addr) == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->Control(ARM_ETH_MAC_CONFIGURE, ARM_ETH_MAC_SPEED_100M |
ARM_ETH_MAC_DUPLEX_FULL | ARM_ETH_MAC_ADDRESS_BROADCAST) == ARM_DRIVER_OK);
TEST_ASSERT(eth_phy->Initialize(eth_mac->PHY_Read, eth_mac->PHY_Write) == ARM_DRIVER_OK);
TEST_ASSERT(eth_phy->PowerControl(ARM_POWER_FULL) == ARM_DRIVER_OK);
osDelay (100);
TEST_ASSERT(eth_phy->SetInterface(capab.media_interface) == ARM_DRIVER_OK);
TEST_ASSERT(eth_phy->SetMode(ARM_ETH_PHY_AUTO_NEGOTIATE) == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->Control(ARM_ETH_MAC_CONTROL_RX, 1) == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->Control(ARM_ETH_MAC_CONTROL_TX, 1) == ARM_DRIVER_OK);

/* Set Ethernet frame */
memcpy (buffer_out, IP_frame, sizeof (IP_frame));
memcpy (&buffer_out[6], &mac_addr, 6);

TEST_ASSERT(eth_mac->Control(ARM_ETH_MAC_CONFIGURE, ARM_ETH_MAC_SPEED_100M | ARM_ETH_MAC_DUPLEX_FULL |
ARM_ETH_MAC_ADDRESS_MULTICAST | ARM_ETH_MAC_LOOPBACK) == ARM_DRIVER_OK);

for (i = 0; i < ARRAY_SIZE(vlan_id); i++) {
TEST_ASSERT(eth_mac->Control (ARM_ETH_MAC_VLAN_FILTER,
ARM_ETH_MAC_VLAN_FILTER_ID_ONLY | vlan_id[i]) == ARM_DRIVER_OK);
for (j = 0; j < ARRAY_SIZE(test_id); j++) {
int32_t retv;
/* Set VLAN ID tag */
buffer_out[14] = (test_id[j] >> 8) & 0xFF;
buffer_out[15] = test_id[j] & 0xFF;
retv = ETH_RunTransfer(buffer_out, buffer_in, 64, 0);
if (((test_id[j] == vlan_id[i]) && (retv != ARM_DRIVER_OK)) ||
((test_id[j] != vlan_id[i]) && (retv == ARM_DRIVER_OK))) {
snprintf(str,sizeof(str),"[FAILED] VLAN tag %d",vlan_id[i]);
TEST_FAIL_MESSAGE(str);
break;
}
else TEST_PASS();
}
}

/* Power off and uninitialize */
TEST_ASSERT(eth_phy->PowerControl(ARM_POWER_OFF) == ARM_DRIVER_OK);
TEST_ASSERT(eth_phy->Uninitialize() == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->PowerControl(ARM_POWER_OFF) == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->Uninitialize() == ARM_DRIVER_OK);

/* Free buffers */
free(buffer_out);
free(buffer_in);
}

/*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
/**
\brief Function: ETH_MAC_SignalEvent
Expand Down Expand Up @@ -1222,7 +1341,7 @@ void ETH_Loopback_External (void) {
while (eth_phy->GetLinkState() != ARM_ETH_LINK_UP) {
if ((GET_SYSTICK() - tick) >= SYSTICK_MICROSEC(ETH_LINK_TIMEOUT*1000)) {
TEST_FAIL_MESSAGE("[FAILED] Link down, connect Ethernet cable");
goto end;
goto exit;
}
}

Expand All @@ -1232,7 +1351,7 @@ void ETH_Loopback_External (void) {
(uint32_t)info.duplex << ARM_ETH_MAC_DUPLEX_Pos |
ARM_ETH_MAC_ADDRESS_BROADCAST) == ARM_DRIVER_OK);

/* Clear input buffer*/
/* Clear input buffer */
memset(buffer_in, 0, 14+ETH_MTU);
if (ETH_RunTransfer(buffer_out, buffer_in, 14+ETH_MTU, 0) != ARM_DRIVER_OK) {
TEST_FAIL_MESSAGE("[FAILED] Transfer external cable loopback");
Expand All @@ -1241,11 +1360,12 @@ void ETH_Loopback_External (void) {
} else TEST_PASS();

/* Power off and uninitialize */
exit:
TEST_ASSERT(eth_phy->PowerControl(ARM_POWER_OFF) == ARM_DRIVER_OK);
TEST_ASSERT(eth_phy->Uninitialize() == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->PowerControl(ARM_POWER_OFF) == ARM_DRIVER_OK);
TEST_ASSERT(eth_mac->Uninitialize() == ARM_DRIVER_OK);
end:

/* Free buffers */
free(buffer_out);
free(buffer_in);
Expand Down
5 changes: 4 additions & 1 deletion Source/cmsis_dv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2023 Arm Limited. All rights reserved.
* Copyright (c) 2015-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -271,6 +271,9 @@ static TEST_CASE TC_List_ETH[] = {
TCD ( ETH_MAC_Config_CommonParams, ETH_MAC_CONFIG_COMMON_PARAMS_EN ),
TCD ( ETH_MAC_Control_Filtering, ETH_MAC_CONTROL_FILTERING_EN ),
TCD ( ETH_MAC_SetAddressFilter, ETH_MAC_SET_ADDRESS_FILTER_EN ),
#ifdef ETH_MAC_VLAN_FILTER_EN
TCD ( ETH_MAC_VLAN_Filter, ETH_MAC_VLAN_FILTER_EN ),
#endif
TCD ( ETH_MAC_SignalEvent, ETH_MAC_SIGNAL_EVENT_EN ),
TCD ( ETH_MAC_PTP_ControlTimer, ETH_MAC_PTP_CONTROL_TIMER_EN ),
TCD ( ETH_MAC_CheckInvalidInit, ETH_MAC_CHECK_INVALID_INIT_EN ),
Expand Down

0 comments on commit 9fff162

Please sign in to comment.