summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/lance/lancehrd.h
blob: 1a9f3c48e19e67133b6259caa207b212a59ee649 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

    lance.c

Abstract:

    The main program for a LANCE (Local Area Network Controller
    Am 7990) MAC driver.

Author:

    Anthony V. Ercolano (tonye) creation-date 19-Jun-1990

Environment:

    This driver is expected to work in DOS, OS2 and NT at the equivalent
    of kernal mode.

    Architecturally, there is an assumption in this driver that we are
    on a little endian machine.

Notes:

    optional-notes

Revision History:

    31-Jul-1992  R.D. Lanser:
       Removed system implementation dependent defines for the DEC
       TurboChannel option PMAD-AA (Lance ethernet).

--*/

#ifndef _LANCEHARDWARE_
#define _LANCEHARDWARE_

//
// Compressed ID for DE422 EISA adapter
//

#define DE422_COMPRESSED_ID     0x2042a310

//
// All registers on the LANCE are 16 bits.
//

#define LANCE_SELECT_CSR0 ((USHORT)0)
#define LANCE_SELECT_CSR1 ((USHORT)1)
#define LANCE_SELECT_CSR2 ((USHORT)2)
#define LANCE_SELECT_CSR3 ((USHORT)3)

#define LANCE_CSR0_INITIALIZE             ((USHORT)(0x0001))
#define LANCE_CSR0_START                  ((USHORT)(0x0002))
#define LANCE_CSR0_STOP                   ((USHORT)(0x0004))
#define LANCE_CSR0_TRANSMIT_DEMAND        ((USHORT)(0x0008))
#define LANCE_CSR0_TRANSMITTER_ON         ((USHORT)(0x0010))
#define LANCE_CSR0_RECEIVER_ON            ((USHORT)(0x0020))
#define LANCE_CSR0_INTERRUPT_ENABLE       ((USHORT)(0x0040))
#define LANCE_CSR0_INTERRUPT_FLAG         ((USHORT)(0x0080))
#define LANCE_CSR0_INITIALIZATION_DONE    ((USHORT)(0x0100))
#define LANCE_CSR0_TRANSMITTER_INTERRUPT  ((USHORT)(0x0200))
#define LANCE_CSR0_RECEIVER_INTERRUPT     ((USHORT)(0x0400))
#define LANCE_CSR0_MEMORY_ERROR           ((USHORT)(0x0800))
#define LANCE_CSR0_MISSED_PACKET          ((USHORT)(0x1000))
#define LANCE_CSR0_COLLISION_ERROR        ((USHORT)(0x2000))
#define LANCE_CSR0_BABBLE                 ((USHORT)(0x4000))
#define LANCE_CSR0_ERROR_SUMMARY          ((USHORT)(0x8000))
#define LANCE_CSR0_ERROR_BITS             ((USHORT)(0xf800))


//
// We define a constant csr3 value that is useful for setting the ACON
// bit in csr3.
//
#define LANCE_CSR3_ACON ((USHORT)0x02)


#define LANCE_NICSR_LED_ON                ((USHORT)(0x0001))
#define LANCE_NICSR_INT_ON                ((USHORT)(0x0002))
#define LANCE_NICSR_IMASK                 ((USHORT)(0x0004))
#define LANCE_NICSR_128K                  ((USHORT)(0x0008))
#define LANCE_NICSR_BUFFER_SIZE           ((USHORT)(0x0020))


//
// Definitions for the many different lance card types.
//

#define LANCE_DEPCA_INTERRUPT_VECTOR 5
#define LANCE_DEPCA_INTERRUPT_IRQL   5

#define LANCE_DE201_INTERRUPT_VECTOR ((CCHAR)5)
#define LANCE_DE201_INTERRUPT_IRQL LANCE_DE201_INTERRUPT_VECTOR

#define LANCE_DE100_INTERRUPT_VECTOR ((CCHAR)3)
#define LANCE_DE100_INTERRUPT_IRQL LANCE_DE100_INTERRUPT_VECTOR




