ReactOS 0.4.15-dev-7928-g68a8619
hardware.c
Go to the documentation of this file.
1/*
2 * ReactOS Realtek 8139 Driver
3 *
4 * Copyright (C) 2013 Cameron Gutman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include "nic.h"
23
24#define NDEBUG
25#include <debug.h>
26
30 IN PRTL_ADAPTER Adapter
31 )
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}
41
45 IN PRTL_ADAPTER Adapter
46 )
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}
72
76 IN PRTL_ADAPTER Adapter
77 )
78{
79 ASSERT(NdisGetPhysicalAddressHigh(Adapter->ReceiveBufferPa) == 0);
80
81 NdisRawWritePortUlong(Adapter->IoBase + R_RXSA, Adapter->ReceiveBufferPa.LowPart);
82
84}
85
89 IN PRTL_ADAPTER Adapter
90 )
91{
92 NdisRawWritePortUlong(Adapter->IoBase + R_RXSA, 0);
94}
95
99 IN PRTL_ADAPTER Adapter
100 )
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}
111
113NTAPI
115 IN PRTL_ADAPTER Adapter,
116 OUT PUCHAR MacAddress
117 )
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}
128
130NTAPI
132 IN PRTL_ADAPTER Adapter
133 )
134{
135 NdisRawWritePortUshort(Adapter->IoBase + R_IM, Adapter->InterruptMask);
136 return NDIS_STATUS_SUCCESS;
137}
138
140NTAPI
142 IN PRTL_ADAPTER Adapter
143 )
144{
145 NdisRawWritePortUshort(Adapter->IoBase + R_IM, 0);
146 return NDIS_STATUS_SUCCESS;
147}
148
149USHORT
150NTAPI
152 IN PRTL_ADAPTER Adapter,
153 OUT PBOOLEAN InterruptRecognized
154 )
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}
164
165VOID
166NTAPI
168 IN PRTL_ADAPTER Adapter
169 )
170{
171 NdisRawWritePortUshort(Adapter->IoBase + R_IS, Adapter->InterruptPending);
172}
173
174VOID
175NTAPI
177 IN PRTL_ADAPTER Adapter
178 )
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}
187
189NTAPI
191 IN PRTL_ADAPTER Adapter
192 )
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}
222
224NTAPI
226 IN PRTL_ADAPTER Adapter,
227 IN UCHAR TxDesc,
230 )
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}
#define NICDisableInterrupts(Adapter)
Definition: 8390.h:159
NDIS_STATUS NTAPI NICPowerOn(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:509
NDIS_STATUS NTAPI NICEnableTxRx(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:574
NDIS_STATUS NTAPI NICSoftReset(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:531
NDIS_STATUS NTAPI NICGetPermanentMacAddress(IN PE1000_ADAPTER Adapter, OUT PUCHAR MacAddress)
Definition: hardware.c:661
NDIS_STATUS NTAPI NICApplyPacketFilter(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:724
VOID NTAPI NICUpdateLinkStatus(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:740
NDIS_STATUS NTAPI NICTransmitPacket(IN PRTL_ADAPTER Adapter, IN UCHAR TxDesc, IN ULONG PhysicalAddress, IN ULONG Length)
Definition: hardware.c:225
NDIS_STATUS NTAPI NICRemoveReceiveBuffer(IN PRTL_ADAPTER Adapter)
Definition: hardware.c:88
NDIS_STATUS NTAPI NICRegisterReceiveBuffer(IN PRTL_ADAPTER Adapter)
Definition: hardware.c:75
NDIS_STATUS NTAPI NICApplyInterruptMask(IN PRTL_ADAPTER Adapter)
Definition: hardware.c:131
VOID NTAPI NICAcknowledgeInterrupts(IN PRTL_ADAPTER Adapter)
Definition: hardware.c:167
USHORT NTAPI NICInterruptRecognized(IN PRTL_ADAPTER Adapter, OUT PBOOLEAN InterruptRecognized)
Definition: hardware.c:151
#define MAX_RESET_ATTEMPTS
Definition: e1000hw.h:15
#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
#define ASSERT(a)
Definition: mode.c:44
#define NdisRawReadPortUshort(Port, Data)
Definition: ndis.h:4191
#define NDIS_PACKET_TYPE_PROMISCUOUS
Definition: ndis.h:668
unsigned int UINT
Definition: ndis.h:50
#define NdisRawReadPortUchar(Port, Data)
Definition: ndis.h:4173
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
#define NDIS_PACKET_TYPE_BROADCAST
Definition: ndis.h:666
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#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 NdisRawWritePortUchar(Port, Data)
Definition: ndis.h:4230
#define NdisRawWritePortUshort(Port, Data)
Definition: ndis.h:4248
#define NdisGetPhysicalAddressHigh(PhysicalAddress)
Definition: ndis.h:3830
VOID EXPORT NdisMSleep(IN ULONG MicrosecondsToSleep)
Definition: miniport.c:2928
@ NdisMediaStateConnected
Definition: ntddndis.h:470
@ NdisMediaStateDisconnected
Definition: ntddndis.h:471
int NDIS_STATUS
Definition: ntddndis.h:475
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
unsigned short USHORT
Definition: pedump.c:61
#define TC_VAL
Definition: nic.h:34
#define RC_VAL
Definition: nic.h:31
#define R_IM
Definition: rtlhw.h:53
#define B_RC_APM
Definition: rtlhw.h:69
#define B_CMD_RST
Definition: rtlhw.h:49
#define R_TXSAD0
Definition: rtlhw.h:30
#define B_RC_AAP
Definition: rtlhw.h:68
#define R_IS
Definition: rtlhw.h:54
#define R_RXSA
Definition: rtlhw.h:34
#define R_MS_LINKDWN
Definition: rtlhw.h:82
#define R_RC
Definition: rtlhw.h:67
#define R_TXSTS0
Definition: rtlhw.h:26
#define B_RC_AM
Definition: rtlhw.h:70
#define B_CMD_TXE
Definition: rtlhw.h:47
#define B_RC_AB
Definition: rtlhw.h:71
#define R_CFG1
Definition: rtlhw.h:78
#define R_MS_SPEED_10
Definition: rtlhw.h:83
#define B_CMD_RXE
Definition: rtlhw.h:48
#define R_TC
Definition: rtlhw.h:55
#define R_CMD
Definition: rtlhw.h:45
#define R_MS
Definition: rtlhw.h:80
#define R_MAC
Definition: rtlhw.h:17
unsigned char * PBOOLEAN
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
unsigned char UCHAR
Definition: xmlstorage.h:181