summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/ibmtok2i/tok162sw.h
blob: 8f431b6b1c80467da5514de602f9ac7a5e6f9c7b (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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
/*++

Copyright (c) 1992  Microsoft Corporation

Module Name:

    tok162sw.h

Abstract:

    The hardware-related definitions for the IBM Token-Ring 16/4 II
    ISA driver.

Author:

    Kevin Martin (kevinma) 1-Feb-1994

Environment:

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

Notes:

    optional-notes

Revision History:


--*/

#include <ndis.h>
#include <tok162hw.h>

//
// Temporary #define for debugging regardless of DBG flag
//
#define     MYDBGPRINT  DbgPrint;

//
// Debugging flags.
//
#if DBG

//
// Degrees of debugging output. Can be OR'd in any combination.
//
#define TOK162_DEBUG_LOUD       0x1
#define TOK162_DEBUG_VERY_LOUD  0x2
#define TOK162_DEBUG_EXTRA_LOUD 0x4

//
// The degree of debugging output being displayed on the debugger currently.
// Defined in TOK162.C.
//
extern  UCHAR                   Tok162Debug;

//
// Macros that decide on the debugging based on Tok162Debug.
//
#define LOUD_DEBUG(A)       if (Tok162Debug & TOK162_DEBUG_LOUD) { A ; }
#define VERY_LOUD_DEBUG(A)  if (Tok162Debug & TOK162_DEBUG_VERY_LOUD) { A ; }
#define EXTRA_LOUD_DEBUG(A) if (Tok162Debug & TOK162_DEBUG_EXTRA_LOUD) { A ; }
#define CURRENT_DEBUG(A)    if (Tok162Debug & 8) { A ; }

//
// The size of the logging array
//
#define LOG_SIZE                256

//
// Pointer for the logging array. Allocated in TOK162.C
// (AllocateAdapterMemory)
//
extern  PUCHAR                  Tok162Log;

//
// The current index into the logging array.
//
extern  USHORT                  Tok162LogPlace;

//
// Logging macro.
//
#define IF_LOG(ch) { Tok162Log[Tok162LogPlace] = (ch); \
                     Tok162LogPlace = (Tok162LogPlace + 1) % LOG_SIZE; }

#else // if dbg

//
// Make sure all of the debugging and logging calls resolve to NULL
//
#define LOUD_DEBUG(A)
#define VERY_LOUD_DEBUG(A)
#define EXTRA_LOUD_DEBUG(A)

#define IF_LOG(ch) { }

#endif // if dbg

//
// Version constants for this driver
//
#define TOK162_NDIS_MAJOR_VERSION 3
#define TOK162_NDIS_MINOR_VERSION 0

//
// Macro to allocate physical memory.
//
#define TOK162_ALLOC_PHYS(_Status, _pBuffer, _Length) \
{ \
    NDIS_PHYSICAL_ADDRESS MinusOne = NDIS_PHYSICAL_ADDRESS_CONST (-1, -1); \
    *(_Status) = NdisAllocateMemory( \
                     (PVOID*)(_pBuffer), \
                     (_Length), \
                     0, \
                     MinusOne); \
}

//
// Macro to free physical memory previously allocated.
//
#define TOK162_FREE_PHYS(_Buffer) NdisFreeMemory((_Buffer), 0, 0)

//
// Enumeration for the reset stages.
//
enum ResetStates{InitialInit,
                 CheckReset,
                 CheckResetRetry,
                 DoTheInit,
                 CheckInit,
                 CheckInitRetry
                 };

//
// Adapter structure is defined further down.
//
struct _TOK162_ADAPTER;


//
// TOK162 Configuration Block
//
// This structure contains configuration data for the TOK162. This
// structure is filled in based on the switches.
//
typedef struct _TOK162_CONFIGURATION_BLOCK {

    //
    // This is the adapter mode;
    //
    USHORT AdapterMode;

    //
    // This field contains the wait state
    //
    USHORT WaitState;

    //
    // This field contains the RPL
    //
    BOOLEAN RPL;

    //
    // This field contains the RPL Address
    //
    UINT RPLAddress;

    //
    // This field contains the DMA Channel
    //
    USHORT DMAChannel;

    //
    // This field contains the Ring Speed
    //
    USHORT RingSpeed;

    //
    // Interrupt level
    //
    USHORT  InterruptLevel;

    //
    // This field contains the connector type
    //
    USHORT UTPorSTP;

} TOK162_CONFIGURATION_BLOCK, *PTOK162_CONFIGURATION_BLOCK;