#define LANCE_DEPCA_HARDWARE_MEMORY (0x10000)      // 64K
#define LANCE_DEPCA_NICSR_ADDRESS   ((ULONG)(0x200))
#define LANCE_DEPCA_BASE            ((PVOID)(0xD0000))
#define LANCE_DEPCA_RAP_OFFSET      ((ULONG)(0x006))
#define LANCE_DEPCA_RDP_OFFSET      ((ULONG)(0x004))
#define LANCE_DEPCA_EPROM_OFFSET    ((ULONG)(0x00c))
#define LANCE_DEPCA_LAN_CFG_OFFSET  ((ULONG)(0x600))

#define LANCE_DE201_HARDWARE_MEMORY (0x10000)      // 64K
#define LANCE_DE201_BASE            ((PVOID)(0xD0000))

#define LANCE_DE201_PRI_NICSR_ADDRESS   ((ULONG)(0x300))
#define LANCE_DE201_SEC_NICSR_ADDRESS   ((ULONG)(0x200))
#define LANCE_DE201_RAP_OFFSET          ((ULONG)(0x006))
#define LANCE_DE201_RDP_OFFSET          ((ULONG)(0x004))
#define LANCE_DE201_NETWORK_OFFSET      ((ULONG)(0x00C))

#define LANCE_DE422_NICSR_ADDRESS        ((ULONG)(0xC00))
#define LANCE_DE422_RAP_OFFSET           ((ULONG)(0x006))
#define LANCE_DE422_RDP_OFFSET           ((ULONG)(0x004))
#define LANCE_DE422_NETWORK_OFFSET       ((ULONG)(0x00C))
#define LANCE_DE422_EISA_CONFIGURATION_OFFSET   ((ULONG)(0x00C))
#define LANCE_DE422_EXTENDED_MEMORY_BASE_OFFSET ((ULONG)(0x008))
#define LANCE_DE422_EISA_IDENTIFICATION_OFFSET  ((ULONG)(0x080))
#define LANCE_DE422_EISA_CONTROL_OFFSET         ((ULONG)(0x084))





#define LANCE_NUMBER_OF_TRANSMIT_RINGS ((UINT)64)
#define LANCE_LOG_TRANSMIT_RINGS ((UINT)6)

#define LANCE_128K_NUMBER_OF_RECEIVE_RINGS ((UINT)128)
#define LANCE_128K_LOG_RECEIVE_RINGS ((UINT)7)

#define LANCE_64K_NUMBER_OF_RECEIVE_RINGS ((UINT)128)
#define LANCE_64K_LOG_RECEIVE_RINGS ((UINT)7)

#define LANCE_32K_NUMBER_OF_RECEIVE_RINGS ((UINT)32)
#define LANCE_32K_LOG_RECEIVE_RINGS ((UINT)5)

#define LANCE_32K_SIZE_OF_RECEIVE_BUFFERS ((UINT)256)
#define LANCE_64K_SIZE_OF_RECEIVE_BUFFERS ((UINT)256)
#define LANCE_128K_SIZE_OF_RECEIVE_BUFFERS  ((UINT)512)

//
// Note: The value of LANCE_SIZE_OF_RECEIVE_BUFFERS should always be the
//       largest of the receive buffers sizes.  At this time, it is 512
//       for the DEC TurboChannel card.  If this size changes, recompile
//       loopback.c.
//
#define LANCE_SIZE_OF_RECEIVE_BUFFERS ((UINT)256)
#ifndef i386
#define LANCE_LOOPBACK_SIZE_OF_RECEIVE_BUFFERS  ((UINT)512)
#else
#define LANCE_LOOPBACK_SIZE_OF_RECEIVE_BUFFERS  LANCE_SIZE_OF_RECEIVE_BUFFERS
#endif


#define LANCE_SMALL_BUFFER_SIZE ((UINT)64)
#define LANCE_MEDIUM_BUFFER_SIZE ((UINT)256)
#define LANCE_LARGE_BUFFER_SIZE ((UINT)1514)

#define LANCE_128K_NUMBER_OF_SMALL_BUFFERS ((UINT)100)
#define LANCE_128K_NUMBER_OF_MEDIUM_BUFFERS ((UINT)50)
#define LANCE_128K_NUMBER_OF_LARGE_BUFFERS ((UINT)20)

#define LANCE_64K_NUMBER_OF_SMALL_BUFFERS ((UINT)10)
#define LANCE_64K_NUMBER_OF_MEDIUM_BUFFERS ((UINT)10)
#define LANCE_64K_NUMBER_OF_LARGE_BUFFERS ((UINT)4)

