Implement software loopback for PCNet driver.

This commit is contained in:
TomAwezome 2022-07-08 04:49:34 -04:00
parent 92a36b3ada
commit 00c336c255
2 changed files with 12 additions and 6 deletions

View file

@ -501,12 +501,21 @@ I64 PCNetTransmitPacketAllocate(U8 **packet_buffer_out, I64 length)
return de_index; return de_index;
} }
U8 *EthernetMACGet()
{
return pcnet.mac_address;
}
U0 PCNetTransmitPacketFinish(I64 de_index) U0 PCNetTransmitPacketFinish(I64 de_index)
{/* Release ownership of the packet to the PCNet card {/* Release ownership of the packet to the PCNet card
by setting the OWN bit to 1. */ by setting the OWN bit to 1. */
CPCNetDescriptorEntry *entry = &pcnet.tx_de_buffer[de_index * sizeof(CPCNetDescriptorEntry)]; CPCNetDescriptorEntry *entry = &pcnet.tx_de_buffer[de_index * sizeof(CPCNetDescriptorEntry)];
// check the TX packet MAC against local MAC, if they match: software loopback the TX packet to RX NetQueue
if (!MemCompare(EthernetMACGet(), pcnet.tx_buffer_addr + de_index * ETHERNET_FRAME_SIZE, 6))
NetQueuePush(pcnet.tx_buffer_addr + de_index * ETHERNET_FRAME_SIZE, U16_MAX - (entry->status1 & 0xFFFF) + 1);
Bts(&entry->status1, PCNET_DESCRIPTORf_OWN); Bts(&entry->status1, PCNET_DESCRIPTORf_OWN);
NetLog("PCNET FINISH TX PACKET: TX DE index: %X, OWN bit of entry at entry: %b.", NetLog("PCNET FINISH TX PACKET: TX DE index: %X, OWN bit of entry at entry: %b.",
de_index, Bt(&entry->status1, PCNET_DESCRIPTORf_OWN)); de_index, Bt(&entry->status1, PCNET_DESCRIPTORf_OWN));
@ -742,11 +751,6 @@ I64 EthernetFrameAllocate(U8 **packet_buffer_out,
return de_index; return de_index;
} }
U8 *EthernetMACGet()
{
return pcnet.mac_address;
}
U0 NetStop() U0 NetStop()
{ // Halt network activity by setting STOP bit on Status CSR. { // Halt network activity by setting STOP bit on Status CSR.
U32 csr = PCNetCSRRead(PCNET_CSR_CTRLSTATUS); U32 csr = PCNetCSRRead(PCNET_CSR_CTRLSTATUS);

View file

@ -127,9 +127,11 @@ CARPHash *ARPCachePut(U32 ip_address, U8 *mac_address)
} }
U0 ARPLocalIPV4Set(U32 ip_address) U0 ARPLocalIPV4Set(U32 ip_address)
{ // takes in little endian IP, stores into globals as Big Endian { // takes in little endian IP, stores into arp_globals as Big Endian and into ARP cache as Little Endian
arp_globals.local_ipv4 = EndianU32(ip_address); arp_globals.local_ipv4 = EndianU32(ip_address);
ARPCachePut(ip_address, EthernetMACGet);
ARPSend(ARP_REPLY, ARPSend(ARP_REPLY,
ethernet_globals.ethernet_broadcast, ethernet_globals.ethernet_broadcast,
EthernetMACGet, EthernetMACGet,