//
// In addition to the Command Block fields which the TOK162HW.H
// defines, we need some additional fields for our own purposes.
// To ensure that these fields are properly aligned (and to
// ensure that the actual Command Block is properly aligned)
// we'll defined a Super Command Block.  This structure will
// contain a "normal" TOK162 Command Block plus some additional
// fields. This structure is used for both commands and transmits.
//
typedef struct _TOK162_SUPER_COMMAND_BLOCK {

    //
    // The actual TOK162 Command Block.
    //
    TOK162_COMMAND_BLOCK        Hardware;

    //
    // This contains the physical address of the above Command Block.
    //
    NDIS_PHYSICAL_ADDRESS       Self;
    TOK162_PHYSICAL_ADDRESS     PhysicalTransmitEntry;

    //
    // Constrain Buffer addresses
    //
    NDIS_PHYSICAL_ADDRESS       TOK162BufferPhysicalAddress;
    TOK162_PHYSICAL_ADDRESS     TOK162BufferAddress;

    //
    // This contains the virtual address of the next pending command.
    //
    struct _TOK162_SUPER_COMMAND_BLOCK *NextCommand;

    //
    // Points to the packet from which data is being transmitted
    // through this Command Block.
    //
    PNDIS_PACKET                OwningPacket;

    //
    // When a packet is submitted to the hardware we record
    // here whether it used adapter buffers and if so, the buffer
    // index.
    //
    BOOLEAN                     UsedTOK162Buffer;

    //
    // Is this from a set
    //
    BOOLEAN                     Set;

    //
    // If this is a public (adapter-wide) command block, then
    // this will contain this block's index into the adapter's
    // command queue.
    //
    USHORT                      CommandBlockIndex;

    //
    // This tells if the command block is a regular or transmit command block.
    //
    BOOLEAN                     CommandBlock;

    //
    // This field is used to timestamp the command blocks
    // as they are placed into the command queue.  If a
    // block fails to execute, the adapter will get a kick in the ass to
    // start it up again.
    //
    BOOLEAN                     Timeout;

    //
    // Count of the number of times we have retried a command.
    //
    UCHAR                       TimeoutCount;

    //
    // Points to an Mdl which points to this buffer
    //
    PNDIS_BUFFER                FlushBuffer;

} TOK162_SUPER_COMMAND_BLOCK, *PTOK162_SUPER_COMMAND_BLOCK;

//
// In addition to the Receive Entry fields which the TOK162HW.H
// defines, we need some additional fields for our own purposes.
// To ensure that these fields are properly aligned (and to
// ensure that the actual Receive Entry is properly aligned)
// we'll defined a Super Receive Entry.  This structure will
// contain a "normal" TOK162 Receive Entry plus some additional
// fields.
//
typedef struct _TOK162_SUPER_RECEIVE_LIST {

    //
    // The actual TOK162 Receive List.
    //
    TOK162_RECEIVE_LIST         Hardware;

    //
    // This contains the physical address of the above Receive List.
    //
    NDIS_PHYSICAL_ADDRESS       Self;

    //
    // This contains the virtual address of this Receive List's
    // frame buffer.
    //
    PVOID                       ReceiveBuffer;
    NDIS_PHYSICAL_ADDRESS       ReceiveBufferPhysical;

    //
    // This contains the virtual address of the next
    // Receive List in the Receive Queue.
    //
    struct _TOK162_SUPER_RECEIVE_LIST *NextEntry;

    //
    // Points to an Mdl which points to this buffer
    //
    PNDIS_BUFFER                FlushBuffer;

} TOK162_SUPER_RECEIVE_LIST, *PTOK162_SUPER_RECEIVE_LIST;

//
// Adapter Structure
//

