ReactOS 0.4.15-dev-7924-g5949c20
8390.c File Reference
#include <ne2000.h>
Include dependency graph for 8390.c:

Go to the source code of this file.

Functions

static BOOLEAN ProbeAddressForNIC (ULONG_PTR address)
 
BOOLEAN NICCheck (PNIC_ADAPTER Adapter)
 
static BOOLEAN NICTestAddress (PNIC_ADAPTER Adapter, ULONG Address)
 
static BOOLEAN NICTestRAM (PNIC_ADAPTER Adapter)
 
static VOID NICSetPhysicalAddress (PNIC_ADAPTER Adapter)
 
static VOID NICSetMulticastAddressMask (PNIC_ADAPTER Adapter)
 
static BOOLEAN NICReadSAPROM (PNIC_ADAPTER Adapter)
 
NDIS_STATUS NICInitialize (PNIC_ADAPTER Adapter)
 
NDIS_STATUS NICSetup (PNIC_ADAPTER Adapter)
 
NDIS_STATUS NICStart (PNIC_ADAPTER Adapter)
 
NDIS_STATUS NICStop (PNIC_ADAPTER Adapter)
 
NDIS_STATUS NICReset (PNIC_ADAPTER Adapter)
 
static VOID NICStartTransmit (PNIC_ADAPTER Adapter)
 
static VOID NICSetBoundaryPage (PNIC_ADAPTER Adapter)
 
static VOID NICGetCurrentPage (PNIC_ADAPTER Adapter)
 
VOID NICUpdateCounters (PNIC_ADAPTER Adapter)
 
VOID NICReadDataAlign (PNIC_ADAPTER Adapter, PUSHORT Target, ULONG_PTR Source, USHORT Length)
 
VOID NICWriteDataAlign (PNIC_ADAPTER Adapter, ULONG_PTR Target, PUSHORT Source, USHORT Length)
 
VOID NICReadData (PNIC_ADAPTER Adapter, PUCHAR Target, ULONG_PTR Source, USHORT Length)
 
VOID NICWriteData (PNIC_ADAPTER Adapter, ULONG_PTR Target, PUCHAR Source, USHORT Length)
 
static VOID NICIndicatePacket (PNIC_ADAPTER Adapter)
 
static VOID NICReadPacket (PNIC_ADAPTER Adapter)
 
static VOID NICWritePacket (PNIC_ADAPTER Adapter)
 
static BOOLEAN NICPrepareForTransmit (PNIC_ADAPTER Adapter)
 
VOID NICTransmit (PNIC_ADAPTER Adapter)
 
static VOID HandleReceive (PNIC_ADAPTER Adapter)
 
static VOID HandleTransmit (PNIC_ADAPTER Adapter)
 
VOID NTAPI MiniportHandleInterrupt (IN NDIS_HANDLE MiniportAdapterContext)
 

Variables

ULONG_PTR ProbeAddressList [] = { 0x280, 0x300, 0x320, 0x340, 0x360, 0x380, 0 }
 

Function Documentation

◆ HandleReceive()

static VOID HandleReceive ( PNIC_ADAPTER  Adapter)
static

Definition at line 1146 of file 8390.c.

1155{
1156 UINT i;
1157 UCHAR Tmp;
1158 UINT PacketCount;
1159
1160 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1161
1162 Adapter->DoneIndicating = FALSE;
1163 PacketCount = 0;
1164
1165 NICGetCurrentPage(Adapter);
1166
1167 if (Adapter->BufferOverflow) {
1168
1169 NDIS_DbgPrint(MID_TRACE, ("Receive ring overflow.\n"));
1170
1171 /* Select page 0 and stop the NIC */
1173
1174 /* Clear RBCR0,RBCR1 - Remote Byte Count Registers */
1175 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR0, 0x00);
1176 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR1, 0x00);
1177
1178 /* Wait for ISR_RST to be set, but timeout after 2ms */
1179 for (i = 0; i < 4; i++) {
1180 NdisRawReadPortUchar(Adapter->IOBase + PG0_ISR, &Tmp);
1181 if (Tmp & ISR_RST)
1182 break;
1183
1184 NdisStallExecution(500);
1185 }
1186
1187#if DBG
1188 if (i == 4)
1189 NDIS_DbgPrint(MIN_TRACE, ("NIC was not reset after 2ms.\n"));
1190#endif
1191
1192 if ((Adapter->InterruptStatus & (ISR_PTX | ISR_TXE)) == 0) {
1193 /* We may need to restart the transmitter */
1194 Adapter->TransmitPending = TRUE;
1195 }
1196
1197 /* Initialize TCR - Transmit Configuration Register to loopback mode 1 */
1199
1200 /* Start NIC */
1202
1203 NICStart(Adapter);
1204
1205 Adapter->BufferOverflow = FALSE;
1206 }
1207
1208 if (Adapter->ReceiveError) {
1209 NDIS_DbgPrint(MID_TRACE, ("Receive error.\n"));
1210
1211 /* Skip this packet */
1212 Adapter->NextPacket = Adapter->CurrentPage;
1213 NICSetBoundaryPage(Adapter);
1214
1215 Adapter->ReceiveError = FALSE;
1216 }
1217
1218 for (;;) {
1219 NICGetCurrentPage(Adapter);
1220
1221 NDIS_DbgPrint(MID_TRACE, ("Current page (0x%X) NextPacket (0x%X).\n",
1222 Adapter->CurrentPage,
1223 Adapter->NextPacket));
1224
1225 if (Adapter->CurrentPage == Adapter->NextPacket) {
1226 NDIS_DbgPrint(MID_TRACE, ("No more packets.\n"));
1227 break;
1228 } else {
1229 NDIS_DbgPrint(MID_TRACE, ("Got a packet in the receive ring.\n"));
1230
1231 NDIS_DbgPrint(MAX_TRACE,("Adapter->MiniportAdapterHandle: %x\n",
1232 Adapter->MiniportAdapterHandle));
1233 /* Read packet from receive buffer ring */
1234 NICReadPacket(Adapter);
1235
1236 Adapter->DoneIndicating = TRUE;
1237
1238 PacketCount++;
1239 if (PacketCount == 10) {
1240 /* Don't starve transmit interrupts */
1241 break;
1242 }
1243 }
1244 }
1245
1246 if ((Adapter->TransmitPending) && (Adapter->TXCurrent != -1)) {
1247 NDIS_DbgPrint(MID_TRACE, ("Retransmitting current packet at (%d).\n", Adapter->TXCurrent));
1248 /* Retransmit packet */
1249 NICStartTransmit(Adapter);
1250 Adapter->TransmitPending = FALSE;
1251 }
1252
1253 if (Adapter->DoneIndicating)
1255}
static VOID NICReadPacket(PNIC_ADAPTER Adapter)
Definition: 8390.c:948
static VOID NICGetCurrentPage(PNIC_ADAPTER Adapter)
Definition: 8390.c:596
static VOID NICStartTransmit(PNIC_ADAPTER Adapter)
Definition: 8390.c:533
NDIS_STATUS NICStart(PNIC_ADAPTER Adapter)
Definition: 8390.c:429
static VOID NICSetBoundaryPage(PNIC_ADAPTER Adapter)
Definition: 8390.c:578
#define PG0_ISR
Definition: 8390.h:23
#define TCR_LOOP
Definition: 8390.h:111
#define PG0_TCR
Definition: 8390.h:33
#define ISR_TXE
Definition: 8390.h:76
#define CR_RD2
Definition: 8390.h:67
#define PG0_RBCR0
Definition: 8390.h:28
#define CR_PAGE0
Definition: 8390.h:68
#define ISR_PTX
Definition: 8390.h:74
#define CR_STA
Definition: 8390.h:63
#define ISR_RST
Definition: 8390.h:80
#define PG0_RBCR1
Definition: 8390.h:29
#define PG0_CR
Definition: 8390.h:11
#define CR_STP
Definition: 8390.h:62
#define MIN_TRACE
Definition: debug.h:14
#define MID_TRACE
Definition: debug.h:15
#define MAX_TRACE
Definition: debug.h:16
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
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 NdisMEthIndicateReceiveComplete(MiniportAdapterHandle)
Definition: ndis.h:5482
unsigned int UINT
Definition: ndis.h:50
#define NdisRawReadPortUchar(Port, Data)
Definition: ndis.h:4173
#define NdisStallExecution
Definition: ndis.h:4453
#define NdisRawWritePortUchar(Port, Data)
Definition: ndis.h:4230
BOOLEAN BufferOverflow
Definition: ne2000.h:139
UINT CurrentPage
Definition: ne2000.h:135
BOOLEAN ReceiveError
Definition: ne2000.h:142
PUCHAR IOBase
Definition: ne2000.h:92
UCHAR InterruptStatus
Definition: ne2000.h:123
UINT NextPacket
Definition: ne2000.h:136
BOOLEAN DoneIndicating
Definition: ne2000.h:157
BOOLEAN TransmitPending
Definition: ne2000.h:148
INT TXCurrent
Definition: ne2000.h:166
NDIS_HANDLE MiniportAdapterHandle
Definition: ne2000.h:80
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by MiniportHandleInterrupt().

