https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4561998a45b928461eacf…
commit 4561998a45b928461eacf323ec23d15dd19e6f0e
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Sat May 19 00:23:45 2018 +0200
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Thu Feb 7 19:48:54 2019 +0100
[E1000] Create an initial driver skeleton
Based on the rtl8139 driver written by Cameron Gutman
CORE-14675
---
drivers/network/dd/CMakeLists.txt | 1 +
drivers/network/dd/e1000/CMakeLists.txt | 20 ++
drivers/network/dd/e1000/debug.h | 64 +++++++
drivers/network/dd/e1000/e1000.rc | 5 +
drivers/network/dd/e1000/e1000hw.h | 19 ++
drivers/network/dd/e1000/hardware.c | 193 +++++++++++++++++++
drivers/network/dd/e1000/info.c | 250 +++++++++++++++++++++++++
drivers/network/dd/e1000/interrupt.c | 49 +++++
drivers/network/dd/e1000/ndis.c | 315 ++++++++++++++++++++++++++++++++
drivers/network/dd/e1000/nic.h | 171 +++++++++++++++++
media/inf/CMakeLists.txt | 1 +
media/inf/nete1000.inf | 50 +++++
12 files changed, 1138 insertions(+)
diff --git a/drivers/network/dd/CMakeLists.txt b/drivers/network/dd/CMakeLists.txt
index ffa9635eca..89b96df489 100644
--- a/drivers/network/dd/CMakeLists.txt
+++ b/drivers/network/dd/CMakeLists.txt
@@ -1,4 +1,5 @@
+add_subdirectory(e1000)
add_subdirectory(ne2000)
add_subdirectory(pcnet)
add_subdirectory(rtl8139)
diff --git a/drivers/network/dd/e1000/CMakeLists.txt
b/drivers/network/dd/e1000/CMakeLists.txt
new file mode 100644
index 0000000000..eeee376c2e
--- /dev/null
+++ b/drivers/network/dd/e1000/CMakeLists.txt
@@ -0,0 +1,20 @@
+
+add_definitions(
+ -DNDIS50_MINIPORT
+ -DNDIS_MINIPORT_DRIVER
+ -DNDIS_LEGACY_MINIPORT)
+
+list(APPEND SOURCE
+ ndis.c
+ hardware.c
+ info.c
+ interrupt.c
+ nic.h
+ e1000hw.h
+ debug.h)
+
+add_library(e1000 SHARED ${SOURCE} e1000.rc)
+add_pch(e1000 nic.h SOURCE)
+set_module_type(e1000 kernelmodedriver)
+add_importlibs(e1000 ndis ntoskrnl hal)
+add_cd_file(TARGET e1000 DESTINATION reactos/system32/drivers FOR all)
diff --git a/drivers/network/dd/e1000/debug.h b/drivers/network/dd/e1000/debug.h
new file mode 100644
index 0000000000..b6ff2cf92e
--- /dev/null
+++ b/drivers/network/dd/e1000/debug.h
@@ -0,0 +1,64 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS Intel PRO/1000 Driver
+ * FILE: include/debug.h
+ * PURPOSE: Debugging support macros
+ * DEFINES: DBG - Enable debug output
+ * NASSERT - Disable assertions
+ */
+
+#pragma once
+
+#define NORMAL_MASK 0x000000FF
+#define SPECIAL_MASK 0xFFFFFF00
+#define MIN_TRACE 0x00000001
+#define MID_TRACE 0x00000002
+#define MAX_TRACE 0x00000003
+
+#define DEBUG_MEMORY 0x00000100
+#define DEBUG_ULTRA 0xFFFFFFFF
+
+#if DBG
+
+extern ULONG DebugTraceLevel;
+
+
+#define NDIS_DbgPrint(_t_, _x_) \
+ if ((_t_ > NORMAL_MASK) \
+ ? (DebugTraceLevel & _t_) > NORMAL_MASK \
+ : (DebugTraceLevel & NORMAL_MASK) >= _t_) { \
+ DbgPrint("(%s:%d)(%s) ", __FILE__, __LINE__, __FUNCTION__); \
+ DbgPrint _x_ ; \
+ }
+
+
+#define ASSERT_IRQL(x) ASSERT(KeGetCurrentIrql() <= (x))
+#define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql() == (x))
+
+#else /* DBG */
+
+#define NDIS_DbgPrint(_t_, _x_)
+
+#define ASSERT_IRQL(x)
+#define ASSERT_IRQL_EQUAL(x)
+/* #define ASSERT(x) */ /* ndis.h */
+
+#endif /* DBG */
+
+
+#define assert(x) ASSERT(x)
+#define assert_irql(x) ASSERT_IRQL(x)
+
+
+#define UNIMPLEMENTED \
+ NDIS_DbgPrint(MIN_TRACE, ("UNIMPLEMENTED.\n"));
+
+
+#define UNIMPLEMENTED_DBGBREAK(...) \
+ do { \
+ NDIS_DbgPrint(MIN_TRACE, ("UNIMPLEMENTED.\n")); \
+ DbgPrint("" __VA_ARGS__); \
+ DbgBreakPoint(); \
+ } while (0)
+
+
diff --git a/drivers/network/dd/e1000/e1000.rc b/drivers/network/dd/e1000/e1000.rc
new file mode 100644
index 0000000000..88019a54a0
--- /dev/null
+++ b/drivers/network/dd/e1000/e1000.rc
@@ -0,0 +1,5 @@
+#define REACTOS_VERSION_DLL
+#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Intel PRO/1000 Driver"
+#define REACTOS_STR_INTERNAL_NAME "e1000"
+#define REACTOS_STR_ORIGINAL_FILENAME "e1000.sys"
+#include <reactos/version.rc>
diff --git a/drivers/network/dd/e1000/e1000hw.h b/drivers/network/dd/e1000/e1000hw.h
new file mode 100644
index 0000000000..57ac8fc2e8
--- /dev/null
+++ b/drivers/network/dd/e1000/e1000hw.h
@@ -0,0 +1,19 @@
+/*
+ * PROJECT: ReactOS Intel PRO/1000 Driver
+ * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Intel PRO/1000 driver definitions
+ * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen(a)reactos.org)
+ */
+
+#pragma once
+
+#define IEEE_802_ADDR_LENGTH 6
+
+
+/* Ethernet frame header */
+typedef struct _ETH_HEADER {
+ UCHAR Destination[IEEE_802_ADDR_LENGTH];
+ UCHAR Source[IEEE_802_ADDR_LENGTH];
+ USHORT PayloadType;
+} ETH_HEADER, *PETH_HEADER;
+
diff --git a/drivers/network/dd/e1000/hardware.c b/drivers/network/dd/e1000/hardware.c
new file mode 100644
index 0000000000..b238be0997
--- /dev/null
+++ b/drivers/network/dd/e1000/hardware.c
@@ -0,0 +1,193 @@
+/*
+ * PROJECT: ReactOS Intel PRO/1000 Driver
+ * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Hardware specific functions
+ * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen(a)reactos.org)
+ */
+
+#include "nic.h"
+
+#include <debug.h>
+
+BOOLEAN
+NTAPI
+NICRecognizeHardware(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return FALSE;
+}
+
+NDIS_STATUS
+NTAPI
+NICInitializeAdapterResources(
+ IN PE1000_ADAPTER Adapter,
+ IN PNDIS_RESOURCE_LIST ResourceList)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICAllocateResources(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICRegisterInterrupts(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICUnregisterInterrupts(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICReleaseIoResources(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+
+NDIS_STATUS
+NTAPI
+NICPowerOn(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICSoftReset(
+ IN PE1000_ADAPTER adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICEnableTxRx(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICDisableTxRx(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICGetPermanentMacAddress(
+ IN PE1000_ADAPTER Adapter,
+ OUT PUCHAR MacAddress)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICApplyInterruptMask(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICDisableInterrupts(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+USHORT
+NTAPI
+NICInterruptRecognized(
+ IN PE1000_ADAPTER Adapter,
+ OUT PBOOLEAN InterruptRecognized)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return 0;
+}
+
+VOID
+NTAPI
+NICAcknowledgeInterrupts(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+}
+
+VOID
+NTAPI
+NICUpdateLinkStatus(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+}
+
+NDIS_STATUS
+NTAPI
+NICApplyPacketFilter(
+ IN PE1000_ADAPTER Adapter)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+NICTransmitPacket(
+ IN PE1000_ADAPTER Adapter,
+ IN UCHAR TxDesc,
+ IN ULONG PhysicalAddress,
+ IN ULONG Length)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
diff --git a/drivers/network/dd/e1000/info.c b/drivers/network/dd/e1000/info.c
new file mode 100644
index 0000000000..84817956e4
--- /dev/null
+++ b/drivers/network/dd/e1000/info.c
@@ -0,0 +1,250 @@
+/*
+ * PROJECT: ReactOS Intel PRO/1000 Driver
+ * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Miniport information callbacks
+ * COPYRIGHT: Copyright 2013 Cameron Gutman (cameron.gutman(a)reactos.org)
+ * Copyright 2018 Mark Jansen (mark.jansen(a)reactos.org)
+ */
+
+#include "nic.h"
+
+#include <debug.h>
+
+static ULONG SupportedOidList[] =
+{
+ OID_GEN_SUPPORTED_LIST,
+ OID_GEN_HARDWARE_STATUS,
+ OID_GEN_MEDIA_SUPPORTED,
+ OID_GEN_MEDIA_IN_USE,
+ OID_GEN_MAXIMUM_LOOKAHEAD,
+ OID_GEN_MAXIMUM_FRAME_SIZE,
+ OID_GEN_LINK_SPEED,
+ OID_GEN_TRANSMIT_BUFFER_SPACE,
+ OID_GEN_RECEIVE_BUFFER_SPACE,
+ OID_GEN_RECEIVE_BLOCK_SIZE,
+ OID_GEN_TRANSMIT_BLOCK_SIZE,
+ OID_GEN_VENDOR_ID,
+ OID_GEN_VENDOR_DESCRIPTION,
+ OID_GEN_VENDOR_DRIVER_VERSION,
+ OID_GEN_CURRENT_LOOKAHEAD,
+ OID_GEN_DRIVER_VERSION,
+ OID_GEN_MAXIMUM_TOTAL_SIZE,
+ OID_GEN_MAC_OPTIONS,
+ OID_GEN_MEDIA_CONNECT_STATUS,
+ OID_802_3_PERMANENT_ADDRESS,
+ OID_802_3_CURRENT_ADDRESS,
+};
+
+NDIS_STATUS
+NTAPI
+MiniportQueryInformation(
+ IN NDIS_HANDLE MiniportAdapterContext,
+ IN NDIS_OID Oid,
+ IN PVOID InformationBuffer,
+ IN ULONG InformationBufferLength,
+ OUT PULONG BytesWritten,
+ OUT PULONG BytesNeeded)
+{
+ PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
+ ULONG genericUlong;
+ ULONG copyLength;
+ PVOID copySource;
+ NDIS_STATUS status;
+
+ status = NDIS_STATUS_SUCCESS;
+ copySource = &genericUlong;
+ copyLength = sizeof(ULONG);
+
+ NdisAcquireSpinLock(&Adapter->Lock);
+
+ switch (Oid)
+ {
+ case OID_GEN_SUPPORTED_LIST:
+ copySource = (PVOID)&SupportedOidList;
+ copyLength = sizeof(SupportedOidList);
+ break;
+
+ case OID_GEN_HARDWARE_STATUS:
+ UNIMPLEMENTED_DBGBREAK();
+ genericUlong = (ULONG)NdisHardwareStatusReady; //FIXME
+ break;
+
+ case OID_GEN_MEDIA_SUPPORTED:
+ case OID_GEN_MEDIA_IN_USE:
+ {
+ static const NDIS_MEDIUM medium = NdisMedium802_3;
+ copySource = (PVOID)&medium;
+ copyLength = sizeof(medium);
+ break;
+ }
+
+ case OID_GEN_RECEIVE_BLOCK_SIZE:
+ case OID_GEN_TRANSMIT_BLOCK_SIZE:
+ case OID_GEN_CURRENT_LOOKAHEAD:
+ case OID_GEN_MAXIMUM_LOOKAHEAD:
+ case OID_GEN_MAXIMUM_FRAME_SIZE:
+ genericUlong = MAXIMUM_FRAME_SIZE - sizeof(ETH_HEADER);
+ break;
+
+ case OID_GEN_LINK_SPEED:
+ genericUlong = Adapter->LinkSpeedMbps * 1000;
+ break;
+
+ case OID_GEN_TRANSMIT_BUFFER_SPACE:
+ genericUlong = MAXIMUM_FRAME_SIZE;
+ break;
+
+ case OID_GEN_RECEIVE_BUFFER_SPACE:
+ genericUlong = RECEIVE_BUFFER_SIZE;
+ break;
+
+ case OID_GEN_VENDOR_ID:
+ /* The 3 bytes of the MAC address is the vendor ID */
+ genericUlong = 0;
+ genericUlong |= (Adapter->PermanentMacAddress[0] << 16);
+ genericUlong |= (Adapter->PermanentMacAddress[1] << 8);
+ genericUlong |= (Adapter->PermanentMacAddress[2] & 0xFF);
+ break;
+
+ case OID_GEN_VENDOR_DESCRIPTION:
+ {
+ static UCHAR vendorDesc[] = "ReactOS Team";
+ copySource = vendorDesc;
+ copyLength = sizeof(vendorDesc);
+ break;
+ }
+
+ case OID_GEN_VENDOR_DRIVER_VERSION:
+ genericUlong = DRIVER_VERSION;
+ break;
+
+ case OID_GEN_DRIVER_VERSION:
+ {
+ static const USHORT driverVersion =
+ (NDIS_MINIPORT_MAJOR_VERSION << 8) + NDIS_MINIPORT_MINOR_VERSION;
+ copySource = (PVOID)&driverVersion;
+ copyLength = sizeof(driverVersion);
+ break;
+ }
+
+ case OID_GEN_MAXIMUM_TOTAL_SIZE:
+ genericUlong = MAXIMUM_FRAME_SIZE;
+ break;
+
+ case OID_GEN_MAC_OPTIONS:
+ genericUlong = NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
+ NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |
+ NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
+ NDIS_MAC_OPTION_NO_LOOPBACK;
+ break;
+
+ case OID_GEN_MEDIA_CONNECT_STATUS:
+ genericUlong = Adapter->MediaState;
+ break;
+
+
+ case OID_802_3_CURRENT_ADDRESS:
+ copySource = Adapter->CurrentMacAddress;
+ copyLength = IEEE_802_ADDR_LENGTH;
+ break;
+
+ case OID_802_3_PERMANENT_ADDRESS:
+ copySource = Adapter->PermanentMacAddress;
+ copyLength = IEEE_802_ADDR_LENGTH;
+ break;
+
+ default:
+ NDIS_DbgPrint(MIN_TRACE, ("Unknown OID 0x%x\n", Oid));
+ status = NDIS_STATUS_NOT_SUPPORTED;
+ break;
+ }
+
+ if (status == NDIS_STATUS_SUCCESS)
+ {
+ if (copyLength > InformationBufferLength)
+ {
+ *BytesNeeded = copyLength;
+ *BytesWritten = 0;
+ status = NDIS_STATUS_INVALID_LENGTH;
+ }
+ else
+ {
+ NdisMoveMemory(InformationBuffer, copySource, copyLength);
+ *BytesWritten = copyLength;
+ *BytesNeeded = copyLength;
+ }
+ }
+ else
+ {
+ *BytesWritten = 0;
+ *BytesNeeded = 0;
+ }
+
+ NdisReleaseSpinLock(&Adapter->Lock);
+
+ NDIS_DbgPrint(MAX_TRACE, ("Query OID 0x%x: Completed with status 0x%x (%d,
%d)\n",
+ Oid, status, *BytesWritten, *BytesNeeded));
+
+ return status;
+}
+
+NDIS_STATUS
+NTAPI
+MiniportSetInformation(
+ IN NDIS_HANDLE MiniportAdapterContext,
+ IN NDIS_OID Oid,
+ IN PVOID InformationBuffer,
+ IN ULONG InformationBufferLength,
+ OUT PULONG BytesRead,
+ OUT PULONG BytesNeeded)
+{
+ PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
+ ULONG genericUlong;
+ NDIS_STATUS status;
+
+ status = NDIS_STATUS_SUCCESS;
+
+ NdisAcquireSpinLock(&Adapter->Lock);
+
+ switch (Oid)
+ {
+ case OID_GEN_CURRENT_LOOKAHEAD:
+ if (InformationBufferLength < sizeof(ULONG))
+ {
+ *BytesRead = 0;
+ *BytesNeeded = sizeof(ULONG);
+ status = NDIS_STATUS_INVALID_LENGTH;
+ break;
+ }
+
+ NdisMoveMemory(&genericUlong, InformationBuffer, sizeof(ULONG));
+
+ if (genericUlong > MAXIMUM_FRAME_SIZE - sizeof(ETH_HEADER))
+ {
+ status = NDIS_STATUS_INVALID_DATA;
+ }
+ else
+ {
+ // Ignore this...
+ }
+
+ break;
+
+ default:
+ NDIS_DbgPrint(MIN_TRACE, ("Unknown OID 0x%x\n", Oid));
+ status = NDIS_STATUS_NOT_SUPPORTED;
+ *BytesRead = 0;
+ *BytesNeeded = 0;
+ break;
+ }
+
+ if (status == NDIS_STATUS_SUCCESS)
+ {
+ *BytesRead = InformationBufferLength;
+ *BytesNeeded = 0;
+ }
+
+ NdisReleaseSpinLock(&Adapter->Lock);
+
+ return status;
+}
diff --git a/drivers/network/dd/e1000/interrupt.c b/drivers/network/dd/e1000/interrupt.c
new file mode 100644
index 0000000000..16e46e76ce
--- /dev/null
+++ b/drivers/network/dd/e1000/interrupt.c
@@ -0,0 +1,49 @@
+/*
+ * PROJECT: ReactOS Intel PRO/1000 Driver
+ * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Interrupt handlers
+ * COPYRIGHT: Copyright 2013 Cameron Gutman (cameron.gutman(a)reactos.org)
+ * Copyright 2018 Mark Jansen (mark.jansen(a)reactos.org)
+ */
+
+#include "nic.h"
+
+#include <debug.h>
+
+VOID
+NTAPI
+MiniportISR(
+ OUT PBOOLEAN InterruptRecognized,
+ OUT PBOOLEAN QueueMiniportHandleInterrupt,
+ IN NDIS_HANDLE MiniportAdapterContext)
+{
+ PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
+
+ //
+ // FIXME: We need to synchronize with this ISR for changes to InterruptPending,
+ // LinkChange, MediaState, and LinkSpeedMbps. We can get away with IRQL
+ // synchronization on non-SMP machines because we run a DIRQL here.
+ //
+
+ Adapter->InterruptPending |= NICInterruptRecognized(Adapter,
InterruptRecognized);
+ if (!(*InterruptRecognized))
+ {
+ /* This is not ours. */
+ *QueueMiniportHandleInterrupt = FALSE;
+ return;
+ }
+
+ UNIMPLEMENTED;
+
+ /* Acknowledge the interrupt and mark the events pending service */
+ NICAcknowledgeInterrupts(Adapter);
+ *QueueMiniportHandleInterrupt = TRUE;
+}
+
+VOID
+NTAPI
+MiniportHandleInterrupt(
+ IN NDIS_HANDLE MiniportAdapterContext)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+}
diff --git a/drivers/network/dd/e1000/ndis.c b/drivers/network/dd/e1000/ndis.c
new file mode 100644
index 0000000000..b02f397bd9
--- /dev/null
+++ b/drivers/network/dd/e1000/ndis.c
@@ -0,0 +1,315 @@
+/*
+ * PROJECT: ReactOS Intel PRO/1000 Driver
+ * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Driver entrypoint
+ * COPYRIGHT: Copyright 2013 Cameron Gutman (cameron.gutman(a)reactos.org)
+ * Copyright 2018 Mark Jansen (mark.jansen(a)reactos.org)
+ */
+
+#include "nic.h"
+
+#include <debug.h>
+
+ULONG DebugTraceLevel = DEBUG_ULTRA;
+
+NDIS_STATUS
+NTAPI
+MiniportReset(
+ OUT PBOOLEAN AddressingReset,
+ IN NDIS_HANDLE MiniportAdapterContext)
+{
+ *AddressingReset = FALSE;
+ UNIMPLEMENTED_DBGBREAK();
+ return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+NTAPI
+MiniportSend(
+ IN NDIS_HANDLE MiniportAdapterContext,
+ IN PNDIS_PACKET Packet,
+ IN UINT Flags)
+{
+ NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+ return NDIS_STATUS_FAILURE;
+}
+
+VOID
+NTAPI
+MiniportHalt(
+ IN NDIS_HANDLE MiniportAdapterContext)
+{
+ PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
+
+ ASSERT(Adapter != NULL);
+
+ /* First disable sending / receiving */
+ NICDisableTxRx(Adapter);
+
+ /* Then unregister interrupts */
+ NICUnregisterInterrupts(Adapter);
+
+ /* Finally, free other resources (Ports, IO ranges,...) */
+ NICReleaseIoResources(Adapter);
+
+ /* Destroy the adapter context */
+ NdisFreeMemory(Adapter, sizeof(*Adapter), 0);
+}
+
+NDIS_STATUS
+NTAPI
+MiniportInitialize(
+ OUT PNDIS_STATUS OpenErrorStatus,
+ OUT PUINT SelectedMediumIndex,
+ IN PNDIS_MEDIUM MediumArray,
+ IN UINT MediumArraySize,
+ IN NDIS_HANDLE MiniportAdapterHandle,
+ IN NDIS_HANDLE WrapperConfigurationContext)
+{
+ PE1000_ADAPTER Adapter;
+ NDIS_STATUS Status;
+ UINT i;
+ PNDIS_RESOURCE_LIST ResourceList;
+ UINT ResourceListSize;
+ PCI_COMMON_CONFIG PciConfig;
+ //ULONG Value;
+
+ /* Make sure the medium is supported */
+ for (i = 0; i < MediumArraySize; i++)
+ {
+ if (MediumArray[i] == NdisMedium802_3)
+ {
+ *SelectedMediumIndex = i;
+ break;
+ }
+ }
+
+ if (i == MediumArraySize)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("802.3 medium was not found in the medium
array\n"));
+ return NDIS_STATUS_UNSUPPORTED_MEDIA;
+ }
+
+ /* Allocate our adapter context */
+ Status = NdisAllocateMemoryWithTag((PVOID*)&Adapter,
+ sizeof(*Adapter),
+ E1000_TAG);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Failed to allocate adapter context
(0x%x)\n", Status));
+ return NDIS_STATUS_RESOURCES;
+ }
+
+ RtlZeroMemory(Adapter, sizeof(*Adapter));
+ Adapter->AdapterHandle = MiniportAdapterHandle;
+ NdisAllocateSpinLock(&Adapter->Lock);
+
+
+ /* Notify NDIS of some characteristics of our NIC */
+ NdisMSetAttributesEx(MiniportAdapterHandle,
+ Adapter,
+ 0,
+ NDIS_ATTRIBUTE_BUS_MASTER,
+ NdisInterfacePci);
+
+ NdisReadPciSlotInformation(Adapter->AdapterHandle,
+ 0,
+ FIELD_OFFSET(PCI_COMMON_CONFIG, VendorID),
+ &PciConfig, sizeof(PciConfig));
+
+ Adapter->VendorID = PciConfig.VendorID;
+ Adapter->DeviceID = PciConfig.DeviceID;
+
+ Adapter->SubsystemID = PciConfig.u.type0.SubSystemID;
+ Adapter->SubsystemVendorID = PciConfig.u.type0.SubVendorID;
+
+
+ if (!NICRecognizeHardware(Adapter))
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Hardware not recognized\n"));
+ Status = NDIS_STATUS_UNSUPPORTED_MEDIA;
+ goto Cleanup;
+ }
+
+
+ /* Get our resources for IRQ and IO base information */
+ ResourceList = NULL;
+ ResourceListSize = 0;
+ NdisMQueryAdapterResources(&Status,
+ WrapperConfigurationContext,
+ ResourceList,
+ &ResourceListSize);
+ if (Status != NDIS_STATUS_RESOURCES)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unexpected failure of NdisMQueryAdapterResources
(0x%x)\n", Status));
+ Status = NDIS_STATUS_FAILURE;
+ /* call NdisWriteErrorLogEntry */
+ goto Cleanup;
+ }
+
+ Status = NdisAllocateMemoryWithTag((PVOID*)&ResourceList,
+ ResourceListSize,
+ E1000_TAG);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Failed to allocate resource list (0x%x)\n",
Status));
+ /* call NdisWriteErrorLogEntry */
+ goto Cleanup;
+ }
+
+ NdisMQueryAdapterResources(&Status,
+ WrapperConfigurationContext,
+ ResourceList,
+ &ResourceListSize);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unexpected failure of NdisMQueryAdapterResources
(0x%x)\n", Status));
+ /* call NdisWriteErrorLogEntry */
+ goto Cleanup;
+ }
+
+ ASSERT(ResourceList->Version == 1);
+ ASSERT(ResourceList->Revision == 1);
+
+ Status = NICInitializeAdapterResources(Adapter, ResourceList);
+
+ NdisFreeMemory(ResourceList, ResourceListSize, 0);
+ ResourceList = NULL;
+
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Adapter didn't receive enough
resources\n"));
+ goto Cleanup;
+ }
+
+ /* Allocate the DMA resources */
+ Status = NdisMInitializeScatterGatherDma(MiniportAdapterHandle,
+ FALSE, // 32bit
+ MAXIMUM_FRAME_SIZE);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unable to configure DMA\n"));
+ Status = NDIS_STATUS_RESOURCES;
+ goto Cleanup;
+ }
+
+ Status = NICAllocateIoResources(Adapter);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unable to allocate resources\n"));
+ Status = NDIS_STATUS_RESOURCES;
+ goto Cleanup;
+ }
+
+ /* Adapter setup */
+ Status = NICPowerOn(Adapter);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unable to power on NIC (0x%x)\n", Status));
+ goto Cleanup;
+ }
+
+ Status = NICSoftReset(Adapter);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unable to reset the NIC (0x%x)\n",
Status));
+ goto Cleanup;
+ }
+
+ Status = NICGetPermanentMacAddress(Adapter, Adapter->PermanentMacAddress);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unable to get the fixed MAC address
(0x%x)\n", Status));
+ goto Cleanup;
+ }
+
+ RtlCopyMemory(Adapter->CurrentMacAddress, Adapter->PermanentMacAddress,
IEEE_802_ADDR_LENGTH);
+
+ /* Update link state and speed */
+ NICUpdateLinkStatus(Adapter);
+
+ /* We're ready to handle interrupts now */
+ Status = NICRegisterInterrupts(Adapter);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unable to register interrupt (0x%x)\n",
Status));
+ goto Cleanup;
+ }
+
+ /* Enable interrupts on the NIC */
+ //Adapter->InterruptMask = DEFAULT_INTERRUPT_MASK;
+ Status = NICApplyInterruptMask(Adapter);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unable to apply interrupt mask (0x%x)\n",
Status));
+ goto Cleanup;
+ }
+
+ /* Turn on TX and RX now */
+ Status = NICEnableTxRx(Adapter);
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Unable to enable TX and RX (0x%x)\n",
Status));
+ goto Cleanup;
+ }
+
+ return NDIS_STATUS_SUCCESS;
+
+Cleanup:
+ if (ResourceList != NULL)
+ {
+ NdisFreeMemory(ResourceList, ResourceListSize, 0);
+ }
+ if (Adapter != NULL)
+ {
+ MiniportHalt(Adapter);
+ }
+
+ return Status;
+}
+
+NTSTATUS
+NTAPI
+DriverEntry(
+ IN PDRIVER_OBJECT DriverObject,
+ IN PUNICODE_STRING RegistryPath)
+{
+ NDIS_HANDLE WrapperHandle;
+ NDIS_MINIPORT_CHARACTERISTICS Characteristics = { 0 };
+ NDIS_STATUS Status;
+
+ Characteristics.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
+ Characteristics.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;
+ Characteristics.CheckForHangHandler = NULL;
+ Characteristics.DisableInterruptHandler = NULL;
+ Characteristics.EnableInterruptHandler = NULL;
+ Characteristics.HaltHandler = MiniportHalt;
+ Characteristics.HandleInterruptHandler = MiniportHandleInterrupt;
+ Characteristics.InitializeHandler = MiniportInitialize;
+ Characteristics.ISRHandler = MiniportISR;
+ Characteristics.QueryInformationHandler = MiniportQueryInformation;
+ Characteristics.ReconfigureHandler = NULL;
+ Characteristics.ResetHandler = MiniportReset;
+ Characteristics.SendHandler = MiniportSend;
+ Characteristics.SetInformationHandler = MiniportSetInformation;
+ Characteristics.TransferDataHandler = NULL;
+ Characteristics.ReturnPacketHandler = NULL;
+ Characteristics.SendPacketsHandler = NULL;
+ Characteristics.AllocateCompleteHandler = NULL;
+
+ NdisMInitializeWrapper(&WrapperHandle, DriverObject, RegistryPath, NULL);
+ if (!WrapperHandle)
+ {
+ return NDIS_STATUS_FAILURE;
+ }
+
+ Status = NdisMRegisterMiniport(WrapperHandle, &Characteristics,
sizeof(Characteristics));
+ if (Status != NDIS_STATUS_SUCCESS)
+ {
+ NdisTerminateWrapper(WrapperHandle, 0);
+ return NDIS_STATUS_FAILURE;
+ }
+
+ return NDIS_STATUS_SUCCESS;
+}
diff --git a/drivers/network/dd/e1000/nic.h b/drivers/network/dd/e1000/nic.h
new file mode 100644
index 0000000000..ea6922ed17
--- /dev/null
+++ b/drivers/network/dd/e1000/nic.h
@@ -0,0 +1,171 @@
+/*
+ * PROJECT: ReactOS Intel PRO/1000 Driver
+ * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Intel PRO/1000 driver definitions
+ * COPYRIGHT: Copyright 2013 Cameron Gutman (cameron.gutman(a)reactos.org)
+ * Copyright 2018 Mark Jansen (mark.jansen(a)reactos.org)
+ */
+
+#ifndef _E1000_PCH_
+#define _E1000_PCH_
+
+#include <ndis.h>
+
+#include "e1000hw.h"
+
+#define E1000_TAG '001e'
+
+#define MAXIMUM_FRAME_SIZE 1522
+#define RECEIVE_BUFFER_SIZE 2048
+
+#define DRIVER_VERSION 1
+
+
+typedef struct _E1000_ADAPTER
+{
+ NDIS_SPIN_LOCK Lock;
+ NDIS_HANDLE AdapterHandle;
+ USHORT VendorID;
+ USHORT DeviceID;
+ USHORT SubsystemID;
+ USHORT SubsystemVendorID;
+
+ UCHAR PermanentMacAddress[IEEE_802_ADDR_LENGTH];
+ UCHAR CurrentMacAddress[IEEE_802_ADDR_LENGTH];
+
+ ULONG LinkSpeedMbps;
+ ULONG MediaState;
+ ULONG InterruptPending;
+
+} E1000_ADAPTER, *PE1000_ADAPTER;
+
+
+BOOLEAN
+NTAPI
+NICRecognizeHardware(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICInitializeAdapterResources(
+ IN PE1000_ADAPTER Adapter,
+ IN PNDIS_RESOURCE_LIST ResourceList);
+
+NDIS_STATUS
+NTAPI
+NICAllocateResources(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICRegisterInterrupts(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICUnregisterInterrupts(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICReleaseIoResources(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICPowerOn(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICSoftReset(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICEnableTxRx(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICDisableTxRx(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICGetPermanentMacAddress(
+ IN PE1000_ADAPTER Adapter,
+ OUT PUCHAR MacAddress);
+
+NDIS_STATUS
+NTAPI
+NICApplyPacketFilter(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICApplyInterruptMask(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICDisableInterrupts(
+ IN PE1000_ADAPTER Adapter);
+
+USHORT
+NTAPI
+NICInterruptRecognized(
+ IN PE1000_ADAPTER Adapter,
+ OUT PBOOLEAN InterruptRecognized);
+
+VOID
+NTAPI
+NICAcknowledgeInterrupts(
+ IN PE1000_ADAPTER Adapter);
+
+VOID
+NTAPI
+NICUpdateLinkStatus(
+ IN PE1000_ADAPTER Adapter);
+
+NDIS_STATUS
+NTAPI
+NICTransmitPacket(
+ IN PE1000_ADAPTER Adapter,
+ IN UCHAR TxDesc,
+ IN ULONG PhysicalAddress,
+ IN ULONG Length);
+
+NDIS_STATUS
+NTAPI
+MiniportSetInformation(
+ IN NDIS_HANDLE MiniportAdapterContext,
+ IN NDIS_OID Oid,
+ IN PVOID InformationBuffer,
+ IN ULONG InformationBufferLength,
+ OUT PULONG BytesRead,
+ OUT PULONG BytesNeeded);
+
+NDIS_STATUS
+NTAPI
+MiniportQueryInformation(
+ IN NDIS_HANDLE MiniportAdapterContext,
+ IN NDIS_OID Oid,
+ IN PVOID InformationBuffer,
+ IN ULONG InformationBufferLength,
+ OUT PULONG BytesWritten,
+ OUT PULONG BytesNeeded);
+
+VOID
+NTAPI
+MiniportISR(
+ OUT PBOOLEAN InterruptRecognized,
+ OUT PBOOLEAN QueueMiniportHandleInterrupt,
+ IN NDIS_HANDLE MiniportAdapterContext);
+
+VOID
+NTAPI
+MiniportHandleInterrupt(
+ IN NDIS_HANDLE MiniportAdapterContext);
+
+#endif /* _E1000_PCH_ */
diff --git a/media/inf/CMakeLists.txt b/media/inf/CMakeLists.txt
index d84ffff539..8080d1ec91 100644
--- a/media/inf/CMakeLists.txt
+++ b/media/inf/CMakeLists.txt
@@ -25,6 +25,7 @@ list(APPEND INF_FILES
msmouse.inf
NET_NIC.inf
netamd.inf
+ nete1000.inf
netisa.inf
netrtl.inf
netrtpnt.inf
diff --git a/media/inf/nete1000.inf b/media/inf/nete1000.inf
new file mode 100644
index 0000000000..ed47b46926
--- /dev/null
+++ b/media/inf/nete1000.inf
@@ -0,0 +1,50 @@
+; NETRTL.INF
+
+; Installation file for Intel-based NICs
+
+[Version]
+Signature = "$Windows NT$"
+;Signature = "$ReactOS$"
+LayoutFile = layout.inf
+Class = Net
+ClassGUID = {4D36E972-E325-11CE-BFC1-08002BE10318}
+Provider = %ReactOS%
+DriverVer = 18/05/2018,1.00
+
+[DestinationDirs]
+DefaultDestDir = 12
+
+[Manufacturer]
+%IntelMfg% = IntelMfg
+
+[IntelMfg]
+%IntelE1000.DeviceDesc% = E1000_Inst.ndi,PCI\VEN_8086&DEV_100F
+
+;----------------------------- E1000 DRIVER -----------------------------
+
+[E1000_Inst.ndi.NT]
+Characteristics = 0x4 ; NCF_PHYSICAL
+BusType = 5 ; PCIBus
+CopyFiles = E1000_CopyFiles.NT
+
+[E1000_CopyFiles.NT]
+e1000.sys
+
+[E1000_Inst.ndi.NT.Services]
+AddService = e1000, 0x00000002, E1000_Service_Inst
+
+[E1000_Service_Inst]
+ServiceType = 1
+StartType = 3
+ErrorControl = 0
+ServiceBinary = %12%\e1000.sys
+LoadOrderGroup = NDIS
+
+;-------------------------------- STRINGS -------------------------------
+
+[Strings]
+ReactOS = "ReactOS Team"
+
+IntelMfg = "Intel"
+
+IntelE1000.DeviceDesc = "Intel PRO/1000 Ethernet Adapter"