#define LANCE_32K_NUMBER_OF_SMALL_BUFFERS ((UINT)10)
#define LANCE_32K_NUMBER_OF_MEDIUM_BUFFERS ((UINT)10)
#define LANCE_32K_NUMBER_OF_LARGE_BUFFERS ((UINT)2)


#define LANCE_ISR_WRITE_RAP(A,C)  NdisRawWritePortUshort((ULONG)((A)->RAP),C)
#define LANCE_ISR_READ_RDP(A,C)   NdisRawReadPortUshort((ULONG)((A)->RDP),C)
#define LANCE_ISR_WRITE_RDP(A,C)  NdisRawWritePortUshort((ULONG)((A)->RDP),C)
#define LANCE_ISR_WRITE_NICSR(A,C) NdisRawWritePortUshort((ULONG)((A)->Nicsr),C)


#define LANCE_GET_LOW_PART_ADDRESS(Adr) \
    ((USHORT)((Adr) & 0xffff))

#define LANCE_GET_HIGH_PART_ADDRESS(Adr) \
    ((UCHAR)((Adr) & 0xff0000) >> 16)

typedef struct _LANCE_INITIALIZATION_BLOCK {

    USHORT ModeRegister;
    UCHAR PhysicalAddress[6];
    UCHAR LogicalAddressFilter[8];
    USHORT LowReceiveRingAddress;
    UCHAR HighReceiveRingAddress;
    UCHAR ReceiveLengthLow5BitsReserved;
    USHORT LowTransmitRingAddress;
    UCHAR HighTransmitRingAddress;
    UCHAR TransmitLengthLow5BitsReserved;

} LANCE_INITIALIZATION_BLOCK,*PLANCE_INITIALIZATION_BLOCK;

//
// Define masks to access bits in the mode register of the initialization
// block.
//
#define LANCE_MODE_PROMISCUOUS ((USHORT)(0x8000))

//
// Defines for moving to/from shared memory.
//


#define LANCE_ZERO_MEMORY_FOR_HARDWARE(Destination,Length) \
    NdisZeroMappedMemory(Destination,Length)

#define LANCE_MOVE_STRUCT_TO_HARDWARE(Destination,Source) \
    NdisMoveToMappedMemory(&(Destination), &(Source), sizeof(Source))

#define LANCE_MOVE_MEMORY_TO_HARDWARE(Destination,Source,Length) \
    NdisMoveToMappedMemory(Destination, Source, Length)

#define LANCE_MOVE_HARDWARE_TO_MEMORY(Destination,Source,Length) \
    NdisMoveFromMappedMemory(Destination, Source, Length)

#define LANCE_WRITE_HARDWARE_LOW_PART_ADDRESS(Destination, Source) \
    NdisWriteRegisterUshort((PUSHORT)(&Destination), (USHORT)(Source))

#define LANCE_WRITE_HARDWARE_HIGH_PART_ADDRESS(Destination, Source) \
    NdisWriteRegisterUchar((PUCHAR)(&Destination), (UCHAR)(Source))

#define LANCE_WRITE_HARDWARE_MEMORY_UCHAR(Destination, Source) \
    NdisWriteRegisterUchar((PUCHAR)(&Destination), (UCHAR)(Source))

#define LANCE_WRITE_HARDWARE_MEMORY_USHORT(Destination, Source) \
    NdisWriteRegisterUshort((PUSHORT)(&Destination), (USHORT)(Source))

#define LANCE_READ_HARDWARE_MEMORY_UCHAR(Source, Destination) \
    NdisReadRegisterUchar((PUCHAR)(&Source), Destination)

#define LANCE_READ_HARDWARE_MEMORY_USHORT(Source, Destination) \
    NdisReadRegisterUshort((PUSHORT)(&Source), Destination)

#if defined(_ALPHA_)

#define LANCE_SET_RING_BITS(Destination, Data) \
{ \
    UCHAR Tmp; \
    LANCE_READ_HARDWARE_MEMORY_UCHAR(Destination, &Tmp); \
    LANCE_WRITE_HARDWARE_MEMORY_UCHAR(Destination, Tmp | Data); \
}