◆ HandleTransmit()

static VOID HandleTransmit ( PNIC_ADAPTER  Adapter)
static

Definition at line 1258 of file 8390.c.

1265{
1266 UINT Length;
1267 UINT BufferCount;
1268
1269// PIP_PACKET pIPPacket;
1270// pIPPacket = (PIP_PACKET)
1271// DisplayIPPacket(pIPPacket);
1272
1273 if (Adapter->TransmitError) {
1274 /* FIXME: Retransmit now or let upper layer protocols handle retransmit? */
1275 Adapter->TransmitError = FALSE;
1276 }
1277
1278 /* Free transmit buffers */
1279 Length = Adapter->TXSize[Adapter->TXCurrent];
1280 BufferCount = (Length + DRIVER_BLOCK_SIZE - 1) / DRIVER_BLOCK_SIZE;
1281
1282 NDIS_DbgPrint(MID_TRACE, ("Freeing (%d) buffers at (%d).\n",
1283 BufferCount,
1284 Adapter->TXCurrent));
1285
1286 Adapter->TXFree += BufferCount;
1287 Adapter->TXSize[Adapter->TXCurrent] = 0;
1288 Adapter->TXCurrent = (Adapter->TXCurrent + BufferCount) % Adapter->TXCount;
1289
1290 if (Adapter->TXSize[Adapter->TXCurrent] == 0) {
1291 NDIS_DbgPrint(MID_TRACE, ("No more packets in transmit buffer.\n"));
1292
1293 Adapter->TXCurrent = -1;
1294 }
1295
1296 if (Adapter->TXQueueTail) {
1297 if (NICPrepareForTransmit(Adapter))
1298 NICStartTransmit(Adapter);
1299 }
1300}
static BOOLEAN NICPrepareForTransmit(PNIC_ADAPTER Adapter)
Definition: 8390.c:1064
if(dx< 0)
Definition: linetemp.h:194
#define DRIVER_BLOCK_SIZE
Definition: ne2000.h:50
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
UINT TXFree
Definition: ne2000.h:162
BOOLEAN TransmitError
Definition: ne2000.h:145
PNDIS_PACKET TXQueueTail
Definition: ne2000.h:171
UINT TXCount
Definition: ne2000.h:161
UINT TXSize[DRIVER_DEFAULT_TX_BUFFER_COUNT]
Definition: ne2000.h:165

Referenced by MiniportHandleInterrupt().

◆ MiniportHandleInterrupt()

VOID NTAPI MiniportHandleInterrupt ( IN NDIS_HANDLE  MiniportAdapterContext)

Definition at line 1303 of file 8390.c.

