EmbeddedPkg/Lan9118Dxe: Rework filter init, enabling and disabling

Correct the setting of the hardware filters according to what it asked
to the driver through the ReceiveFilters() interface function.

Keep track of the hardware settings in the "ReceiveFilterSetting" field of
 the EFI_SIMPLE_NETWORK_MODE structure.

From now, after initialization, all filters are disabled and thus no packet
received.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16243 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Ronald Cron 2014-10-27 10:42:13 +00:00 committed by oliviermartin
parent e52aee5d31
commit 11bbc25789
2 changed files with 77 additions and 56 deletions

View File

@ -99,16 +99,25 @@ Lan9118DxeEntry (
SnpMode->NvRamSize = 0; // No NVRAM with this device SnpMode->NvRamSize = 0; // No NVRAM with this device
SnpMode->NvRamAccessSize = 0; // No NVRAM with this device SnpMode->NvRamAccessSize = 0; // No NVRAM with this device
// Update network mode information //
SnpMode->ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST | // Claim that all receive filter settings are supported, though the MULTICAST mode
EFI_SIMPLE_NETWORK_RECEIVE_UNICAST | // is not completely supported. The LAN9118 Ethernet controller is only able to
EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST | // do a "hash filtering" and not a perfect filtering on multicast addresses. The
EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;/* | // controller does not filter the multicast addresses directly but a hash value
EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;*/ // of them. The hash value of a multicast address is derived from its CRC and
// Current allowed settings // ranges from 0 to 63 included.
SnpMode->ReceiveFilterSetting = EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST | // We claim that the perfect MULTICAST filtering mode is supported because
EFI_SIMPLE_NETWORK_RECEIVE_UNICAST | // we do not want the user to switch directly to the PROMISCOUS_MULTICAST mode
EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST; // and thus not being able to take advantage of the hash filtering.
//
SnpMode->ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |
EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST |
EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST |
EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS |
EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;
// We do not intend to receive anything for the time being.
SnpMode->ReceiveFilterSetting = 0;
// LAN9118 has 64bit hash table, can filter 64 MCast MAC Addresses // LAN9118 has 64bit hash table, can filter 64 MCast MAC Addresses
SnpMode->MaxMCastFilterCount = MAX_MCAST_FILTER_CNT; SnpMode->MaxMCastFilterCount = MAX_MCAST_FILTER_CNT;
@ -344,12 +353,7 @@ SnpInitialize (
return Status; return Status;
} }
// Enable the receiver and transmitter // Enable the transmitter
Status = StartRx (0, Snp);
if (EFI_ERROR(Status)) {
return Status;
}
Status = StartTx (START_TX_MAC | START_TX_CFG, Snp); Status = StartTx (START_TX_MAC | START_TX_CFG, Snp);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
return Status; return Status;
@ -553,7 +557,9 @@ SnpReceiveFilters (
UINT32 Crc; UINT32 Crc;
UINT8 HashValue; UINT8 HashValue;
UINT32 MacCSRValue; UINT32 MacCSRValue;
UINT32 ReceiveFilterSetting;
EFI_MAC_ADDRESS *Mac; EFI_MAC_ADDRESS *Mac;
EFI_MAC_ADDRESS ZeroMac;
// Check Snp Instance // Check Snp Instance
if (Snp == NULL) { if (Snp == NULL) {
@ -631,6 +637,12 @@ SnpReceiveFilters (
MultHashTableHigh = IndirectMACRead32 (INDIRECT_MAC_INDEX_HASHH); MultHashTableHigh = IndirectMACRead32 (INDIRECT_MAC_INDEX_HASHH);
} }
//
// Before to change anything, stop and reset the reception of
// packets.
//
StopRx (STOP_RX_CLEAR, Snp);
// //
// Write the mask of the selected hash values for the multicast filtering. // Write the mask of the selected hash values for the multicast filtering.
// The two masks are set to zero if the multicast filtering is not enabled. // The two masks are set to zero if the multicast filtering is not enabled.
@ -638,64 +650,62 @@ SnpReceiveFilters (
IndirectMACWrite32 (INDIRECT_MAC_INDEX_HASHL, MultHashTableLow); IndirectMACWrite32 (INDIRECT_MAC_INDEX_HASHL, MultHashTableLow);
IndirectMACWrite32 (INDIRECT_MAC_INDEX_HASHH, MultHashTableHigh); IndirectMACWrite32 (INDIRECT_MAC_INDEX_HASHH, MultHashTableHigh);
ReceiveFilterSetting = (Mode->ReceiveFilterSetting | Enable) & (~Disable);
//
// Read MAC controller // Read MAC controller
MacCSRValue = IndirectMACRead32 (INDIRECT_MAC_INDEX_CR); //
MacCSRValue = IndirectMACRead32 (INDIRECT_MAC_INDEX_CR);
MacCSRValue &= ~(MACCR_HPFILT | MACCR_BCAST | MACCR_PRMS | MACCR_MCPAS);
// Set the options for the MAC_CSR if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_UNICAST) {
if (Enable & EFI_SIMPLE_NETWORK_RECEIVE_UNICAST) { Lan9118SetMacAddress (&Mode->CurrentAddress, Snp);
StartRx (0, Snp);
DEBUG ((DEBUG_NET, "Allowing Unicast Frame Reception\n")); DEBUG ((DEBUG_NET, "Allowing Unicast Frame Reception\n"));
} else {
//
// The Unicast packets do not have to be listen to, set the MAC
// address of the LAN9118 to be the "not configured" all zeroes
// ethernet MAC address.
//
ZeroMem (&ZeroMac, NET_ETHER_ADDR_LEN);
Lan9118SetMacAddress (&ZeroMac, Snp);
} }
if (Disable & EFI_SIMPLE_NETWORK_RECEIVE_UNICAST) { if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) {
StopRx (0, Snp);
DEBUG ((DEBUG_NET, "Disabling Unicast Frame Reception\n"));
}
if (Enable & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) {
MacCSRValue |= MACCR_HPFILT; MacCSRValue |= MACCR_HPFILT;
DEBUG ((DEBUG_NET, "Allowing Multicast Frame Reception\n")); DEBUG ((DEBUG_NET, "Allowing Multicast Frame Reception\n"));
} }
if (Disable & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) { if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) {
MacCSRValue &= ~MACCR_HPFILT; MacCSRValue |= MACCR_MCPAS;
DEBUG ((DEBUG_NET, "Disabling Multicast Frame Reception\n")); DEBUG ((DEBUG_NET, "Enabling Promiscuous Multicast Mode\n"));
} }
if (Enable & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) { if ((ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) == 0) {
MacCSRValue &= ~(MACCR_BCAST); MacCSRValue |= MACCR_BCAST;
} else {
DEBUG ((DEBUG_NET, "Allowing Broadcast Frame Reception\n")); DEBUG ((DEBUG_NET, "Allowing Broadcast Frame Reception\n"));
} }
if (Disable & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) { if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) {
MacCSRValue |= MACCR_BCAST;
DEBUG ((DEBUG_NET, "Disabling Broadcast Frame Reception\n"));
}
if (Enable & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) {
MacCSRValue |= MACCR_PRMS; MacCSRValue |= MACCR_PRMS;
DEBUG ((DEBUG_NET, "Enabling Promiscuous Mode\n")); DEBUG ((DEBUG_NET, "Enabling Promiscuous Mode\n"));
} }
if (Disable & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) { //
MacCSRValue &= ~MACCR_PRMS;
DEBUG ((DEBUG_NET, "Disabling Promiscuous Mode\n"));
}
if (Enable & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) {
MacCSRValue |= (MACCR_HPFILT | MACCR_PRMS);
DEBUG ((DEBUG_NET, "Enabling Promiscuous Multicast Mode\n"));
}
if (Disable & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) {
MacCSRValue &= ~(MACCR_HPFILT | MACCR_PRMS);
DEBUG ((DEBUG_NET, "Disabling Promiscuous Multicast Mode\n"));
}
// Write the options to the MAC_CSR // Write the options to the MAC_CSR
//
IndirectMACWrite32 (INDIRECT_MAC_INDEX_CR, MacCSRValue); IndirectMACWrite32 (INDIRECT_MAC_INDEX_CR, MacCSRValue);
gBS->Stall (LAN9118_STALL); gBS->Stall (LAN9118_STALL);
//
// If we have to retrieve something, start packet reception.
//
Mode->ReceiveFilterSetting = ReceiveFilterSetting;
if (ReceiveFilterSetting != 0) {
StartRx (0, Snp);
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -769,8 +779,20 @@ SnpStationAddress (
} }
} }
// Write address CopyMem (&Snp->Mode->CurrentAddress, New, NET_ETHER_ADDR_LEN);
Lan9118SetMacAddress (New, Snp);
//
// If packet reception is currently activated, stop and reset it,
// set the new ethernet address and restart the packet reception.
// Otherwise, nothing to do, the MAC address will be updated in
// SnpReceiveFilters() when the UNICAST packet reception will be
// activated.
//
if (Snp->Mode->ReceiveFilterSetting != 0) {
StopRx (STOP_RX_CLEAR, Snp);
Lan9118SetMacAddress (New, Snp);
StartRx (0, Snp);
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -320,8 +320,6 @@ Lan9118SetMacAddress (
(UINT32)(Mac->Addr[4] & 0xFF) | (UINT32)(Mac->Addr[4] & 0xFF) |
((Mac->Addr[5] & 0xFF) << 8) ((Mac->Addr[5] & 0xFF) << 8)
); );
CopyMem (&Snp->Mode->CurrentAddress, &Mac, NET_ETHER_ADDR_LEN);
} }
VOID VOID
@ -398,6 +396,7 @@ Lan9118Initialize (
DEBUG ((EFI_D_WARN, "Warning: using driver-default MAC address\n")); DEBUG ((EFI_D_WARN, "Warning: using driver-default MAC address\n"));
DefaultMacAddress = FixedPcdGet64 (PcdLan9118DefaultMacAddress); DefaultMacAddress = FixedPcdGet64 (PcdLan9118DefaultMacAddress);
Lan9118SetMacAddress((EFI_MAC_ADDRESS *) &DefaultMacAddress, Snp); Lan9118SetMacAddress((EFI_MAC_ADDRESS *) &DefaultMacAddress, Snp);
CopyMem (&Snp->Mode->CurrentAddress, &DefaultMacAddress, NET_ETHER_ADDR_LEN);
} }
} else { } else {
// Store the MAC address that was loaded from EEPROM // Store the MAC address that was loaded from EEPROM