#else

#define LANCE_SET_RING_BITS(Destination, Data)   (Destination) |= ((Data))

#endif // _ALPHA_

typedef struct _LANCE_RECEIVE_ENTRY {

    //
    // 24 bit pointer to the buffer for the receive
    // data.  This is written by the host and unchanged
    // by the LANCE.
    //
    USHORT LowReceiveBufferAddress;
    UCHAR HighReceiveBufferAddress;

    //
    // This char field contains numerous bits describing
    // the errors that can occur in the packet as well as
    // whether this is the first and/or last buffer in the packet.
    //
    UCHAR ReceiveSummaryBits;

    //
    // This is the twos compliment of the buffer length.
    //
    // NOTE: The high order 4 bits must be enabled.
    //
    USHORT BufferByteCount;

    //
    // This is the length of the data in the packet.
    //
    // Note that the high order 4 bits are undefined.
    //
    USHORT MessageLength;

} LANCE_RECEIVE_ENTRY,*PLANCE_RECEIVE_ENTRY;

//
// A number of macros that make accessing the various bits of the receive
// ring entry a little easier as well as providing some validity checks.
//

//
// Used to set the address of the receive buffer.
//
// Rd is a pointer to a receive descriptor.
//
// Adr is a *physical* address.
//
//
#define LANCE_SET_RECEIVE_BUFFER_ADDRESS(Adptr,Rd,Adr) \
{ \
    PVOID _Adr = (Adr); \
    PLANCE_ADAPTER _Adptr = (Adptr);\
    PLANCE_RECEIVE_ENTRY _Rd = (Rd); \
    ULONG _Offset;\
    _Offset = (ULONG)_Adr - (ULONG)(_Adptr->MmMappedBaseAddr);\
    _Offset = _Offset + (ULONG)(_Adptr->HardwareBaseOffset);\
    LANCE_WRITE_HARDWARE_LOW_PART_ADDRESS(\
        _Rd->LowReceiveBufferAddress,\
        (USHORT)((ULONG)_Offset) & 0xffff); \
    LANCE_WRITE_HARDWARE_HIGH_PART_ADDRESS(\
        _Rd->HighReceiveBufferAddress,\
        (UCHAR)(((ULONG)_Offset) >> 16) & 0xff); \
}


//
// Used to set the length of the receive buffer.  The stored value
// is actually the twos compliment of the length.  Note that
// the twos complement of this value must have the high order 4 bits
// enabled.
//
// Rd is a pointer to a receive descriptor.
//
// Len is the unsigned short length of the buffer.
//
#define LANCE_SET_RECEIVE_BUFFER_LENGTH(Rd,Len) \
    LANCE_WRITE_HARDWARE_MEMORY_USHORT(\
        Rd->BufferByteCount,\
        (USHORT)((~Len)+1)\
        )

//
// Masks for the summary bits in the receive descriptor.
//
#define LANCE_RECEIVE_END_OF_PACKET   ((UCHAR)0x01)
#define LANCE_RECEIVE_START_OF_PACKET ((UCHAR)0x02)
#define LANCE_RECEIVE_BUFFER_ERROR    ((UCHAR)0x04)
#define LANCE_RECEIVE_CRC_ERROR       ((UCHAR)0x08)
#define LANCE_RECEIVE_OVERFLOW_ERROR  ((UCHAR)0x10)
#define LANCE_RECEIVE_FRAMING_ERROR   ((UCHAR)0x20)
#define LANCE_RECEIVE_ERROR_SUMMARY   ((UCHAR)0x40)
#define LANCE_RECEIVE_OWNED_BY_CHIP   ((UCHAR)0x80)

//
// This macro gets the packet message length from what is
// assumed to be the last buffer in a packet.  Note that
// on the lance the length of the data includes the four
// byte CRC so we must subtract four from length in the
// ring entry.
//
// Rd is a pointer to a receive descriptor.
// Value is the place to store the result.
//
#if defined(_ALPHA_)

#define LANCE_GET_MESSAGE_SIZE(Rd, Value) \
{ \
    NdisReadRegisterUshort(                                                   \
              ((ULONG)Rd + FIELD_OFFSET(LANCE_RECEIVE_ENTRY, MessageLength)), \
              &Value                                                          \
              );                                                              \
    Value = (Value & ((USHORT)0x0fff)) -4;                                    \
}