1313{
1314 UCHAR ISRValue;
1315 UCHAR ISRMask;
1316 UCHAR Mask;
1317 PNIC_ADAPTER Adapter = (PNIC_ADAPTER)MiniportAdapterContext;
1318 UINT i = 0;
1319
1320 ISRMask = Adapter->InterruptMask;
1321 NdisRawReadPortUchar(Adapter->IOBase + PG0_ISR, &ISRValue);
1322
1323 NDIS_DbgPrint(MID_TRACE, ("ISRValue (0x%X).\n", ISRValue));
1324
1325 Adapter->InterruptStatus |= (ISRValue & ISRMask);
1326
1327 Mask = 0x01;
1328 while (Adapter->InterruptStatus != 0x00 && i++ < INTERRUPT_LIMIT) {
1329
1330 if (ISRValue != 0x00) {
1331 /* Acknowledge interrupts */
1332 NdisRawWritePortUchar(Adapter->IOBase + PG0_ISR, ISRValue);
1333 Mask = 0x01;
1334 }
1335
1336 NDIS_DbgPrint(MID_TRACE, ("Adapter->InterruptStatus (0x%X) Mask (0x%X).\n",
1337 Adapter->InterruptStatus, Mask));
1338
1339 /* Find next interrupt type */
1340 while (((Adapter->InterruptStatus & Mask) == 0) && (Mask < ISRMask))
1341 Mask = (Mask << 1);
1342
1343 switch (Adapter->InterruptStatus & Mask) {
1344 case ISR_OVW:
1345 NDIS_DbgPrint(MID_TRACE, ("Overflow interrupt.\n"));
1346 /* Overflow. Handled almost the same way as a receive interrupt */
1347 Adapter->BufferOverflow = TRUE;
1348
1349 NDIS_DbgPrint(MAX_TRACE,("Adapter->MiniportAdapterHandle: %x\n",
1350 Adapter->MiniportAdapterHandle));
1351 if(Adapter->MiniportAdapterHandle)
1352 HandleReceive(Adapter);
1353 else
1354 NDIS_DbgPrint(MAX_TRACE,("No miniport adapter yet\n"));
1355
1356 Adapter->InterruptStatus &= ~ISR_OVW;
1357 break;
1358
1359 case ISR_RXE:
1360 NDIS_DbgPrint(MID_TRACE, ("Receive error interrupt.\n"));
1361 NICUpdateCounters(Adapter);
1362
1363 Adapter->ReceiveError = TRUE;
1364 break;
1365 case ISR_PRX:
1366 NDIS_DbgPrint(MID_TRACE, ("Receive interrupt.\n"));
1367
1368 NDIS_DbgPrint(MAX_TRACE,("Adapter->MiniportAdapterHandle: %x\n",
1369 Adapter->MiniportAdapterHandle));
1370 if(Adapter->MiniportAdapterHandle)
1371 HandleReceive(Adapter);
1372 else
1373 NDIS_DbgPrint(MAX_TRACE,("No miniport adapter yet\n"));
1374
1375 Adapter->InterruptStatus &= ~(ISR_PRX | ISR_RXE);
1376 break;
1377
1378 case ISR_TXE:
1379 NDIS_DbgPrint(MID_TRACE, ("Transmit error interrupt.\n"));
1380 NICUpdateCounters(Adapter);
1381
1382 Adapter->TransmitError = TRUE;
1383 break;
1384 case ISR_PTX:
1385 NDIS_DbgPrint(MID_TRACE, ("Transmit interrupt.\n"));
1386
1387 HandleTransmit(Adapter);
1388
1389 Adapter->InterruptStatus &= ~(ISR_PTX | ISR_TXE);
1390 break;
1391
1392 case ISR_CNT:
1393 NDIS_DbgPrint(MID_TRACE, ("Counter interrupt.\n"));
1394 /* Counter overflow. Read counters from the NIC */
1395 NICUpdateCounters(Adapter);
1396
1397 Adapter->InterruptStatus &= ~ISR_CNT;
1398 break;
1399
1400 default:
1401 NDIS_DbgPrint(MID_TRACE, ("Unknown interrupt. Adapter->InterruptStatus (0x%X).\n", Adapter->InterruptStatus));
1402 Adapter->InterruptStatus &= ~Mask;
1403 break;
1404 }
1405
1406 Mask = (Mask << 1);
1407
1408 /* Check if new interrupts are generated */
1409
1410 NdisRawReadPortUchar(Adapter->IOBase + PG0_ISR, &ISRValue);
1411
1412 NDIS_DbgPrint(MID_TRACE, ("ISRValue (0x%X).\n", ISRValue));
1413
1414 Adapter->InterruptStatus |= (ISRValue & ISRMask);
1415 }
1416
1417 NICEnableInterrupts((PNIC_ADAPTER)MiniportAdapterContext);
1418}
static VOID HandleTransmit(PNIC_ADAPTER Adapter)
Definition: 8390.c:1258
static VOID HandleReceive(PNIC_ADAPTER Adapter)
Definition: 8390.c:1146
VOID NICUpdateCounters(PNIC_ADAPTER Adapter)
Definition: 8390.c:619
#define ISR_RXE
Definition: 8390.h:75
#define NICEnableInterrupts(Adapter)
Definition: 8390.h:164
#define ISR_OVW
Definition: 8390.h:77
#define ISR_CNT
Definition: 8390.h:78
#define ISR_PRX
Definition: 8390.h:73
unsigned int Mask
Definition: fpcontrol.c:82
struct _NIC_ADAPTER * PNIC_ADAPTER
#define INTERRUPT_LIMIT
Definition: ne2000.h:61
ULONG InterruptMask
Definition: ne2000.h:120

◆ NICCheck()

BOOLEAN NICCheck ( PNIC_ADAPTER  Adapter)

Definition at line 53 of file 8390.c.

62{
63 int i;
64
65 NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
66
67 /* first try the supplied value */
69 {
70 NDIS_DbgPrint(MID_TRACE, ("Found adapter at 0x%x\n", Adapter->IoBaseAddress));
71 return TRUE;
72 }
73
74 /* ok, no dice, time to probe */
75 for(i = 0; ProbeAddressList[i]; i++)
76 {
78 {
79 NDIS_DbgPrint(MID_TRACE, ("Found adapter at address 0x%x\n", ProbeAddressList[i]));
81 return TRUE;
82 }
83 }
84
85 NDIS_DbgPrint(MIN_TRACE,("Adapter NOT found!\n"));
86 return FALSE;
87}
ULONG_PTR ProbeAddressList[]
Definition: 8390.c:14
static BOOLEAN ProbeAddressForNIC(ULONG_PTR address)
Definition: 8390.c:16
ULONG_PTR IoBaseAddress
Definition: ne2000.h:85

Referenced by MiniportInitialize().

◆ NICGetCurrentPage()

static VOID NICGetCurrentPage ( PNIC_ADAPTER  Adapter)
static

Definition at line 596 of file 8390.c.

603{
604 UCHAR Current;
605
606 /* Select page 1 */
608
609 /* Read current page */
610 NdisRawReadPortUchar(Adapter->IOBase + PG1_CURR, &Current);
611
612 /* Select page 0 */
614
615 Adapter->CurrentPage = Current;
616}
#define CR_PAGE1
Definition: 8390.h:69
#define PG1_CURR
Definition: 8390.h:42

Referenced by HandleReceive().

◆ NICIndicatePacket()

static VOID NICIndicatePacket ( PNIC_ADAPTER  Adapter)
static

Definition at line 887 of file 8390.c.

894{
895 UINT IndicateLength;
896
897 IndicateLength = (Adapter->PacketHeader.PacketLength <
898 (Adapter->LookaheadSize + DRIVER_HEADER_SIZE))?
899 (Adapter->PacketHeader.PacketLength) :
901
902 /* Fill the lookahead buffer */
903 NICReadData(Adapter,
904 (PUCHAR)&Adapter->Lookahead,
905 Adapter->PacketOffset + sizeof(PACKET_HEADER),
906 IndicateLength + DRIVER_HEADER_SIZE);
907
908 NDIS_DbgPrint(MID_TRACE, ("Indicating (%d) bytes.\n", IndicateLength));
909 NDIS_DbgPrint(MID_TRACE, ("ne2000!NICIndicatePacket: Indicating (%d) bytes.\n", IndicateLength));
910
911#if 0
912 NDIS_DbgPrint(MAX_TRACE, ("FRAME:\n"));
913 for (i = 0; i < (IndicateLength + 7) / 8; i++) {
914 NDIS_DbgPrint(MAX_TRACE, ("%02X %02X %02X %02X %02X %02X %02X %02X\n",
915 Adapter->Lookahead[i*8+0],
916 Adapter->Lookahead[i*8+1],
917 Adapter->Lookahead[i*8+2],
918 Adapter->Lookahead[i*8+3],
919 Adapter->Lookahead[i*8+4],
920 Adapter->Lookahead[i*8+5],
921 Adapter->Lookahead[i*8+6],
922 Adapter->Lookahead[i*8+7]));
923 }
924#endif
925
926 if (IndicateLength >= DRIVER_HEADER_SIZE) {
927 NDIS_DbgPrint(MAX_TRACE,("Adapter->MiniportAdapterHandle: %x\n",
928 Adapter->MiniportAdapterHandle));
930 NULL,
931 (PVOID)&Adapter->Lookahead,
934 IndicateLength - DRIVER_HEADER_SIZE,
936 } else {
938 NULL,
939 (PVOID)&Adapter->Lookahead,
940 IndicateLength,
941 NULL,
942 0,
943 0);
944 }
945}
VOID NICReadData(PNIC_ADAPTER Adapter, PUCHAR Target, ULONG_PTR Source, USHORT Length)
Definition: 8390.c:791
#define NULL
Definition: types.h:112
#define NdisMEthIndicateReceive(MiniportAdapterHandle, MiniportReceiveContext, HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize, PacketSize)
Definition: ndis.h:5458
#define DRIVER_HEADER_SIZE
Definition: ne2000.h:43
PACKET_HEADER PacketHeader
Definition: ne2000.h:151
UCHAR Lookahead[DRIVER_MAXIMUM_LOOKAHEAD+DRIVER_HEADER_SIZE]
Definition: ne2000.h:130
ULONG PacketOffset
Definition: ne2000.h:154
UINT LookaheadSize
Definition: ne2000.h:129
USHORT PacketLength
Definition: 8390.h:142
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by NICReadPacket().

