protected override void Initialize() { Device.Name = "AMDPCNet_0x" + Device.Resources.GetIOPortRegion(0).BaseIOPort.ToString("X"); ioProm1 = Device.Resources.GetIOPortReadWrite(0, 0x0); ioProm4 = Device.Resources.GetIOPortReadWrite(0, 0x4); rdp = Device.Resources.GetIOPortReadWrite(0, 0x10); rap = Device.Resources.GetIOPortReadWrite(0, 0x14); bdp = Device.Resources.GetIOPortReadWrite(0, 0x1C); initBlock = Device.Resources.GetMemory(0); txDescriptor = Device.Resources.GetMemory(1); rxDescriptor = Device.Resources.GetMemory(2); buffers = Device.Resources.GetMemory(3); bufferSize = 2048; uint len = (ushort)(~bufferSize); len = ((len + 1) & 0x0FFF) | 0x8000F000; physicalBufferAddress = HAL.GetPhysicalAddress(buffers); for (uint index = 0; index < 16; index++) { uint offset = index * 4; rxDescriptor.Write32((offset + 1) * 4, len); rxDescriptor.Write32((offset + 2) * 4, physicalBufferAddress + (bufferSize * index)); txDescriptor.Write32((offset + 2) * 4, physicalBufferAddress + (bufferSize * (index + 16))); } nextTXDesc = 0; }
/// <summary> /// Setups this hardware device driver /// </summary> /// <param name="hardwareResources"></param> /// <returns></returns> public override bool Setup(HardwareResources hardwareResources) { this.HardwareResources = hardwareResources; base.Name = "AMDPCNet_0x" + hardwareResources.GetIOPortRegion(0).BaseIOPort.ToString("X"); ioProm1 = hardwareResources.GetIOPortReadWrite(0, 0x0); ioProm4 = hardwareResources.GetIOPortReadWrite(0, 0x4); rdp = hardwareResources.GetIOPortReadWrite(0, 0x10); rap = hardwareResources.GetIOPortReadWrite(0, 0x14); bdp = hardwareResources.GetIOPortReadWrite(0, 0x1C); initBlock = hardwareResources.GetMemory(0); txDescriptor = hardwareResources.GetMemory(1); rxDescriptor = hardwareResources.GetMemory(2); buffers = hardwareResources.GetMemory(3); bufferSize = 2048; uint len = (ushort)(~bufferSize); len = ((len + 1) & 0x0FFF) | 0x8000F000; physicalBufferAddress = HAL.GetPhysicalAddress(buffers); for (uint index = 0; index < 16; index++) { uint offset = index * 4; rxDescriptor.Write32((offset + 1) * 4, len); rxDescriptor.Write32((offset + 2) * 4, physicalBufferAddress + (bufferSize * index)); txDescriptor.Write32((offset + 2) * 4, physicalBufferAddress + (bufferSize * (index + 16))); } nextTXDesc = 0; return(true); }
/// <summary> /// Retrieves the packets. /// </summary> protected void RetrievePackets() { // Check all descriptors for (uint rxd = 0; rxd < 16; rxd++) { uint offset = rxd * 4; uint status = rxDescriptor.Read32(offset + 1); // Check is 31/OWN bit is not set if ((status & 0x80000000) == 0) { ushort length = (ushort)(rxDescriptor.Read16(offset + 0) & 0xFFF); var data = new byte[length]; for (uint i = 0; i < data.Length; i++) { data[i] = buffers.Read8((rxd * bufferSize) + i); } // if queue fails because it is already full, the packet is discarded packetBuffer.QueuePacketForStack(data); // Clear 31/OWN bit rxDescriptor.Write32(offset + 1, status | 0x80000000); } } }
/// <summary> /// Sends the packet. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public bool SendPacket(byte[] data) { uint txd = nextTXDesc++; if (nextTXDesc >= 16) { nextTXDesc = 0; } uint offset = txd * 4; // check if (oldest) descriptor is available (Bit 31/OWN = 0 available) if ((txDescriptor.Read32(offset + 1) & 0x80000000) == 0) { for (uint i = 0; i < data.Length; i++) { buffers.Write8((txd * bufferSize) + i, data[i]); } ushort length = (ushort)(~data.Length); length++; // Set bits 31/OWN, 25/STP (start of packet), 24/ENP (end of packet) and two's compliment of the buffer length txDescriptor.Write32(offset + 1, (length & (uint)(0x0FFF)) | (uint)(0x8300F000)); return(true); } return(false); }
public override void Start() { if (Device.Status != DeviceStatus.Available) { return; } // Enable the card //HardwareResources.DeviceResource.EnableDevice(); // TODO // Do a 32-bit write to set 32-bit mode rdp.Write32(0); // Get the EEPROM MAC Address var eepromMac = new byte[6]; var data = ioProm1.Read32(); eepromMac[0] = (byte)(data & 0xFF); eepromMac[1] = (byte)((data >> 8) & 0xFF); eepromMac[2] = (byte)((data >> 16) & 0xFF); eepromMac[3] = (byte)((data >> 24) & 0xFF); data = ioProm4.Read32(); eepromMac[4] = (byte)(data & 0xFF); eepromMac[5] = (byte)((data >> 8) & 0xFF); macAddress = new MACAddress(eepromMac); // Fill in the initialization block initBlock.Write32(0, (0x4 << 28) | (0x4 << 30)); initBlock.Write32(4, (uint)(eepromMac[0] | (eepromMac[1] << 8) | (eepromMac[2] << 16) | (eepromMac[3] << 24))); initBlock.Write32(8, (uint)(eepromMac[4] | (eepromMac[5] << 8))); // Fill in the hardware MAC address initBlock.Write32(16, 0x0); initBlock.Write32(24, 0x0); initBlock.Write32(28, rxDescriptor.Address); initBlock.Write32(32, txDescriptor.Address); // Write the initialization blocks address to the registers on the card InitializationBlockAddress = HAL.GetPhysicalAddress(initBlock); // Set the device to PCNet-PCI II Controller mode (full 32-bit mode) SoftwareStyleRegister = 0x03; nextTXDesc = 0; Device.Status = DeviceStatus.Online; }
/// <summary> /// Sets the fifo. /// </summary> /// <param name="index">The index.</param> /// <param name="value">The value.</param> protected void SetFifo(uint index, uint value) { fifo.Write32(index * 4, value); }