1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS Novell Eagle 2000 driver
4  * FILE:        include/ne2000.h
5  * PURPOSE:     NE2000 driver definitions
6  */
7 
8 #ifndef _NE2000_PCH_
9 #define _NE2000_PCH_
10 
11 #define NDIS_MINIPORT_DRIVER 1
12 #define NDIS_LEGACY_MINIPORT 1
13 #define NDIS51_MINIPORT 1
14 #include <ndis.h>
15 #include <8390.h>
16 
17 #include "debug.h"
18 
19 /* Define NOCARD to test NDIS without a card */
20 //#define NOCARD
21 
22 /* NE2000 specific constants */
23 #define NIC_DATA            0x10    /* Data register */
24 #define NIC_RESET           0x1F    /* Reset register */
25 
26 
27 /* Global constants */
28 
29 #define DRIVER_NDIS_MAJOR_VERSION 3
30 #define DRIVER_NDIS_MINOR_VERSION 0
31 
32 #define DRIVER_DEFAULT_IO_BASE_ADDRESS      0x280  /* bochs default */
33 #define DRIVER_DEFAULT_INTERRUPT_NUMBER     9      /* bochs default */
34 #define DRIVER_DEFAULT_INTERRUPT_SHARED     FALSE
35 #define DRIVER_DEFAULT_INTERRUPT_MODE       NdisInterruptLatched
36 
37 #define DRIVER_MAX_MULTICAST_LIST_SIZE  8
38 
39 #define DRIVER_VENDOR_DESCRIPTION       "Novell Eagle 2000 Adapter."
40 #define DRIVER_VENDOR_DRIVER_VERSION    0x0100  /* 1.0 */
41 
42 #define DRIVER_FRAME_SIZE           1514    /* Size of an ethernet frame */
43 #define DRIVER_HEADER_SIZE          14      /* Size of an ethernet header */
44 #define DRIVER_LENGTH_OF_ADDRESS    6       /* Size of an ethernet address */
45 
46 /* Maximum lookahead buffer size */
47 #define DRIVER_MAXIMUM_LOOKAHEAD (252 - DRIVER_HEADER_SIZE)
48 
49 /* Size of a block in a buffer ring */
50 #define DRIVER_BLOCK_SIZE   256
51 
52 
53 /* Default number of transmit buffers */
54 #define DRIVER_DEFAULT_TX_BUFFER_COUNT 12
55 #define BUFFERS_PER_TX_BUF 1
56 
57 /* Interrupt Mask Register value */
58 #define DRIVER_INTERRUPT_MASK   IMR_ALLE - IMR_RDCE
59 
60 /* Maximum number of interrupts handled per call to MiniportHandleInterrupt */
61 #define INTERRUPT_LIMIT 10
62 
63 /* Global structures */
64 
65 typedef struct _MINIPORT_RESERVED
66 {
67     PNDIS_PACKET Next;
68 } MINIPORT_RESERVED, *PMINIPORT_RESERVED;
69 
70 #define RESERVED(Packet) ((PMINIPORT_RESERVED)((Packet)->MiniportReserved))
71 
72 typedef UCHAR DRIVER_HARDWARE_ADDRESS[DRIVER_LENGTH_OF_ADDRESS];
73 
74 /* Information about an adapter */
75 typedef struct _NIC_ADAPTER
76 {
77     /* Entry on global adapter list */
78     LIST_ENTRY ListEntry;
79     /* Adapter handle */
80     NDIS_HANDLE MiniportAdapterHandle;
81     /* NDIS interrupt object */
82     NDIS_MINIPORT_INTERRUPT Interrupt;
83 
84     /* I/O base address and interrupt number of adapter */
85     ULONG_PTR IoBaseAddress;
86     ULONG InterruptLevel;
87     ULONG InterruptVector;
88     BOOLEAN InterruptShared;
89     KINTERRUPT_MODE InterruptMode;
90 
91     /* Mapped address of the I/O base port */
92     PUCHAR IOBase;
93 
94     /* TRUE if the NIC can transfer in word mode */
95     BOOLEAN WordMode;
96 
97     /* Base address and size of the onboard memory window */
98     PUCHAR RamBase;
99     UINT RamSize;
100 
101     /* Station Address PROM (SAPROM) */
102     UCHAR SAPROM[16];
103 
104     /* Onboard ethernet address from the manufacturer */
105     DRIVER_HARDWARE_ADDRESS PermanentAddress;
106 
107     /* Ethernet address currently in use */
108     DRIVER_HARDWARE_ADDRESS StationAddress;
109 
110     /* Maximum number of multicast addresses this adapter supports */
111     ULONG MaxMulticastListSize;
112 
113     /* List of multicast addresses in use */
114     DRIVER_HARDWARE_ADDRESS Addresses[DRIVER_MAX_MULTICAST_LIST_SIZE];
115 
116     /* Current multicast address mask */
117     UCHAR MulticastAddressMask[8];
118 
119     /* Masked interrupts (IMR value) */
120     ULONG InterruptMask;
121 
122     /* Interrupts that have occurred */
123     UCHAR InterruptStatus;
124 
125     /* Current packet filter */
126     ULONG PacketFilter;
127 
128     /* Lookahead buffer */
129     UINT LookaheadSize;
130     UCHAR Lookahead[DRIVER_MAXIMUM_LOOKAHEAD + DRIVER_HEADER_SIZE];
131 
132     /* Receive buffer ring */
133     UINT PageStart;
134     UINT PageStop;
135     UINT CurrentPage;
136     UINT NextPacket;
137 
138     /* TRUE if there was a buffer overflow */
139     BOOLEAN BufferOverflow;
140 
141     /* TRUE if an error occurred during reception of a packet */
142     BOOLEAN ReceiveError;
143 
144     /* TRUE if an error occurred during transmission of a packet */
145     BOOLEAN TransmitError;
146 
147     /* TRUE if a transmit interrupt is pending */
148     BOOLEAN TransmitPending;
149 
150     /* Received packet header */
151     PACKET_HEADER PacketHeader;
152 
153     /* Offset in onboard RAM of received packet */
154     ULONG PacketOffset;
155 
156     /* TRUE if receive indications are done and should be completed */
157     BOOLEAN DoneIndicating;
158 
159     /* Transmit buffers */
160     UINT TXStart;   /* Start block of transmit buffer ring */
161     UINT TXCount;   /* Number of blocks in transmit buffer ring */
162     UINT TXFree;    /* Number of free transmit buffers */
163     UINT TXNext;    /* Next buffer to use */
164     /* Length of packet. 0 means buffer is unused */
165     UINT TXSize[DRIVER_DEFAULT_TX_BUFFER_COUNT];
166     INT TXCurrent;  /* Current buffer beeing transmitted. -1 means none */
167 
168     /* Head of transmit queue */
169     PNDIS_PACKET TXQueueHead;
170     /* Tail of transmit queue */
171     PNDIS_PACKET TXQueueTail;
172 
173     /* Statistics */
174     ULONG FrameAlignmentErrors;
175     ULONG CrcErrors;
176     ULONG MissedPackets;
177 
178     /* Flags used for driver cleanup */
179     BOOLEAN IOPortRangeRegistered;
180     BOOLEAN InterruptRegistered;
181     BOOLEAN ShutdownHandlerRegistered;
182 } NIC_ADAPTER, *PNIC_ADAPTER;
183 
184 /* Global driver information */
185 typedef struct _DRIVER_INFORMATION
186 {
187     NDIS_HANDLE NdisWrapperHandle;  /* Returned from NdisInitializeWrapper */
188     NDIS_HANDLE NdisMacHandle;      /* Returned from NdisRegisterMac */
189     LIST_ENTRY  AdapterListHead;    /* Adapters this driver control */
190 } DRIVER_INFORMATION, *PDRIVER_INFORMATION;
191 
192 
193 
194 /* Global variable */
195 
196 extern DRIVER_INFORMATION DriverInfo;
197 extern NDIS_PHYSICAL_ADDRESS HighestAcceptableMax;
198 
199 
200 
201 /* Prototypes */
202 
203 BOOLEAN NICCheck(
204     PNIC_ADAPTER Adapter);
205 
206 NDIS_STATUS NICInitialize(
207     PNIC_ADAPTER Adapter);
208 
209 NDIS_STATUS NICSetup(
210     PNIC_ADAPTER Adapter);
211 
212 NDIS_STATUS NICStart(
213     PNIC_ADAPTER Adapter);
214 
215 NDIS_STATUS NICStop(
216     PNIC_ADAPTER Adapter);
217 
218 NDIS_STATUS NICReset(
219     PNIC_ADAPTER Adapter);
220 
221 VOID NICUpdateCounters(
222     PNIC_ADAPTER Adapter);
223 
224 VOID NICReadDataAlign(
225     PNIC_ADAPTER Adapter,
226     PUSHORT Target,
227     ULONG_PTR Source,
228     USHORT Length);
229 
230 VOID NICWriteDataAlign(
231     PNIC_ADAPTER Adapter,
232     ULONG_PTR Target,
233     PUSHORT Source,
234     USHORT Length);
235 
236 VOID NICReadData(
237     PNIC_ADAPTER Adapter,
238     PUCHAR Target,
239     ULONG_PTR Source,
240     USHORT Length);
241 
242 VOID NICWriteData(
243     PNIC_ADAPTER Adapter,
244     ULONG_PTR Target,
245     PUCHAR Source,
246     USHORT Length);
247 
248 VOID NICTransmit(
249     PNIC_ADAPTER Adapter);
250 
251 #endif /* _NE2000_PCH_ */
252