◆ NICInitialize()

NDIS_STATUS NICInitialize ( PNIC_ADAPTER  Adapter)

Definition at line 289 of file 8390.c.

300{
301 UCHAR Tmp;
302
303 NDIS_DbgPrint(MID_TRACE, ("Called.\n"));
304
305 /* Reset the NIC */
306 NdisRawReadPortUchar(Adapter->IOBase + NIC_RESET, &Tmp);
307
308 /* Wait for 1.6ms */
309 NdisStallExecution(1600);
310
311 /* Write the value back */
312 NdisRawWritePortUchar(Adapter->IOBase + NIC_RESET, Tmp);
313
314 /* Select page 0 and stop NIC */
316
317 /* Initialize DCR - Data Configuration Register (byte mode/8 bytes FIFO) */
319
320 /* Clear RBCR0 and RBCR1 - Remote Byte Count Registers */
321 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR0, 0x00);
322 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR1, 0x00);
323
324 /* Initialize RCR - Receive Configuration Register (monitor mode) */
326
327 /* Enter loopback mode (internal NIC module loopback) */
329
330 /* Read the Station Address PROM */
331 if (!NICReadSAPROM(Adapter))
333
334 NDIS_DbgPrint(MID_TRACE, ("Station address is (%02X %02X %02X %02X %02X %02X).\n",
335 Adapter->StationAddress[0], Adapter->StationAddress[1],
336 Adapter->StationAddress[2], Adapter->StationAddress[3],
337 Adapter->StationAddress[4], Adapter->StationAddress[5]));
338
339 /* Select page 0 and start NIC */
341
342 /* Clear ISR - Interrupt Status Register */
343 NdisRawWritePortUchar(Adapter->IOBase + PG0_ISR, 0xFF);
344
345 /* Find NIC RAM size */
346 NICTestRAM(Adapter);
347
348 return NDIS_STATUS_SUCCESS;
349}
static BOOLEAN NICTestRAM(PNIC_ADAPTER Adapter)
Definition: 8390.c:120
static BOOLEAN NICReadSAPROM(PNIC_ADAPTER Adapter)
Definition: 8390.c:215
#define DCR_FT10
Definition: 8390.h:124
#define DCR_LS
Definition: 8390.h:120
#define PG0_RCR
Definition: 8390.h:31
#define PG0_DCR
Definition: 8390.h:35
#define RCR_MON
Definition: 8390.h:97
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define NDIS_STATUS_ADAPTER_NOT_FOUND
Definition: ndis.h:470
#define NIC_RESET
Definition: ne2000.h:24
DRIVER_HARDWARE_ADDRESS StationAddress
Definition: ne2000.h:108

Referenced by MiniportInitialize().

◆ NICPrepareForTransmit()

static BOOLEAN NICPrepareForTransmit ( PNIC_ADAPTER  Adapter)
static

Definition at line 1064 of file 8390.c.

1075{
1076 UINT Length;
1077 UINT BufferCount;
1079
1080 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1081
1082 /* Calculate number of buffers needed to transmit packet */
1084 NULL,
1085 NULL,
1086 NULL,
1087 &Length);
1088
1089 BufferCount = (Length + DRIVER_BLOCK_SIZE - 1) / DRIVER_BLOCK_SIZE;
1090
1091 if (BufferCount > Adapter->TXFree) {
1092 NDIS_DbgPrint(MID_TRACE, ("No transmit resources. Have (%d) buffers, need (%d).\n",
1093 Adapter->TXFree, BufferCount));
1094 /* We don't have the resources to transmit this packet right now */
1095 return FALSE;
1096 }
1097
1098 /* Write the packet to the card */
1099 NICWritePacket(Adapter);
1100
1101 /* If the NIC is not transmitting, reset the current transmit pointer */
1102 if (Adapter->TXCurrent == -1)
1103 Adapter->TXCurrent = Adapter->TXNext;
1104
1105 Adapter->TXNext = (Adapter->TXNext + BufferCount) % Adapter->TXCount;
1106 Adapter->TXFree -= BufferCount;
1107
1108 /* Remove the packet from the queue */
1109 Packet = Adapter->TXQueueHead;
1110 Adapter->TXQueueHead = RESERVED(Packet)->Next;
1111
1112 if (Packet == Adapter->TXQueueTail)
1113 Adapter->TXQueueTail = NULL;
1114
1115 /* Assume the transmit went well */
1117 Packet,
1119
1120 return TRUE;
1121}
static VOID NICWritePacket(PNIC_ADAPTER Adapter)
Definition: 8390.c:995
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
#define NdisMSendComplete(MiniportAdapterHandle, Packet, Status)
Definition: ndis.h:5689
#define RESERVED(Packet)
Definition: ne2000.h:70
PNDIS_PACKET TXQueueHead
Definition: ne2000.h:169
UINT TXNext
Definition: ne2000.h:163

Referenced by HandleTransmit(), and NICTransmit().

◆ NICReadData()

VOID NICReadData ( PNIC_ADAPTER  Adapter,
PUCHAR  Target,
ULONG_PTR  Source,
USHORT  Length 
)

Definition at line 791 of file 8390.c.

804{
805 USHORT Tmp;
806
807 /* Avoid transfers to odd addresses */
808 if (Source & 0x01) {
809 /* Transfer one word and use the MSB */
810 NICReadDataAlign(Adapter, &Tmp, Source - 1, 0x02);
811 *Target = (UCHAR)(Tmp >> 8);
812 Source++;
813 Target++;
814 Length--;
815 }
816
817 if (Length & 0x01) {
818 /* Transfer as many words as we can without exceeding the buffer length */
819 Tmp = Length & 0xFFFE;
820 NICReadDataAlign(Adapter, (PUSHORT)Target, Source, Tmp);
821 Source += Tmp;
822 Target = (PUCHAR)((ULONG_PTR) Target + Tmp);
823
824 /* Read one word and keep the LSB */
825 NICReadDataAlign(Adapter, &Tmp, Source, 0x02);
826 *Target = (UCHAR)(Tmp & 0x00FF);
827 } else
828 /* Transfer the rest of the data */
830}
VOID NICReadDataAlign(PNIC_ADAPTER Adapter, PUSHORT Target, ULONG_PTR Source, USHORT Length)
Definition: 8390.c:642
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
unsigned short USHORT
Definition: pedump.c:61
uint16_t * PUSHORT
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306

Referenced by MiniportTransferData(), NICIndicatePacket(), and NICReadPacket().

◆ NICReadDataAlign()