#else

#define LANCE_GET_MESSAGE_SIZE(Rd, Value) \
   Value = (((Rd->MessageLength) & ((USHORT)0x0fff))-4)

#endif // _ALPHA_

typedef struct _LANCE_TRANSMIT_ENTRY {

    //
    // 24 bit pointer to the transmit buffer.  This is
    // written by the host and unchanged by the LANCE.
    //
    USHORT LowTransmitBufferAddress;
    UCHAR HighTransmitBufferAddress;

    //
    // This field contains summary information about the packet.
    //
    UCHAR TransmitSummaryBits;

    //
    // This field contains the "twos complement" of the length
    // of the buffer.
    //
    // NOTE: The high order four bits must be enabled.
    //
    USHORT BufferByteCount;

    //
    // This short contains the error summary information for the
    // ring entry.
    //
    USHORT ErrorSummaryInfo;

} LANCE_TRANSMIT_ENTRY,*PLANCE_TRANSMIT_ENTRY;

//
// Masks for the normal summary bits in the transmit descriptor.
//
#define LANCE_TRANSMIT_END_OF_PACKET       ((UCHAR)(0x01))
#define LANCE_TRANSMIT_START_OF_PACKET     ((UCHAR)(0x02))
#define LANCE_TRANSMIT_DEFERRED            ((UCHAR)(0x04))
#define LANCE_TRANSMIT_ONE_RETRY           ((UCHAR)(0x08))
#define LANCE_TRANSMIT_MORE_THAN_ONE_RETRY ((UCHAR)(0x10))
#define LANCE_TRANSMIT_ANY_ERRORS          ((UCHAR)(0x40))
#define LANCE_TRANSMIT_OWNED_BY_CHIP       ((UCHAR)(0x80))

//
// Set of masks to recover particular errors that a transmit can encounter.
//
#define LANCE_TRANSMIT_TDR            ((USHORT)(0x03ff))
#define LANCE_TRANSMIT_RETRY          ((USHORT)(0x0400))
#define LANCE_TRANSMIT_LOST_CARRIER   ((USHORT)(0x0800))
#define LANCE_TRANSMIT_LATE_COLLISION ((USHORT)(0x0100))
#define LANCE_TRANSMIT_UNDERFLOW      ((USHORT)(0x4000))
#define LANCE_TRANSMIT_BUFFER         ((USHORT)(0x8000))

//
// Used to set the address of the transmit buffer.
//
// Rd is a pointer to a transmit descriptor.
//
// Adr is a *physical* address.
//
//

#define LANCE_SET_TRANSMIT_BUFFER_ADDRESS(Adptr,Td,Adr) \
{ \
    PVOID _Adr = (Adr); \
    PLANCE_TRANSMIT_ENTRY _Td = (Td); \
    ULONG _Offset;\
    PLANCE_ADAPTER _Adptr = (Adptr);\
    _Offset = (ULONG)_Adr - (ULONG)(_Adptr->MmMappedBaseAddr);\
    _Offset = _Offset + (ULONG)(_Adptr->HardwareBaseOffset);\
    LANCE_WRITE_HARDWARE_LOW_PART_ADDRESS(\
        _Td->LowTransmitBufferAddress,\
        (USHORT)(((ULONG)_Offset) & 0xffff)\
        );\
    LANCE_WRITE_HARDWARE_HIGH_PART_ADDRESS(\
        _Td->HighTransmitBufferAddress,\
        (UCHAR)((((ULONG)_Offset) >> 16) & 0xff)\
        );\
}


//
// Used to set the length of the transmit buffer.  The stored value
// is actually the twos compliment of the length.  Note that
// the twos complement of this value must have the high order 4 bits
// enabled.
//
// Td is a pointer to a transmit descriptor.
//
// Len is the unsigned short length of the buffer.
//
#define LANCE_SET_TRANSMIT_BUFFER_LENGTH(Td,Len) \
    LANCE_WRITE_HARDWARE_MEMORY_USHORT(\
        Td->BufferByteCount,\
        (USHORT)((~Len)+1)\
        )

#endif // _LANCEHARDWARE_