From 6d287c9681b37b71e8dade989cae21597bce4684 Mon Sep 17 00:00:00 2001 From: Scalpel_cp <165da7fc5536ee16440a98f161bfa866a8b94595G55xazV5> Date: Thu, 20 Mar 2008 18:42:45 +0000 Subject: [PATCH] RTL driver changes. Set size of packet to send. Initialize RxBuffer. Packet sending is still VERY unstable. --- source/Cosmos.Driver.RTL8139/Packet.cs | 7 ++- source/Cosmos.Driver.RTL8139/RTL8139.cs | 59 ++++++++----------- .../Register/TransmitStatusDescriptor.cs | 19 ++++++ source/FrodeTest/Program.cs | 2 +- source/FrodeTest/Shell/Session.cs | 26 ++++++-- source/FrodeTest/Test/RTL8139Test.cs | 12 ++-- 6 files changed, 78 insertions(+), 47 deletions(-) diff --git a/source/Cosmos.Driver.RTL8139/Packet.cs b/source/Cosmos.Driver.RTL8139/Packet.cs index 1eb597b1e..52e5d6ce7 100644 --- a/source/Cosmos.Driver.RTL8139/Packet.cs +++ b/source/Cosmos.Driver.RTL8139/Packet.cs @@ -20,9 +20,12 @@ namespace Cosmos.Driver.RTL8139 body = data; } - public byte[] PacketBody() + public byte[] PacketBody { - return body; + get + { + return body; + } //return new byte[10]; //TODO: Redo this completely! Hardcoded to some bogus value now. } } diff --git a/source/Cosmos.Driver.RTL8139/RTL8139.cs b/source/Cosmos.Driver.RTL8139/RTL8139.cs index 5f366ab13..5b59f25eb 100644 --- a/source/Cosmos.Driver.RTL8139/RTL8139.cs +++ b/source/Cosmos.Driver.RTL8139/RTL8139.cs @@ -227,16 +227,18 @@ namespace Cosmos.Driver.RTL8139 /// Initialize the Receive Buffer. The RBSTART register consists of 4 bytes (0x30h to 0x33h) which should contain /// the address of a buffer to save incoming data to. /// - private void InitReceiveBuffer() + public void InitReceiveBuffer() { - //TODO: Really unsure of the types and math here... - //char[] rx_buffer = new char[8192+16]; //8k + header - //pciCard.Write8(RTL8139Register.RxBuf, (byte)rx_buffer); - //byte[] rxbuffer = new byte( - //Prepare a buffer area + byte[] rxbuffer = new byte[2048]; + + UInt32 address = pciCard.BaseAddress1 + (byte)MainRegister.Bit.RxBuf; //Write the address of the buffer area to the RBSTART + WriteAddressToPCI(ref rxbuffer, address); + + Console.WriteLine("RxBuffer contains address: " + IOSpace.Read32(address)); + } /// @@ -245,20 +247,21 @@ namespace Cosmos.Driver.RTL8139 /// /// /// - private unsafe void WriteBufferToPCI(byte[] bytearray, uint address) + private unsafe void WriteAddressToPCI(ref byte[] bytearray, uint address) { - /*fixed (byte* bodystart = &bytearray[0]) - { - IOSpace.Write32(address, (uint)bodystart); - } - */ + + /* The data in the bytearray contains the actual bytes we want to transfer to the network. + * This bytearray must be in a continous memoryarea on the computer. + * We then write the address of this memoryarea to the network card. + * The address is stored in the Transmit Start Address which corresponds to the Transmit Status Descriptor we are currently using (0-3). + */ fixed (byte* bodystart = &bytearray[0]) { IntPtr bodyAddress = (IntPtr)bodystart; IOSpace.Write32(address, (uint)bodyAddress); - Console.WriteLine("Address: + " + (uint)bodyAddress); + Console.WriteLine("Address where packet body is stored: " + (uint)bodyAddress); } } @@ -271,37 +274,27 @@ namespace Cosmos.Driver.RTL8139 //Tell the PCI card the address of body of the Packet. UInt32 address = pciCard.BaseAddress1 + - (byte)MainRegister.Bit.TSD0 + + (byte)MainRegister.Bit.TSD0 + //I think this should be TSAD0, but then no packet is sent... TransmitStatusDescriptor.GetCurrentTSDescriptor(); - byte[] body = packet.PacketBody(); + Console.WriteLine("Address of TSAD0: " + address); - Console.WriteLine("Packet to send: "); - foreach (byte item in body) - { - Console.Write(item + ":"); - } - Console.WriteLine(); + byte[] body = packet.PacketBody; - this.WriteBufferToPCI(body, address); + WriteAddressToPCI(ref body, address); - Console.WriteLine("Data in TSD0:"); + Console.Write("Data in Transmit Status Descriptor " + TransmitStatusDescriptor.GetCurrentTSDescriptor() + ":"); Console.WriteLine(IOSpace.Read32(address)); - - //Console.WriteLine("Address of packet: " + (string)(&body[0])); + //At this point the TSDA0 should contain the address of the data. + Console.WriteLine("The Data pointed to: " + IOSpace.Read32(IOSpace.Read32(address))); //Set the transmit status - which enables the transmit. TransmitStatusDescriptor tsd = TransmitStatusDescriptor.Load(pciCard); - this.SetEarlyTxThreshold(1024); + tsd.Size = body.Length; + Console.WriteLine("Told NIC to send " + tsd.Size + " bytes."); + SetEarlyTxThreshold(1024); Console.WriteLine("Sending..."); tsd.ClearOWNBit(); TransmitStatusDescriptor.IncrementTSDescriptor(); } - - - - - - - } } diff --git a/source/Cosmos.Driver.RTL8139/Register/TransmitStatusDescriptor.cs b/source/Cosmos.Driver.RTL8139/Register/TransmitStatusDescriptor.cs index fc48ed45b..ee60242c2 100644 --- a/source/Cosmos.Driver.RTL8139/Register/TransmitStatusDescriptor.cs +++ b/source/Cosmos.Driver.RTL8139/Register/TransmitStatusDescriptor.cs @@ -52,6 +52,25 @@ namespace Cosmos.Driver.RTL8139.Register IOSpace.Write8(tdsAddress + offset, data); } + /// + /// The total size in bytes of the data in the descriptor. Must not be longer then 1792 bytes (0x700h), this + /// will set Tx queue invalid. + /// + public int Size + { + get + { + byte offset = 0; + return (int)IOSpace.Read8(tds + offset); + } + set + { + //TODO: Check this - the register contains 12 bits. We only write 8 bits here. + byte offset = 0; + IOSpace.Write8(tds + offset, (byte)value); + } + } + public UInt32 TSD() { return IOSpace.Read32(tdsAddress); diff --git a/source/FrodeTest/Program.cs b/source/FrodeTest/Program.cs index 68cbe4652..96687e657 100644 --- a/source/FrodeTest/Program.cs +++ b/source/FrodeTest/Program.cs @@ -33,7 +33,7 @@ namespace FrodeTest //Test.SwitchTest.RunTest(); Test.RTL8139Test.RunTest(); //Test.BinaryHelperTest.RunTest(); - Test.TransmitStatusDescriptorTest.RunTest(); + //Test.TransmitStatusDescriptorTest.RunTest(); //Test.PacketHeaderTest.RunTest(); //Test.RAMBusTest.RunTest(); //Test.BoolTest.RunTest(); diff --git a/source/FrodeTest/Shell/Session.cs b/source/FrodeTest/Shell/Session.cs index f7c5f24a2..47202b1fa 100644 --- a/source/FrodeTest/Shell/Session.cs +++ b/source/FrodeTest/Shell/Session.cs @@ -30,14 +30,32 @@ namespace FrodeTest.Shell nic.Enable(); Console.WriteLine("Enabled Network card"); } - else if (command.Equals("timer")) + else if (command.Equals("send")) { - Console.WriteLine("NIC TimerCount: " + nic.TimerCount); + //Console.WriteLine("NIC TimerCount: " + nic.TimerCount); + //Cosmos.Hardware.PC.Bus.PCIDevice pciNic = Cosmos.Hardware.PC.Bus.PCIBus.GetPCIDevice(0, 3, 0); + Cosmos.Driver.RTL8139.PacketHeader head = new Cosmos.Driver.RTL8139.PacketHeader(0xFF); + byte[] data = FrodeTest.Test.Mock.FakeBroadcastPacket.GetFakePacketAllHigh(); + Cosmos.Driver.RTL8139.Packet packet = new Cosmos.Driver.RTL8139.Packet(head, data); + + //nic = new Cosmos.Driver.RTL8139.RTL8139(pciNic); + if (nic == null) + { + Console.WriteLine("Enable NIC with command nic first"); + return; + } + nic.Enable(); + nic.EnableRecieve(); + nic.EnableTransmit(); + nic.Transmit(packet); } else if (command.Equals("reset")) { - nic.TimerCount = 1; - Console.WriteLine("NIC TimerCount: " + nic.TimerCount); + //nic.TimerCount = 1; + nic.SoftReset(); + nic.EnableTransmit(); + nic.EnableRecieve(); + Console.WriteLine("NIC reset"); } else Console.WriteLine("No such systemcommand or application: " + command); diff --git a/source/FrodeTest/Test/RTL8139Test.cs b/source/FrodeTest/Test/RTL8139Test.cs index 840859aae..b0f31fd69 100644 --- a/source/FrodeTest/Test/RTL8139Test.cs +++ b/source/FrodeTest/Test/RTL8139Test.cs @@ -15,7 +15,7 @@ namespace FrodeTest.Test //Console.WriteLine("PCI Command: " + pciNic.Command); //pciNic.EnableDevice(); - Console.WriteLine("PCI Command: " + pciNic.Command); + //Console.WriteLine("PCI Command: " + pciNic.Command); if (!pciNic.DeviceExists) Console.WriteLine("Unable to find PCI device for Network card"); @@ -31,18 +31,16 @@ namespace FrodeTest.Test Console.WriteLine("BaseAddress1 is : " + pciNic.BaseAddress1); Console.WriteLine("Enabling card..."); nic.Enable(); - - //nic.SoftReset(); + //nic.InitReceiveBuffer(); nic.EnableRecieve(); nic.EnableTransmit(); - Cosmos.Hardware.PC.Global.Sleep(50); - Console.WriteLine("Timer: " + nic.TimerCount); + //Cosmos.Hardware.PC.Global.Sleep(50); + //Console.WriteLine("Timer: " + nic.TimerCount); Cosmos.Driver.RTL8139.PacketHeader head = new Cosmos.Driver.RTL8139.PacketHeader(0x77); - byte[] data = Mock.FakeBroadcastPacket.GetFakePacket(); + byte[] data = Mock.FakeBroadcastPacket.GetFakePacketAllHigh(); Cosmos.Driver.RTL8139.Packet packet = new Cosmos.Driver.RTL8139.Packet(head, data); nic.Transmit(packet); - Console.WriteLine("Transmit called"); } } }