VOID NICReadDataAlign ( PNIC_ADAPTER  Adapter,
PUSHORT  Target,
ULONG_PTR  Source,
USHORT  Length 
)

Definition at line 642 of file 8390.c.

655{
656 UCHAR Tmp;
658
659 Count = Length;
660
661 /* Select page 0 and start the NIC */
663
664 /* Initialize RSAR0 and RSAR1 - Remote Start Address Registers */
665 NdisRawWritePortUchar(Adapter->IOBase + PG0_RSAR0, (UCHAR)(Source & 0xFF));
667
668 /* Initialize RBCR0 and RBCR1 - Remote Byte Count Registers */
669 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR0, (UCHAR)(Count & 0xFF));
670 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR1, (UCHAR)(Count >> 8));
671
672 /* Select page 0, read and start the NIC */
674
675 if (Adapter->WordMode)
677 else
679
680 /* Wait for remote DMA to complete, but timeout after some time */
681 for (Count = 0; Count < 0xFFFF; Count++) {
682 NdisRawReadPortUchar(Adapter->IOBase + PG0_ISR, &Tmp);
683 if (Tmp & ISR_RDC)
684 break;
685
687 }
688
689#if DBG
690 if (Count == 0xFFFF)
691 NDIS_DbgPrint(MIN_TRACE, ("Remote DMA did not complete.\n"));
692#endif
693
694 /* Clear remote DMA bit in ISR - Interrupt Status Register */
696}
#define PG0_RSAR1
Definition: 8390.h:27
#define CR_RD0
Definition: 8390.h:65
#define ISR_RDC
Definition: 8390.h:79
#define PG0_RSAR0
Definition: 8390.h:25
#define NdisRawReadPortBufferUshort(Port, Buffer, Length)
Definition: ndis.h:4164
#define NdisRawReadPortBufferUchar(Port, Buffer, Length)
Definition: ndis.h:4144
#define NIC_DATA
Definition: ne2000.h:23
int Count
Definition: noreturn.cpp:7
BOOLEAN WordMode
Definition: ne2000.h:95

Referenced by NICReadData(), NICTestAddress(), and NICWriteData().

◆ NICReadPacket()

static VOID NICReadPacket ( PNIC_ADAPTER  Adapter)
static

Definition at line 948 of file 8390.c.

955{
956 BOOLEAN SkipPacket = FALSE;
957
958 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
959
960 /* Get the header of the next packet in the receive ring */
961 Adapter->PacketOffset = Adapter->NextPacket << 8;
962 NICReadData(Adapter,
963 (PUCHAR)&Adapter->PacketHeader,
964 Adapter->PacketOffset,
965 sizeof(PACKET_HEADER));
966
967 NDIS_DbgPrint(MAX_TRACE, ("HEADER: (Status) (0x%X)\n", Adapter->PacketHeader.Status));
968 NDIS_DbgPrint(MAX_TRACE, ("HEADER: (NextPacket) (0x%X)\n", Adapter->PacketHeader.NextPacket));
969 NDIS_DbgPrint(MAX_TRACE, ("HEADER: (PacketLength) (0x%X)\n", Adapter->PacketHeader.PacketLength));
970
971 if (Adapter->PacketHeader.PacketLength < 64 ||
972 Adapter->PacketHeader.PacketLength > 1518) { /* XXX I don't think the CRC will show up... should be 1514 */
973 NDIS_DbgPrint(MAX_TRACE, ("Bogus packet size (%d).\n",
974 Adapter->PacketHeader.PacketLength));
975 SkipPacket = TRUE;
976 }
977
978 if (SkipPacket) {
979 /* Skip packet */
980 Adapter->NextPacket = Adapter->CurrentPage;
981 } else {
982 NDIS_DbgPrint(MAX_TRACE,("Adapter->MiniportAdapterHandle: %x\n",
983 Adapter->MiniportAdapterHandle));
984 NICIndicatePacket(Adapter);
985
986 /* Go to the next free buffer in receive ring */
987 Adapter->NextPacket = Adapter->PacketHeader.NextPacket;
988 }
989
990 /* Update boundary page */
991 NICSetBoundaryPage(Adapter);
992}
static VOID NICIndicatePacket(PNIC_ADAPTER Adapter)
Definition: 8390.c:887
unsigned char BOOLEAN
UCHAR NextPacket
Definition: 8390.h:141
UCHAR Status
Definition: 8390.h:140

Referenced by HandleReceive().

◆ NICReadSAPROM()

static BOOLEAN NICReadSAPROM ( PNIC_ADAPTER  Adapter)
static

Definition at line 215 of file 8390.c.

229{
230 UINT i;
231 UCHAR Buffer[32];
232 UCHAR WordLength;
233
234 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
235
236 /* Read Station Address PROM (SAPROM) which is 16 bytes at remote DMA address 0.
237 Some cards double the data read which we must compensate for */
238
239 /* Initialize RBCR0 and RBCR1 - Remote Byte Count Registers */
240 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR0, 0x20);
241 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR1, 0x00);
242
243 /* Initialize RSAR0 and RSAR1 - Remote Start Address Registers */
244 NdisRawWritePortUchar(Adapter->IOBase + PG0_RSAR0, 0x00);
245 NdisRawWritePortUchar(Adapter->IOBase + PG0_RSAR1, 0x00);
246
247 /* Select page 0, read and start the NIC */
249
250 /* Read one byte at a time */
251 WordLength = 2; /* Assume a word is two bytes */
252 for (i = 0; i < 32; i += 2) {
254 NdisRawReadPortUchar(Adapter->IOBase + NIC_DATA, &Buffer[i + 1]);
255 if (Buffer[i] != Buffer[i + 1])
256 WordLength = 1; /* A word is one byte long */
257 }
258
259 /* If WordLength is 2 the data read before was doubled. We must compensate for this */
260 if (WordLength == 2) {
261 NDIS_DbgPrint(MAX_TRACE,("NE2000 or compatible network adapter found.\n"));
262
263 Adapter->WordMode = TRUE;
264
265 /* Move the SAPROM data to the adapter object */
266 for (i = 0; i < 16; i++)
267 Adapter->SAPROM[i] = Buffer[i * 2];
268
269 /* Copy the permanent address */
271 (PVOID)&Adapter->PermanentAddress,
272 (PVOID)&Adapter->SAPROM,
274
275 /* Initialize DCR - Data Configuration Register (word mode/4 words FIFO) */
277
278 return TRUE;
279 } else {
280 NDIS_DbgPrint(MAX_TRACE, ("NE1000 or compatible network adapter found.\n"));
281
282 Adapter->WordMode = FALSE;
283
284 return FALSE;
285 }
286}
#define DCR_WTS
Definition: 8390.h:117
Definition: bufpool.h:45
#define NdisMoveMemory(Destination, Source, Length)
Definition: ndis.h:3896
#define DRIVER_LENGTH_OF_ADDRESS
Definition: ne2000.h:44
UCHAR SAPROM[16]
Definition: ne2000.h:102
DRIVER_HARDWARE_ADDRESS PermanentAddress
Definition: ne2000.h:105

Referenced by NICInitialize().

◆ NICReset()

NDIS_STATUS NICReset ( PNIC_ADAPTER  Adapter)

