Hi @PavelL
int WriteL2LookupEntry(int cs)
{
const uint32_t DESTPORTS = 0x004;
const uint32_t INDEX = 2;
const uint64_t MACADDR = 0x112233445566;
const uint64_t MACADDR_MASK = 0xffffffffffff;
const uint32_t VLANID = 0;
const uint32_t VLANID_MASK = 0x0;
const uint32_t IOTAG = 0;
const uint32_t IOTAG_MASK = 0;
const uint32_t SRCPORT = 0x6;
const uint32_t SRCPORT_MASK = 0xF;
const uint32_t ENFPORT = 0;
const uint32_t RETAG = 0;
const uint32_t MIRROR = 0;
const uint32_t TAKETS = 0;
const uint32_t MIRR_VLAN = 0xFFF;
const uint32_t TRAPTOHOST = 0;
const uint32_t CBSIDIN = 0x3F;
const uint32_t CBENONDA = 0;
const uint32_t VLIDX = 0xFFF;
const uint32_t SA_POLICE = 0;
const uint32_t DA_POLICE = 0;
uint32_t L2_OFFSET = 0x23;
uint32_t L2CTRL_OFFSET = 0x29;
const uint32_t SWREG_BASE = 0x00000000;
const uint32_t VALID = 1U;
const uint32_t RDWRSET = 1U;
const uint32_t VALIDENT = 1U;
const uint32_t HOSTCMD = 3U;
const uint32_t MGMTROUTE = 0U;
const uint32_t LOCKED = 1U;
const uint32_t ERROR = 0U;
uint32_t L2_ADDRESS = SWREG_BASE + L2_OFFSET;
uint32_t L2_ADDRESS_CTL = SWREG_BASE + L2CTRL_OFFSET;
uint32_t l2Entry[ADDRESS_RANGE] = {0};
l2Entry[0] = (((INDEX & 0x03ff) << (1 % 32)) + ((ENFPORT & 1) << (11 % 32))
+ ((DESTPORTS & 0x7FF) << (12 % 32)) + ((SRCPORT & 0xF) << (23 % 32))
+ ((MACADDR & 0x1F) << (27 % 32)));
l2Entry[1] = (((MACADDR >> 5) & 0xFFFFFFFF));
l2Entry[2] = ((((MACADDR >> 37) & 0x7FF) << (64 % 32)) + ((VLANID & 0xFFF) << (75 % 32))
+ ((IOTAG & 1) << (87 % 32)) + ((MACADDR_MASK & 0xFF) << (88 % 32)));
l2Entry[3] = (((MACADDR_MASK >> & 0xFFFFFFFF));
l2Entry[4] = (((MACADDR_MASK >> 40) & 0xFF << (128 % 32)) + ((VLANID_MASK & 0xfff) << (136 % 32))
+ ((IOTAG_MASK & 1) << (148 % 32)) + ((SRCPORT_MASK & 0xF) << (149 % 32))
+ ((RETAG & 0x1) << (153 % 32)) + ((MIRROR & 0x1) << (154 % 32))
+ ((TAKETS & 0x1) << (155 % 32)) + ((MIRR_VLAN & 0xF) << (156 % 32)));
l2Entry[5] = (((MIRR_VLAN >> 4) & 0xFF << (160 % 32)) + ((TRAPTOHOST & 0x1) << (168 % 32))
+ ((CBSIDIN & 0x3F) << (169 % 32)) + ((CBENONDA & 0x1) << (175 % 32))
+ ((VLIDX & 0xFFF) << (177 % 32)) + ((SA_POLICE & 0x1) << (189 % 32))
+ ((DA_POLICE & 0x1) << (190 % 32)));
uint32_t status = 0;
do {
Std_ReturnType ret = spi_read_reg(L2_ADDRESS_CTL, &status);
if (ret != E_OK) {
return -1;
}
} while ((status >> VALID_BIT_SHIFT) & 1U);
for (int i = 0; i < ADDRESS_RANGE; i++) {
Std_ReturnType ret = spi_write_reg(L2_ADDRESS + i, l2Entry[i]);
if (ret != E_OK) {
return -2;
}
uint32_t readBack = 0;
ret = spi_read_reg(L2_ADDRESS + i, &readBack);
if (ret != E_OK || readBack != l2Entry[i]) {
return -3;
}
}
uint32_t controlL2Entry = 0;
controlL2Entry = ((VALID << 31) + (RDWRSET << 30) + (ERROR << 29) + (LOCKED << 28) + (VALIDENT << 27) +
(MGMTROUTE << 26) + (HOSTCMD << 23));
Std_ReturnType ret = spi_write_reg(L2_ADDRESS_CTL, controlL2Entry);
if (ret != E_OK) {
return -4;
}
do {
ret = spi_read_reg(L2_ADDRESS_CTL, &status);
if (ret != E_OK) {
return -5;
}
} while ((status >> VALID_BIT_SHIFT) & 1U);
return 0;
}
I have changed the implementation similar to Python script. if you found any errors can you send me the changes please
Python script
# Write Control
platform.spi_write(L2_ADDRESS_CTL, controlL2Entry, cs)
table = prettytable.PrettyTable(
("INDEX", "DESTPORTS", "MACADDR", "VLANID", "ENFPORT", "IOTAG"))
entry = (
str(INDEX), '{0:11b}'.format(DESTPORTS), mac_to_str(MACADDR), str(VLANID),
str(ENFPORT), str(IOTAG))
table.add_row(entry)
print(table.get_string())
"After writing, try sending a frame that matches the MAC/VLAN/port criteria of the entry and observe whether it is forwarded according to the DESTPORTS field"
I am trying to send in this way as you mentioned but this reflection is not seen
I am unable to see my entry is getting reflected ?
is there any other things need to be setted up ??
In Python script after writing the register value for controll2entry into L2_ADDRESS_CTL
there were few lines of code which does adding a entry into "prettytable"
Do we need to this also same and whether we have provision to do this ??