ReactOS 0.4.16-dev-122-g325d74c
hardware.c File Reference
#include "nic.h"
#include <debug.h>
Include dependency graph for hardware.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NDIS_STATUS NTAPI NICPowerOn (IN PRTL_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICSoftReset (IN PRTL_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICRegisterReceiveBuffer (IN PRTL_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICRemoveReceiveBuffer (IN PRTL_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICEnableTxRx (IN PRTL_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICGetPermanentMacAddress (IN PRTL_ADAPTER Adapter, OUT PUCHAR MacAddress)
 
NDIS_STATUS NTAPI NICApplyInterruptMask (IN PRTL_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICDisableInterrupts (IN PRTL_ADAPTER Adapter)
 
USHORT NTAPI NICInterruptRecognized (IN PRTL_ADAPTER Adapter, OUT PBOOLEAN InterruptRecognized)
 
VOID NTAPI NICAcknowledgeInterrupts (IN PRTL_ADAPTER Adapter)
 
VOID NTAPI NICUpdateLinkStatus (IN PRTL_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICApplyPacketFilter (IN PRTL_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICTransmitPacket (IN PRTL_ADAPTER Adapter, IN UCHAR TxDesc, IN ULONG PhysicalAddress, IN ULONG Length)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file hardware.c.

Function Documentation

◆ NICAcknowledgeInterrupts()

VOID NTAPI NICAcknowledgeInterrupts ( IN PRTL_ADAPTER  Adapter)

Definition at line 167 of file hardware.c.

170{
171 NdisRawWritePortUshort(Adapter->IoBase + R_IS, Adapter->InterruptPending);
172}
#define NdisRawWritePortUshort(Port, Data)
Definition: ndis.h:4248
#define R_IS
Definition: rtlhw.h:54

Referenced by MiniportISR().

◆ NICApplyInterruptMask()

NDIS_STATUS NTAPI NICApplyInterruptMask ( IN PRTL_ADAPTER  Adapter)

Definition at line 131 of file hardware.c.

134{
135 NdisRawWritePortUshort(Adapter->IoBase + R_IM, Adapter->InterruptMask);
136 return NDIS_STATUS_SUCCESS;
137}
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define R_IM
Definition: rtlhw.h:53

◆ NICApplyPacketFilter()

NDIS_STATUS NTAPI NICApplyPacketFilter ( IN PRTL_ADAPTER  Adapter)

Definition at line 190 of file hardware.c.

193{
194 ULONG filterMask;
195
196 filterMask = RC_VAL;
197
198 if (Adapter->PacketFilter & NDIS_PACKET_TYPE_DIRECTED)
199 {
200 filterMask |= B_RC_APM;
201 }
202
203 if (Adapter->PacketFilter & NDIS_PACKET_TYPE_MULTICAST)
204 {
205 filterMask |= B_RC_AM;
206 }
207
208 if (Adapter->PacketFilter & NDIS_PACKET_TYPE_BROADCAST)
209 {
210 filterMask |= B_RC_AB;
211 }
212
213 if (Adapter->PacketFilter & NDIS_PACKET_TYPE_PROMISCUOUS)
214 {
215 filterMask |= B_RC_AAP;
216 }
217
218 NdisRawWritePortUlong(Adapter->IoBase + R_RC, filterMask);
219
220 return NDIS_STATUS_SUCCESS;
221}
#define NDIS_PACKET_TYPE_PROMISCUOUS
Definition: ndis.h:668
#define NDIS_PACKET_TYPE_BROADCAST
Definition: ndis.h:666
#define NdisRawWritePortUlong(Port, Data)
Definition: ndis.h:4239
#define NDIS_PACKET_TYPE_MULTICAST
Definition: ndis.h:664
#define NDIS_PACKET_TYPE_DIRECTED
Definition: ndis.h:663
#define RC_VAL
Definition: nic.h:31
#define B_RC_APM
Definition: rtlhw.h:69
#define B_RC_AAP
Definition: rtlhw.h:68
#define R_RC
Definition: rtlhw.h:67
#define B_RC_AM
Definition: rtlhw.h:70
#define B_RC_AB
Definition: rtlhw.h:71
uint32_t ULONG
Definition: typedefs.h:59

◆ NICDisableInterrupts()

NDIS_STATUS NTAPI NICDisableInterrupts ( IN PRTL_ADAPTER  Adapter)

Definition at line 141 of file hardware.c.

144{
145 NdisRawWritePortUshort(Adapter->IoBase + R_IM, 0);
146 return NDIS_STATUS_SUCCESS;
147}

◆ NICEnableTxRx()

NDIS_STATUS NTAPI NICEnableTxRx ( IN PRTL_ADAPTER  Adapter)

Definition at line 98 of file hardware.c.

101{
102 NdisRawWritePortUchar(Adapter->IoBase + R_CMD, B_CMD_TXE | B_CMD_RXE);
103
104 //
105 // TX and RX must be enabled before setting these
106 //
107 NdisRawWritePortUlong(Adapter->IoBase + R_RC, RC_VAL);
108 NdisRawWritePortUlong(Adapter->IoBase + R_TC, TC_VAL);
109 return NDIS_STATUS_SUCCESS;
110}
#define NdisRawWritePortUchar(Port, Data)
Definition: ndis.h:4230
#define TC_VAL
Definition: nic.h:34
#define B_CMD_TXE
Definition: rtlhw.h:47
#define B_CMD_RXE
Definition: rtlhw.h:48
#define R_TC
Definition: rtlhw.h:55
#define R_CMD
Definition: rtlhw.h:45

◆ NICGetPermanentMacAddress()

NDIS_STATUS NTAPI NICGetPermanentMacAddress ( IN PRTL_ADAPTER  Adapter,
OUT PUCHAR  MacAddress 
)

Definition at line 114 of file hardware.c.

118{
119 UINT i;
120
121 for (i = 0; i < IEEE_802_ADDR_LENGTH; i++)
122 {
123 NdisRawReadPortUchar(Adapter->IoBase + R_MAC + i, &MacAddress[i]);
124 }
125
126 return NDIS_STATUS_SUCCESS;
127}
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
#define NdisRawReadPortUchar(Port, Data)
Definition: ndis.h:4173
#define R_MAC
Definition: rtlhw.h:17

◆ NICInterruptRecognized()

USHORT NTAPI NICInterruptRecognized ( IN PRTL_ADAPTER  Adapter,
OUT PBOOLEAN  InterruptRecognized 
)

Definition at line 151 of file hardware.c.

155{
156 USHORT interruptStatus;
157
158 NdisRawReadPortUshort(Adapter->IoBase + R_IS, &interruptStatus);
159
160 *InterruptRecognized = (interruptStatus & Adapter->InterruptMask) != 0;
161
162 return (interruptStatus & Adapter->InterruptMask);
163}
#define NdisRawReadPortUshort(Port, Data)
Definition: ndis.h:4191
unsigned short USHORT
Definition: pedump.c:61

Referenced by MiniportISR().

◆ NICPowerOn()

NDIS_STATUS NTAPI NICPowerOn ( IN PRTL_ADAPTER  Adapter)

Definition at line 29 of file hardware.c.

32{
33 //
34 // Send 0x00 to the CONFIG_1 register (0x52) to set the LWAKE + LWPTN to active high.
35 // This should essentially *power on* the device.
36 // -- OSDev Wiki
37 //
38 NdisRawWritePortUchar(Adapter->IoBase + R_CFG1, 0x00);
40}
#define R_CFG1
Definition: rtlhw.h:78

◆ NICRegisterReceiveBuffer()

NDIS_STATUS NTAPI NICRegisterReceiveBuffer ( IN PRTL_ADAPTER  Adapter)

Definition at line 75 of file hardware.c.

78{
79 ASSERT(NdisGetPhysicalAddressHigh(Adapter->ReceiveBufferPa) == 0);
80
81 NdisRawWritePortUlong(Adapter->IoBase + R_RXSA, Adapter->ReceiveBufferPa.LowPart);
82
84}
#define ASSERT(a)
Definition: mode.c:44
#define NdisGetPhysicalAddressHigh(PhysicalAddress)
Definition: ndis.h:3830
#define R_RXSA
Definition: rtlhw.h:34

Referenced by MiniportInitialize().

◆ NICRemoveReceiveBuffer()

NDIS_STATUS NTAPI NICRemoveReceiveBuffer ( IN PRTL_ADAPTER  Adapter)

Definition at line 88 of file hardware.c.

91{
92 NdisRawWritePortUlong(Adapter->IoBase + R_RXSA, 0);
94}

Referenced by MiniportHalt().

◆ NICSoftReset()

NDIS_STATUS NTAPI NICSoftReset ( IN PRTL_ADAPTER  Adapter)

Definition at line 44 of file hardware.c.

47{
48 UCHAR commandReg;
49 UINT resetAttempts;
50
51 //
52 // Sending 0x10 to the Command register (0x37) will send the RTL8139 into a software reset.
53 // Once that byte is sent, the RST bit must be checked to make sure that the chip has finished the reset.
54 // If the RST bit is high (1), then the reset is still in operation.
55 // -- OSDev Wiki
56 NdisRawWritePortUchar(Adapter->IoBase + R_CMD, B_CMD_RST);
57
58 for (resetAttempts = 0; resetAttempts < MAX_RESET_ATTEMPTS; resetAttempts++)
59 {
60 NdisRawReadPortUchar(Adapter->IoBase + R_CMD, &commandReg);
61
62 if (!(commandReg & B_CMD_RST))
63 {
65 }
66
67 NdisMSleep(100);
68 }
69
71}
#define MAX_RESET_ATTEMPTS
Definition: e1000hw.h:15
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
VOID EXPORT NdisMSleep(IN ULONG MicrosecondsToSleep)
Definition: miniport.c:2928
#define B_CMD_RST
Definition: rtlhw.h:49
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ NICTransmitPacket()

NDIS_STATUS NTAPI NICTransmitPacket ( IN PRTL_ADAPTER  Adapter,
IN UCHAR  TxDesc,
IN ULONG  PhysicalAddress,
IN ULONG  Length 
)

Definition at line 225 of file hardware.c.

231{
232 NdisRawWritePortUlong(Adapter->IoBase + R_TXSAD0 + (TxDesc * sizeof(ULONG)), PhysicalAddress);
233 NdisRawWritePortUlong(Adapter->IoBase + R_TXSTS0 + (TxDesc * sizeof(ULONG)), Length);
234 return NDIS_STATUS_SUCCESS;
235}
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define R_TXSAD0
Definition: rtlhw.h:30
#define R_TXSTS0
Definition: rtlhw.h:26
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098

◆ NICUpdateLinkStatus()

VOID NTAPI NICUpdateLinkStatus ( IN PRTL_ADAPTER  Adapter)

Definition at line 176 of file hardware.c.

179{
180 UCHAR mediaState;
181
182 NdisRawReadPortUchar(Adapter->IoBase + R_MS, &mediaState);
183 Adapter->MediaState = (mediaState & R_MS_LINKDWN) ? NdisMediaStateDisconnected :
185 Adapter->LinkSpeedMbps = (mediaState & R_MS_SPEED_10) ? 10 : 100;
186}
@ NdisMediaStateConnected
Definition: ntddndis.h:470
@ NdisMediaStateDisconnected
Definition: ntddndis.h:471
#define R_MS_LINKDWN
Definition: rtlhw.h:82
#define R_MS_SPEED_10
Definition: rtlhw.h:83
#define R_MS
Definition: rtlhw.h:80