Definition at line 500 of file 8390.c.

509{
510 UCHAR Tmp;
511
512 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
513
514 /* Stop the NIC */
515 NICStop(Adapter);
516
517 /* Reset the NIC */
518 NdisRawReadPortUchar(Adapter->IOBase + NIC_RESET, &Tmp);
519
520 /* Wait for 1.6ms */
521 NdisStallExecution(1600);
522
523 /* Write the value back */
524 NdisRawWritePortUchar(Adapter->IOBase + NIC_RESET, Tmp);
525
526 /* Restart the NIC */
527 NICStart(Adapter);
528
529 return NDIS_STATUS_SUCCESS;
530}
NDIS_STATUS NICStop(PNIC_ADAPTER Adapter)
Definition: 8390.c:451

Referenced by MiniportReset().

◆ NICSetBoundaryPage()

static VOID NICSetBoundaryPage ( PNIC_ADAPTER  Adapter)
static

Definition at line 578 of file 8390.c.

585{
586 if (Adapter->NextPacket == Adapter->PageStart) {
588 (UCHAR)(Adapter->PageStop - 1));
589 } else {
591 (UCHAR)(Adapter->NextPacket - 1));
592 }
593}
#define PG0_BNRY
Definition: 8390.h:16
UINT PageStart
Definition: ne2000.h:133
UINT PageStop
Definition: ne2000.h:134

Referenced by HandleReceive(), and NICReadPacket().

◆ NICSetMulticastAddressMask()

static VOID NICSetMulticastAddressMask ( PNIC_ADAPTER  Adapter)
static

Definition at line 190 of file 8390.c.

200{
201 UINT i;
202
203 /* Select page 1 */
205
206 /* Initialize MAR - Multicast Address Registers */
207 for (i = 0; i < 0x08; i++)
209
210 /* Go back to page 0 */
212}
#define PG1_MAR
Definition: 8390.h:43
UCHAR MulticastAddressMask[8]
Definition: ne2000.h:117

Referenced by NICSetup().

◆ NICSetPhysicalAddress()

static VOID NICSetPhysicalAddress ( PNIC_ADAPTER  Adapter)
static

Definition at line 165 of file 8390.c.

175{
176 UINT i;
177
178 /* Select page 1 */
180
181 /* Initialize PAR - Physical Address Registers */
182 for (i = 0; i < 0x06; i++)
183 NdisRawWritePortUchar(Adapter->IOBase + PG1_PAR + i, Adapter->StationAddress[i]);
184
185 /* Go back to page 0 */
187}
#define PG1_PAR
Definition: 8390.h:41

Referenced by NICSetup().

◆ NICSetup()

NDIS_STATUS NICSetup ( PNIC_ADAPTER  Adapter)

Definition at line 352 of file 8390.c.

363{
364 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
365
366 if (Adapter->WordMode ) {
367 /* Initialize DCR - Data Configuration Register (word mode/4 words FIFO) */
369 } else {
370 /* Initialize DCR - Data Configuration Register (byte mode/8 bytes FIFO) */
372 }
373
374 /* Clear RBCR0 and RBCR1 - Remote Byte Count Registers */
375 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR0, 0x00);
376 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR1, 0x00);
377
378 /* Initialize RCR - Receive Configuration Register (monitor mode) */
380
381 /* Enter loopback mode (internal NIC module loopback) */
383
384 /* Set boundary page */
385 NdisRawWritePortUchar(Adapter->IOBase + PG0_BNRY, Adapter->NextPacket);
386
387 /* Set start page */
388 NdisRawWritePortUchar(Adapter->IOBase + PG0_PSTART, Adapter->PageStart);
389
390 /* Set stop page */
391 NdisRawWritePortUchar(Adapter->IOBase + PG0_PSTOP, Adapter->PageStop);
392
393 /* Program our address on the NIC */
394 NICSetPhysicalAddress(Adapter);
395
396 /* Program the multicast address mask on the NIC */
398
399 /* Select page 1 and stop NIC */
401
402 /* Initialize current page register */
403 NdisRawWritePortUchar(Adapter->IOBase + PG1_CURR, Adapter->PageStart + 1);
404
405 /* Select page 0 and stop NIC */
407
408 /* Clear ISR - Interrupt Status Register */
409 NdisRawWritePortUchar(Adapter->IOBase + PG0_ISR, 0xFF);
410
411 /* Initialize IMR - Interrupt Mask Register */
413
414 /* Select page 0 and start NIC */
416
417 Adapter->CurrentPage = Adapter->PageStart + 1;
418 Adapter->NextPacket = Adapter->PageStart + 1;
419 Adapter->BufferOverflow = FALSE;
420 Adapter->ReceiveError = FALSE;
421 Adapter->TransmitError = FALSE;
422
423 NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
424
425 return NDIS_STATUS_SUCCESS;
426}
static VOID NICSetPhysicalAddress(PNIC_ADAPTER Adapter)
Definition: 8390.c:165
static VOID NICSetMulticastAddressMask(PNIC_ADAPTER Adapter)
Definition: 8390.c:190
#define PG0_PSTART
Definition: 8390.h:13
#define PG0_PSTOP
Definition: 8390.h:15
#define PG0_IMR
Definition: 8390.h:37

Referenced by MiniportInitialize().

◆ NICStart()

NDIS_STATUS NICStart ( PNIC_ADAPTER  Adapter)

Definition at line 429 of file 8390.c.

438{
439 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
440
441 /* Take NIC out of loopback mode */
442 NdisRawWritePortUchar(Adapter->IOBase + PG0_TCR, 0x00);
443
444 /* Initialize RCR - Receive Configuration Register (accept all) */
446
447 return NDIS_STATUS_SUCCESS;
448}
#define RCR_AB
Definition: 8390.h:94
#define RCR_AM
Definition: 8390.h:95
#define RCR_PRO
Definition: 8390.h:96

Referenced by HandleReceive(), MiniportInitialize(), and NICReset().

◆ NICStartTransmit()

static VOID NICStartTransmit ( PNIC_ADAPTER  Adapter)
static

Definition at line 533 of file 8390.c.

540{
541 UINT Length;
542 UCHAR FrameStart;
543 UCHAR Tmp;
544
545 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
546
547 if (Adapter->TXCurrent < 0) return;
548
549 //FrameStart = Adapter->TXStart + Adapter->TXCurrent * DRIVER_BLOCK_SIZE;
550 //FrameStart = Adapter->TXStart;
551 FrameStart = (UCHAR)(Adapter->TXStart + (UCHAR)(Adapter->TXCurrent * BUFFERS_PER_TX_BUF));
552
553 /* Set start of frame */
554 NdisRawReadPortUchar(Adapter->IOBase + PG0_TPSR, &Tmp);
555// NdisRawWritePortUchar(Adapter->IOBase + PG0_TPSR,
556// Adapter->TXStart + Adapter->TXCurrent * DRIVER_BLOCK_SIZE);
557
558 NdisRawWritePortUchar(Adapter->IOBase + PG0_TPSR, FrameStart);
559 //NDIS_DbgPrint(MID_TRACE, ("Setting start of frame to (%d).\n", FrameStart));
560
561 /* Set length of frame */
562 Length = Adapter->TXSize[Adapter->TXCurrent];
563 NdisRawWritePortUchar(Adapter->IOBase + PG0_TBCR0, Length & 0xFF);
565
566 /* Start transmitting */
568
569 NDIS_DbgPrint(MID_TRACE, ("Transmitting. FrameStart (%d) TXCurrent (%d) TXStart (%d) Length (%d).\n\n",
570 FrameStart,
571 Adapter->TXCurrent,
572 Adapter->TXStart,
573 Length));
574
575}
#define CR_TXP
Definition: 8390.h:64
#define PG0_TBCR1
Definition: 8390.h:22
#define PG0_TPSR
Definition: 8390.h:18
#define PG0_TBCR0
Definition: 8390.h:20
#define BUFFERS_PER_TX_BUF
Definition: ne2000.h:55
UINT TXStart
Definition: ne2000.h:160