typedef struct _TOK162_ADAPTER {

    //
    // Handle given by NDIS when the miniport was initialized.
    //
    NDIS_HANDLE                 MiniportAdapterHandle;

    //
    // Interrupt pointers and variables for the adapter
    //
    NDIS_MINIPORT_INTERRUPT     Interrupt;
    USHORT                      InterruptLevel;

    //
    // Are we running at 16Mbps?
    //
    BOOLEAN                     Running16Mbps;

    //
    // Pointers for the System Command Block for the adapter
    //
    PSCB                        Scb;
    NDIS_PHYSICAL_ADDRESS       ScbPhysical;

    //
    // Pointers for the System Status Block for the adapter
    //
    PSSB                        Ssb;
    NDIS_PHYSICAL_ADDRESS       SsbPhysical;

    //
    // Command queue and related variables
    //
    PTOK162_SUPER_COMMAND_BLOCK CommandQueue;
    NDIS_PHYSICAL_ADDRESS       CommandQueuePhysical;

    //
    // Index to next command block
    //
    UINT                        NextCommandBlock;

    //
    // Number of command blocks available for use
    //
    UINT                        NumberOfAvailableCommandBlocks;

    //
    // Active command.
    //
    PTOK162_SUPER_COMMAND_BLOCK CommandOnCard;

    //
    // First pending command.
    //
    PTOK162_SUPER_COMMAND_BLOCK WaitingCommandHead;

    //
    // Last pending command.
    //
    PTOK162_SUPER_COMMAND_BLOCK WaitingCommandTail;

    //
    // Current packet filter on adapter
    //
    UINT                        CurrentPacketFilter;

    //
    // Is there an outstanding request
    //
    BOOLEAN                     RequestInProgress;

    //
    // Number of bytes needed and written.
    //
    PUINT                       BytesWritten;
    PUINT                       BytesNeeded;

    //
    // Current Oid processing.
    //
    NDIS_OID                    Oid;

    //
    // Buffer and length of buffer used for doing query/set info calls.
    //
    PVOID                       InformationBuffer;
    UINT                        InformationBufferLength;

    //
    // Current interrupt value
    //
    USHORT                      InterruptMask;

    //
    // Command that caused the interrupt
    //
    USHORT                      SsbCommand;

    //
    // The status variables that are saved as the result of an interrupt
    //
    USHORT                      SsbStatus1;
    USHORT                      SsbStatus2;
    USHORT                      SsbStatus3;

    //
    // The I/O Base address of the adapter.
    //
    ULONG                       PortIOBase;
    PVOID                       PortIOAddress;

    //
    // Pointers and variables for the Open block for the adapter
    //
    POPEN_COMMAND               Open;
    NDIS_PHYSICAL_ADDRESS       OpenPhysical;

    //
    // The network address for the adapter and the current one being used.
    //
    CHAR                        NetworkAddress[TOK162_LENGTH_OF_ADDRESS];
    CHAR                        CurrentAddress[TOK162_LENGTH_OF_ADDRESS];

    //
    // Functional and Group Addresses for the adapter
    //
    ULONG                       FunctionalAddress;
    ULONG                       GroupAddress;

    //
    // Pointer to the Receive Queue.
    //
    PTOK162_SUPER_RECEIVE_LIST  ReceiveQueue;
    NDIS_PHYSICAL_ADDRESS       ReceiveQueuePhysical;

    //
    // Pointer to the current receive list
    //
    PTOK162_SUPER_RECEIVE_LIST  ReceiveQueueCurrent;

    //
    // Number of frame header bytes in the buffer.
    //
    USHORT                      SizeOfReceivedHeader;

    //
    // Count of the receive buffers
    //
    UINT                        NumberOfReceiveBuffers;

    //
    // Size of the receive buffer, based on the ring speed.
    //
    USHORT                      ReceiveBufferSize;

    //
    // The receive flush buffer pool handle
    //
    PNDIS_HANDLE                FlushBufferPoolHandle;

    //
    // Pointer to the Transmit Command Queue.
    //
    PTOK162_SUPER_COMMAND_BLOCK TransmitQueue;
    NDIS_PHYSICAL_ADDRESS       TransmitQueuePhysical;

    //
    // Index of next available transmit block
    //
    UINT                        NextTransmitBlock;

    //
    // Pointer to active transmit.
    //
    PTOK162_SUPER_COMMAND_BLOCK TransmitOnCard;

    //
    // Pointer to head of waiting queue.
    //
    PTOK162_SUPER_COMMAND_BLOCK WaitingTransmitHead;

    //
    // Pointer to tail of waiting queue
    //
    PTOK162_SUPER_COMMAND_BLOCK WaitingTransmitTail;

    //
    // Number of transmit blocks currently free
    //
    UINT                        NumberOfAvailableTransmitBlocks;

    //
    // Total number of transmit blocks/lists
    //
    UINT                        NumberOfTransmitLists;

    //
    // Maximum number of physical buffers that we can handle and still not
    // have to merge the packet
    //
    USHORT                      TransmitThreshold;

    //
    // Flag that when enabled lets routines know that a reset
    // is in progress.
    //
    BOOLEAN                     ResetInProgress;

    //
    // Are we doing the initial initialization?
    //
    BOOLEAN                     InitialInit;

    //
    // Has the initial open completed?
    //
    BOOLEAN                     InitialOpenComplete;

    //
    // Has the initial receive command been sent
    //
    BOOLEAN                     InitialReceiveSent;

    //
    //  Last open error code.
    //
    USHORT                      OpenErrorCode;

    //
    // Reset State
    //
    USHORT                      ResetState;

    //
    // Variables to keep track of the number of retries attempted during
    // a reset
    //
    USHORT                      ResetRetries;
    USHORT                      InitRetries;

    //
    // Result of Reset command
    //
    NDIS_STATUS                 ResetResult;

    //
    // Offsets into adapter memory for different structures.
    // These are obtained at initialization time and the values
    // are read using the READ.ADAPTER DMA command.
    //
    USHORT                      UniversalAddress;
    USHORT                      MicrocodeLevel;
    USHORT                      AdapterAddresses;
    USHORT                      AdapterParms;
    USHORT                      MacBuffer;

    //
    // Buffer for READ.ERROR.LOG
    //
    PTOK162_ERRORLOG            ErrorLog;
    NDIS_PHYSICAL_ADDRESS       ErrorLogPhysical;

    //
    // Buffer for READ.ADAPTER for node addresses. If more info is needed
    // in the future, this will have to be changed as the current addresses
    // are being stored here (func,node,group)
    //
    PTOK162_READADAPTERBUF      AdapterBuf;
    NDIS_PHYSICAL_ADDRESS       AdapterBufPhysical;

    //
    // Counters to hold the various number of errors/statistics for both
    // reception and transmission.
    //
    UINT                        ReceiveCongestionError;
    UINT                        LineError;
    UINT                        LostFrameError;
    UINT                        BurstError;
    UINT                        FrameCopiedError;
    UINT                        TokenError;
    UINT                        InternalError;
    UINT                        ARIFCIError;
    UINT                        AbortDelimeter;
    UINT                        DMABusError;

    //
    // Packet counts
    //
    UINT                        GoodTransmits;
    UINT                        GoodReceives;
    UINT                        TransmitsQueued;
    UINT                        BadTransmits;
    UINT                        BadReceives;

    //
    // Timer objects for TOK162InterruptHandler and TOK162ResetHandler
    //
    NDIS_MINIPORT_TIMER         DeferredTimer;
    NDIS_MINIPORT_TIMER         ResetTimer;

    //
    // Holds number of different types of RING.STATUS.CHANGE
    // indications.
    //
    UINT                        SignalLoss;
    UINT                        HardError;
    UINT                        SoftError;
    UINT                        TransmitBeacon;
    UINT                        LobeWireFault;
    UINT                        AutoRemovalError;
    UINT                        RemoveReceived;
    UINT                        CounterOverflow;
    UINT                        SingleStation;
    UINT                        RingRecovery;

    //
    // Current state of the ring.
    //
    NDIS_802_5_RING_STATE       CurrentRingState;

    //
    //  Last ring status indicated to protocols.
    //
    NDIS_STATUS                 LastNotifyStatus;

    //
    // This is a pointer to the Configuration Block for this
    // adapter.  The Configuration Block will be modified during
    // changes to the packet filter.
    //
    TOK162_CONFIGURATION_BLOCK  ConfigurationBlock;

    //
    // Pointer to the initialization block
    //
    PADAPTER_INITIALIZATION     InitializationBlock;
    NDIS_PHYSICAL_ADDRESS       InitializationBlockPhysical;

    //
    // This points to the next adapter registered for the same Miniport
    //
    LIST_ENTRY                  AdapterList;

} TOK162_ADAPTER,*PTOK162_ADAPTER;

//
// Given a MiniportContextHandle return the PTOK162_ADAPTER
// it represents.
//
#define PTOK162_ADAPTER_FROM_CONTEXT_HANDLE(Handle) \
    ((PTOK162_ADAPTER)(Handle))

//
// This record type is inserted into the MiniportReserved portion
// of the packet header when the packet is going through the
// staged allocation of buffer space prior to the actual send.
//
typedef struct _TOK162_RESERVED {

    //
    // Number of Buffers to move
    //
    UINT                        NdisBuffersToMove;

    //
    // Don't need this part. Reserve it.
    //
    UINT                        Reserved;


} TOK162_RESERVED,*PTOK162_RESERVED;

//
// This macro will return a pointer to the TOK162 reserved portion
// of a packet given a pointer to a packet.
//
#define PTOK162_RESERVED_FROM_PACKET(Packet) \
    ((PTOK162_RESERVED)((Packet)->MiniportReserved))

#include <tok162pr.h>