Referenced by HandleReceive(), HandleTransmit(), and NICTransmit().

◆ NICStop()

NDIS_STATUS NICStop ( PNIC_ADAPTER  Adapter)

Definition at line 451 of file 8390.c.

460{
461 UCHAR Tmp;
462 UINT i;
463
464 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
465
466 /* Select page 0 and stop NIC */
468
469 /* Clear Remote Byte Count Register so ISR_RST will be set */
470 NdisRawWritePortUchar( Adapter->IOBase + PG0_RBCR0, 0x00);
471 NdisRawWritePortUchar( Adapter->IOBase + PG0_RBCR0, 0x00);
472
473 /* Wait for ISR_RST to be set, but timeout after 2ms */
474 for (i = 0; i < 4; i++) {
475 NdisRawReadPortUchar(Adapter->IOBase + PG0_ISR, &Tmp);
476 if (Tmp & ISR_RST)
477 break;
478
480 }
481
482#if DBG
483 if (i == 4)
484 NDIS_DbgPrint(MIN_TRACE, ("NIC was not reset after 2ms.\n"));
485#endif
486
487 /* Initialize RCR - Receive Configuration Register (monitor mode) */
489
490 /* Initialize TCR - Transmit Configuration Register (loopback mode) */
492
493 /* Start NIC */
495
496 return NDIS_STATUS_SUCCESS;
497}

Referenced by MiniportHalt(), MiniportShutdown(), and NICReset().

◆ NICTestAddress()

static BOOLEAN NICTestAddress ( PNIC_ADAPTER  Adapter,
ULONG  Address 
)
static

Definition at line 90 of file 8390.c.

100{
101 USHORT Data;
102 USHORT Tmp;
103
104 /* Read one word */
105 NICReadDataAlign(Adapter, &Data, Address, 0x02);
106
107 /* Alter it */
108 Data ^= 0xFFFF;
109
110 /* Write it back */
111 NICWriteDataAlign(Adapter, Address, &Data, 0x02);
112
113 /* Check if it has changed on the NIC */
114 NICReadDataAlign(Adapter, &Tmp, Address, 0x02);
115
116 return (Data == Tmp);
117}
VOID NICWriteDataAlign(PNIC_ADAPTER Adapter, ULONG_PTR Target, PUSHORT Source, USHORT Length)
Definition: 8390.c:699
static WCHAR Address[46]
Definition: ping.c:68

Referenced by NICTestRAM().

◆ NICTestRAM()

static BOOLEAN NICTestRAM ( PNIC_ADAPTER  Adapter)
static

Definition at line 120 of file 8390.c.

131{
133
134 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
135
136 /* Locate RAM base address */
137 for (Base = 0x0400; Base < 0x10000; Base += 0x0400) {
138 if (NICTestAddress(Adapter, Base))
139 break;
140 }
141
142 if (Base == 0x10000) {
143 /* No RAM on this board */
144 NDIS_DbgPrint(MIN_TRACE, ("No RAM found on board.\n"));
145 return FALSE;
146 }
147
148 Adapter->RamBase = (PUCHAR)Base;
149
150 /* Find RAM size */
151 for (; Base < 0x10000; Base += 0x0400) {
152 if (!NICTestAddress(Adapter, Base))
153 break;
154 }
155
156 Adapter->RamSize = (UINT)(Base - (ULONG_PTR)Adapter->RamBase);
157
158 NDIS_DbgPrint(MID_TRACE, ("RAM is at (0x%X). Size is (0x%X).\n",
159 Adapter->RamBase, Adapter->RamSize));
160
161 return TRUE;
162}
static BOOLEAN NICTestAddress(PNIC_ADAPTER Adapter, ULONG Address)
Definition: 8390.c:90
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2439
UINT RamSize
Definition: ne2000.h:99
PUCHAR RamBase
Definition: ne2000.h:98

Referenced by NICInitialize().

◆ NICTransmit()

VOID NICTransmit ( PNIC_ADAPTER  Adapter)

Definition at line 1124 of file 8390.c.

1133{
1134 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1135
1136 if (Adapter->TXCurrent == -1) {
1137 /* NIC is not transmitting, so start transmitting now */
1138
1139 /* Load next packet onto the card, and start transmitting */
1140 if (NICPrepareForTransmit(Adapter))
1141 NICStartTransmit(Adapter);
1142 }
1143}

Referenced by MiniportSend().

◆ NICUpdateCounters()

VOID NICUpdateCounters ( PNIC_ADAPTER  Adapter)

Definition at line 619 of file 8390.c.

626{
627 UCHAR Tmp;
628
629 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
630
631 NdisRawReadPortUchar(Adapter->IOBase + PG0_CNTR0, &Tmp);
632 Adapter->FrameAlignmentErrors += Tmp;
633
634 NdisRawReadPortUchar(Adapter->IOBase + PG0_CNTR1, &Tmp);
635 Adapter->CrcErrors += Tmp;
636
637 NdisRawReadPortUchar(Adapter->IOBase + PG0_CNTR2, &Tmp);
638 Adapter->MissedPackets += Tmp;
639}
#define PG0_CNTR0
Definition: 8390.h:32
#define PG0_CNTR1
Definition: 8390.h:34
#define PG0_CNTR2
Definition: 8390.h:36
ULONG FrameAlignmentErrors
Definition: ne2000.h:174
ULONG MissedPackets
Definition: ne2000.h:176
ULONG CrcErrors
Definition: ne2000.h:175

Referenced by MiniportHandleInterrupt().

◆ NICWriteData()

VOID NICWriteData ( PNIC_ADAPTER  Adapter,
ULONG_PTR  Target,
PUCHAR  Source,
USHORT  Length 
)

Definition at line 833 of file 8390.c.

846{
847 USHORT Tmp;
848
849 /* Avoid transfers to odd addresses */
850 if (Target & 0x01) {
851 /* Read one word */
852 NICReadDataAlign(Adapter, &Tmp, Target - 1, 0x02);
853
854 /* Merge LSB with the new byte which become the new MSB */
855 Tmp = (Tmp & 0x00FF) | (*Source << 8);
856
857 /* Finally write the value back */
858 NICWriteDataAlign(Adapter, Target - 1, &Tmp, 0x02);
859
860 /* Update pointers */
861 Source = (PUCHAR) ((ULONG_PTR) Source + 1);
862 Target += 1;
863 Length--;
864 }
865
866 if (Length & 0x01) {
867 /* Transfer as many words as we can without exceeding the transfer length */
868 Tmp = Length & 0xFFFE;
869 NICWriteDataAlign(Adapter, Target, (PUSHORT)Source, Tmp);
870 Source += Tmp;
871 Target += Tmp;
872
873 /* Read one word */
874 NICReadDataAlign(Adapter, &Tmp, Target, 0x02);
875
876 /* Merge MSB with the new byte which become the new LSB */
877 Tmp = (Tmp & 0xFF00) | (*Source);
878
879 /* Finally write the value back */
880 NICWriteDataAlign(Adapter, Target, &Tmp, 0x02);
881 } else
882 /* Transfer the rest of the data */
884}

Referenced by NICWritePacket().

◆ NICWriteDataAlign()

VOID NICWriteDataAlign ( PNIC_ADAPTER  Adapter,
ULONG_PTR  Target,
PUSHORT  Source,
USHORT  Length 
)

Definition at line 699 of file 8390.c.

712{
713 UCHAR Tmp;
715
716 /* Select page 0 and start the NIC */
718
719 /* Handle read-before-write bug */
720
721 /* Initialize RSAR0 and RSAR1 - Remote Start Address Registers */
722 NdisRawWritePortUchar(Adapter->IOBase + PG0_RSAR0, (UCHAR)(Target & 0xFF));
724
725 /* Initialize RBCR0 and RBCR1 - Remote Byte Count Registers */
726 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR0, 0x02);
727 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR1, 0x00);
728
729 /* Read and start the NIC */
731
732 /* Read data */
734
735 /* Wait for remote DMA to complete, but timeout after some time */
736 for (Count = 0; Count < 0xFFFF; Count++) {
737 NdisRawReadPortUchar(Adapter->IOBase + PG0_ISR, &Tmp);
738 if (Tmp & ISR_RDC)
739 break;
740
742 }
743
744#if DBG
745 if (Count == 0xFFFF)
746 NDIS_DbgPrint(MIN_TRACE, ("Remote DMA did not complete.\n"));
747#endif
748
749 /* Clear remote DMA bit in ISR - Interrupt Status Register */
751
752
753 /* Now output some data */
754 Count = Length;
755
756 /* Initialize RSAR0 and RSAR1 - Remote Start Address Registers */
757 NdisRawWritePortUchar(Adapter->IOBase + PG0_RSAR0, (UCHAR)(Target & 0xFF));
759
760 /* Initialize RBCR0 and RBCR1 - Remote Byte Count Registers */
761 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR0, (UCHAR)(Count & 0xFF));
762 NdisRawWritePortUchar(Adapter->IOBase + PG0_RBCR1, (UCHAR)(Count >> 8));
763
764 /* Write and start the NIC */
766
767 if (Adapter->WordMode)
769 else
771
772 /* Wait for remote DMA to complete, but timeout after some time */
773 for (Count = 0; Count < 0xFFFF; Count++) {
774 NdisRawReadPortUchar(Adapter->IOBase + PG0_ISR, &Tmp);
775 if (Tmp & ISR_RDC)
776 break;
777
779 }
780
781#if DBG
782 if (Count == 0xFFFF)
783 NDIS_DbgPrint(MIN_TRACE, ("Remote DMA did not complete.\n"));
784#endif
785
786 /* Clear remote DMA bit in ISR - Interrupt Status Register */
788}
#define CR_RD1
Definition: 8390.h:66
#define NdisRawReadPortUshort(Port, Data)
Definition: ndis.h:4191
#define NdisRawWritePortBufferUchar(Port, Buffer, Length)
Definition: ndis.h:4201
#define NdisRawWritePortBufferUshort(Port, Buffer, Length)
Definition: ndis.h:4221

Referenced by NICTestAddress(), and NICWriteData().

◆ NICWritePacket()

static VOID NICWritePacket ( PNIC_ADAPTER  Adapter)
static

Definition at line 995 of file 8390.c.

1006{
1007 PNDIS_BUFFER SrcBuffer;
1008 UINT BytesToCopy, SrcSize, DstSize;
1009 PUCHAR SrcData;
1010 ULONG DstData;
1011 UINT TXStart;
1012 UINT TXStop;
1013
1014 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1015
1016 TXStart = Adapter->TXStart * DRIVER_BLOCK_SIZE;
1017 TXStop = (Adapter->TXStart + Adapter->TXCount) * DRIVER_BLOCK_SIZE;
1018
1020 NULL,
1021 NULL,
1022 &SrcBuffer,
1023 &Adapter->TXSize[Adapter->TXNext]);
1024
1025 NDIS_DbgPrint(MID_TRACE, ("Packet (%d) is now size (%d).\n",
1026 Adapter->TXNext,
1027 Adapter->TXSize[Adapter->TXNext]));
1028
1029 NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
1030
1031 DstData = TXStart + Adapter->TXNext * DRIVER_BLOCK_SIZE;
1032 DstSize = TXStop - DstData;
1033
1034 /* Start copying the data */
1035 for (;;) {
1036 BytesToCopy = (SrcSize < DstSize)? SrcSize : DstSize;
1037
1038 NICWriteData(Adapter, DstData, SrcData, BytesToCopy);
1039
1040 SrcData = (PUCHAR)((ULONG_PTR) SrcData + BytesToCopy);
1041 SrcSize -= BytesToCopy;
1042 DstData += BytesToCopy;
1043 DstSize -= BytesToCopy;
1044
1045 if (SrcSize == 0) {
1046 /* No more bytes in source buffer. Proceed to
1047 the next buffer in the source buffer chain */
1048 NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
1049 if (!SrcBuffer)
1050 break;
1051
1052 NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
1053 }
1054
1055 if (DstSize == 0) {
1056 /* Wrap around the end of the transmit buffer ring */
1057 DstData = TXStart;
1058 DstSize = Adapter->TXCount * DRIVER_BLOCK_SIZE;
1059 }
1060 }
1061}
VOID NICWriteData(PNIC_ADAPTER Adapter, ULONG_PTR Target, PUCHAR Source, USHORT Length)
Definition: 8390.c:833
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3168
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
uint32_t ULONG
Definition: typedefs.h:59

Referenced by NICPrepareForTransmit().

◆ ProbeAddressForNIC()

static BOOLEAN ProbeAddressForNIC ( ULONG_PTR  address)
static

Definition at line 16 of file 8390.c.

29{
30 UCHAR Tmp;
31
32 NDIS_DbgPrint(MID_TRACE, ("Probing address 0x%x\n", address));
33
34 /* Disable interrupts */
36
37 /* Stop the NIC */
39
40 /* Pause for 1.6ms */
42
43 /* Read NIC response */
45
46 if ((Tmp == (CR_RD2 | CR_STP)) || (Tmp == (CR_RD2 | CR_STP | CR_STA)))
47 return TRUE;
48 else
49 return FALSE;
50}
GLuint address
Definition: glext.h:9393

Referenced by NICCheck().

Variable Documentation

◆ ProbeAddressList

ULONG_PTR ProbeAddressList[] = { 0x280, 0x300, 0x320, 0x340, 0x360, 0x380, 0 }

Definition at line 14 of file 8390.c.

Referenced by NICCheck().