summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/ibmtok2i/tok162hw.h
blob: d0cf26ab3c0d2822d6f7d646b6a75550b878f037 (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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

    tokhrd.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:

    References to "IBM Spec" refer to the IBM "Supplement to the LAN
    Technical Reference (Token-Ring Network 16/4 Adapter II)" Specification.
    The document number is - SD21-052-00.

    References to "TI Spec" refer to the Texas Instruments "TMS380 Second-
    Generation Token Ring" User's Guide. The document number is - SPWU005.

Revision History:

--*/

//
// Pack everything on word boundaries
//
#include <pshpack2.h>

//
// Define "Physical Addresses" which are ULONG in size. The card
// wants physical addresses.
//
typedef ULONG TOK162_PHYSICAL_ADDRESS, *PTOK162_PHYSICAL_ADDRESS;


//
// The length of an address (network) is 6 bytes
//
#define TOK162_LENGTH_OF_ADDRESS        6

//
// Define a NULL pointer
//
#define TOK162_NULL ((TOK162_PHYSICAL_ADDRESS)(-1L))

//
// Default number of command blocks
//
#define TOK162_NUMBER_OF_CMD_BLOCKS     4

//
// Burst size for transmit and receive DMA. A zero tells the adapter to
// use the size of the transfer as the burst size.
//
// IBM Spec, Page 21

#define TOK162_BURST_SIZE               0

//
// Number of retries to attempt after a DMA error
//
#define TOK162_DMA_RETRIES              0x0303

//
// Minimum packet size for a valid transfer/receive
//
#define MINIMUM_TOKENRING_PACKET_SIZE   32

//
// Default packet header size
//
#define TOK162_HEADER_SIZE              32

//
// TOK162 Receive/Command Block States
//
#define TOK162_STATE_FREE                       ((USHORT)0x0000)
#define TOK162_STATE_EXECUTING                  ((USHORT)0x0001)
#define TOK162_STATE_WAIT_FOR_ADAPTER           ((USHORT)0x0002)

//
// Start of I/O ports based on switch settings.
//
// IBM Spec, Page 9.
//
#define BASE_OPTION_ZERO                  0x86A0
#define BASE_OPTION_ONE                   0xC6A0
#define BASE_OPTION_TWO                   0xA6A0
#define BASE_OPTION_THREE                 0xE6A0
#define BASE_OPTION_FOUR                  0x96A0
#define BASE_OPTION_FIVE                  0xD6A0
#define BASE_OPTION_SIX                   0xB6A0
#define BASE_OPTION_SEVEN                 0xF6A0

//
// Offsets from above of the actual ports used.
//
// IBM Spec, Page 4.
//
#define PORT_OFFSET_DATA                  0x0000
#define PORT_OFFSET_DATA_AUTO_INC         0x0002
#define PORT_OFFSET_ADDRESS               0x0004
#define PORT_OFFSET_STATUS                0x0006
#define PORT_OFFSET_COMMAND               0x0006
#define PORT_OFFSET_ADAPTER_RESET         0x0008
#define PORT_OFFSET_ADAPTER_ENABLE        0x000A
#define PORT_OFFSET_SWITCH_INT_DISABLE    0x000C
#define PORT_OFFSET_SWITCH_INT_ENABLE     0x000E

//
// Macro to write a ULONG variable to a register on the adapter
//
#define WRITE_ADAPTER_ULONG(a, p, v) \
    NdisRawWritePortUshort((ULONG) (a)->PortIOAddress + (p), \
                            (ULONG) (v))

//
// Macro to read a ULONG variable from a register on the adapter
//
#define READ_ADAPTER_ULONG(a, p, v) \
    NdisRawReadPortUshort((ULONG) (a)->PortIOAddress + (p), \
                           (PULONG) (v))

//
// Macro to write a USHORT variable to a register on the adapter
//
#define WRITE_ADAPTER_USHORT(a, p, v) \
    NdisRawWritePortUshort((ULONG) (a)->PortIOAddress + (p), \
                            (USHORT) (v))

//
// Macro to read a USHORT variable from a register on the adapter
//
#define READ_ADAPTER_USHORT(a, p, v) \
    NdisRawReadPortUshort((ULONG) (a)->PortIOAddress + (p), \
                           (PUSHORT) (v))

//
// Macro to write a CHAR variable to a register on the adapter
//
#define WRITE_ADAPTER_UCHAR(a, p, v) \
    NdisRawWritePortUchar((ULONG)(a)->PortIOAddress + (p), \
                          (UCHAR)(v))

//
// Macro to read a ULONG variable from a register on the adapter
//
#define READ_ADAPTER_UCHAR(a, p, v) \
    NdisRawReadPortUchar((ULONG)(a)->PortIOAddress + (p), \
                          (PUCHAR)(v))

//
// Masks for the command register
//
// IBM Spec, Pages 5-6.
//
#define CMD_PIO_INTERRUPT                 0x8000
#define CMD_PIO_RESET                     0x4000
#define CMD_PIO_SSB_CLEAR                 0x2000
#define CMD_PIO_EXECUTE                   0x1000
#define CMD_PIO_SCB_REQUEST               0x0800
#define CMD_PIO_RCV_CONTINUE              0x0400
#define CMD_PIO_RCV_VALID                 0x0200
#define CMD_PIO_XMIT_VALID                0x0100
#define CMD_PIO_RESET_SYSTEM              0x0080

//
// Common mask combinations
//
#define EXECUTE_SCB_COMMAND               0x9080  // int+exec+resetsysint
#define ENABLE_SSB_UPDATE                 0xA000  // int+ssbclear
#define ENABLE_RECEIVE_VALID              0x8200  // int+rcvvalid

//
// Masks for the status register.
//
// IBM Spec, Pages 6-7.
//
#define STATUS_ADAPTER_INTERRUPT          0x8000
#define STATUS_SYSTEM_INTERRUPT           0x0080

//
// Masks for adapter interrupts.
//
// IBM Spec, Page 7.
//
#define STATUS_INT_CODE_MASK              0x000F
#define STATUS_INT_CODE_CHECK             0x0000
#define STATUS_INT_CODE_IMPL              0x0002
#define STATUS_INT_CODE_RING              0x0004
#define STATUS_INT_CODE_SCB_CLEAR         0x0006
#define STATUS_INT_CODE_CMD_STATUS        0x0008
#define STATUS_INT_CODE_RECEIVE_STATUS    0x000A
#define STATUS_INT_CODE_XMIT_STATUS       0x000C

//
// My Mask for System Interrupts
//
#define MASK_ADAPTER_CHECK              0x0001
#define MASK_RING_STATUS                0x0002
#define MASK_SCB_CLEAR                  0x0004
#define MASK_COMMAND_STATUS             0x0008
#define MASK_RECEIVE_STATUS             0x0010
#define MASK_TRANSMIT_STATUS            0x0020


//
// Adapter switch structure. The switches determine the configuration of the
// card.
//
// IBM Spec, Page 8.
//
typedef struct _ADAPTERSWITCHES {

    //
    // Connector Type.
    //
    USHORT UTP_STP:1;

    //
    // Token Ring Speed
    //
    USHORT RingSpeed:1;

    //
    // DMA Channel
    //
    USHORT DMA:2;

    //
    // Is Remote Program Load enabled?
    //
    USHORT RPL:1;

    //
    // Adapter mode, test or normal
    //
    USHORT AdapterMode:1;

    //
    // Adapter wait state
    //
    USHORT WaitState:1;

    //
    // Interrupt Request Level
    //
    USHORT IntRequest:2;

    //
    // RPL address (if RPL enabled) or adapter I/O base address
    //
    USHORT RPL_PIO_Address:3;

    //
    // Not used.
    //
    USHORT Reserved:4;
} ADAPTERSWITCHES,*PADAPTERSWITCHES;

//
// #defines for the I/O Address switches
//
// IBM Spec, Page 9.
//
#define SW_PIO_ADDR_8                     0x00
#define SW_PIO_ADDR_C                     0x01
#define SW_PIO_ADDR_A                     0x02
#define SW_PIO_ADDR_E                     0x03
#define SW_PIO_ADDR_9                     0x04
#define SW_PIO_ADDR_D                     0x05
#define SW_PIO_ADDR_B                     0x06
#define SW_PIO_ADDR_F                     0x07

//
// #defines for the interrupt request level
//
// IBM Spec, Page 9.
//
#define SW_INT_9                          0x00
#define SW_INT_11                         0x01
#define SW_INT_10                         0x02
#define SW_INT_15                         0x03

//
// #defines for the wait state.
//
// IBM Spec, Page 9.
//
#define SW_WAITSTATE_NORMAL               0x00
#define SW_WAITSTATE_FAST                 0x01

//
// #defines for the adapter mode.
//
// IBM Spec, Page 10.
//
#define SW_ADAPTERMODE_NORMAL             0x00
#define SW_ADAPTERMODE_TEST               0x01

//
// #defines for RPL
//
// IBM Spec, Page 10.
//
#define SW_RPL_DISABLE                    0x00
#define SW_RPL_ENABLE                     0x01

//
// #defines for the DMA channel
//
// IBM Spec, Page 10.
//
#define SW_DMA_5                          0x00
#define SW_DMA_7                          0x01
#define SW_DMA_6                          0x02

//
// #defines for the ring speed.
//
// IBM Spec, Page 10.
//
#define SW_RINGSPEED_4                    0x00
#define SW_RINGSPEED_16                   0x01

//
// #defines for the connector interface.
//
// IBM Spec, Page 10.
//
#define SW_STP                            0x00
#define SW_UTP                            0x01

//
// DMA Command Values
//
// IBM Spec, Page 25.
//
#define CMD_DMA_OPEN                      0x0300
#define CMD_DMA_XMIT                      0x0400
#define CMD_DMA_XMIT_HALT                 0x0500
#define CMD_DMA_RCV                       0x0600
#define CMD_DMA_CLOSE                     0x0700
#define CMD_DMA_SET_GRP_ADDR              0x0800
#define CMD_DMA_SET_FUNC_ADDR             0x0900
#define CMD_DMA_READ_ERRLOG               0x0A00
#define CMD_DMA_READ                      0x0B00
#define CMD_DMA_IMPL_ENABLE               0x0C00
#define CMD_DMA_START_STOP_TRACE          0x0D00

//
// System Command Block structure.
//
// IBM Spec, Pages 13-14.
//
typedef struct _SCB {

    //
    // Command to be submitted to the card.
    //
    USHORT  Command;

    //
    // Parameter USHORTs, different for different commands.
    //
    USHORT  Parm1;
    USHORT  Parm2;

} SCB, *PSCB;

//
// Generic System Status Block Structure.
//
// IBM Spec, Page 15.
//
typedef struct _SSB {

    //
    // Command for which status is returned.
    //
    USHORT  Command;

    //
    // Status USHORTs, different for different commands
    //
    USHORT  Status1;
    USHORT  Status2;
    USHORT  Status3;

} SSB, *PSSB;

//
// Ring Status SSB #defines and structure
//
// IBM Spec, Page 15-16.
//
typedef struct _SSB_RING_STATUS {

    //
    // Command code, will be SSB_CMD_RING_STATUS
    //
    USHORT  Command;

    //
    // Ring Status code, as defined below.
    //
    USHORT  RingStatus;

    //
    // Last two not used.
    //
    USHORT  Reserved1;
    USHORT  Reserved2;

} SSB_RING_STATUS,*PSSB_RING_STATUS;

#define SSB_CMD_RING_STATUS               0x0100

#define RING_STATUS_OVERFLOW              0x8000
#define RING_STATUS_SINGLESTATION         0x4000
#define RING_STATUS_RINGRECOVERY          0x2000
#define RING_STATUS_SIGNAL_LOSS           0x0080
#define RING_STATUS_HARD_ERROR            0x0040
#define RING_STATUS_SOFT_ERROR            0x0020
#define RING_STATUS_XMIT_BEACON           0x0010
#define RING_STATUS_LOBE_WIRE_FAULT       0x0008
#define RING_STATUS_AUTO_REMOVE_1         0x0004
#define RING_STATUS_REMOVE_RECEIVED       0x0001

//
// Command Reject Status SSB #defines and structure
//
typedef struct _SSB_CMD_REJECT_STATUS {

    //
    // Command code, will be SSB_CMD_COMMAND_REJECT_STATUS
    //
    USHORT  Command;

    //
    // Reason for rejection, as defined below.
    //
    USHORT  Reason;

    //
    // Command that was rejected.
    //
    USHORT  SCBCommand;

    //
    // Not used.
    //
    USHORT  Reserved;

} SSB_CMD_REJECT_STATUS, *PSSB_CMD_REJECT_STATUS;

#define SSB_CMD_COMMAND_REJECT_STATUS     0x0200

#define CMD_REJECT_STATUS_BAD_CMD         0x0080
#define CMD_REJECT_STATUS_BAD_ADDR        0x0040
#define CMD_REJECT_STATUS_BAD_OPEN        0x0020
#define CMD_REJECT_STATUS_BAD_CLOSED      0x0010
#define CMD_REJECT_STATUS_BAD_SAME        0x0008

//
// Adapter Check Port information, structure and defines
//
// IBM Spec, Pages 18-19.
//

//
// Offsets within the adapter memory where the values for the check can
// be obtained.
//
// IBM Spec, Page 18.
//
#define ADAPTER_CHECK_PORT_OFFSET_BASE    0x05E0
#define ADAPTER_CHECK_PORT_OFFSET_PARM0   0x05E2
#define ADAPTER_CHECK_PORT_OFFSET_PARM1   0x05E4
#define ADAPTER_CHECK_PORT_OFFSET_PARM2   0x05E6

//
// Structure that can be used to gather all of the adapter check information.
//
typedef struct _ADAPTER_CHECK {

    //
    // USHORT indicating why the adapter check occurred. Reasons are defined
    // below.
    //
    USHORT  Check;

    //
    // The parameters are used based on the reason above. Please see the spec
    // as to what the different parameters are for the given reason.
    //
    USHORT  Parm0;
    USHORT  Parm1;
    USHORT  Parm2;

} ADAPTER_CHECK, *PADAPTER_CHECK;

#define ADAPTER_CHECK_DMA_ABORT_READ      0x4000
#define ADAPTER_CHECK_DMA_ABORT_WRITE     0x2000
#define ADAPTER_CHECK_ILLEGAL_OPCODE      0x1000
#define ADAPTER_CHECK_PARITY_ERR          0x0800
#define ADAPTER_CHECK_PARITY_ERR_EXT      0x0400
#define ADAPTER_CHECK_PARITY_ERR_SIM      0x0200 // System Interface Master
#define ADAPTER_CHECK_PARITY_ERR_PHM      0x0100 // Protocol Handler Master
#define ADAPTER_CHECK_PARITY_ERR_RR       0x0080 // Ring Receive
#define ADAPTER_CHECK_PARITY_ERR_RXMT     0x0040 // Ring Transmit
#define ADAPTER_CHECK_RING_UNDERRUN       0x0020
#define ADAPTER_CHECK_RING_OVERRUN        0x0010
#define ADAPTER_CHECK_INVALID_INT         0x0008
#define ADAPTER_CHECK_INVALID_ERR_INT     0x0004
#define ADAPTER_CHECK_INVALID_XOP         0x0002
#define ADAPTER_CHECK_PROGRAM_CHECK       0x0001

//
// Initialization Structure.
//
// IBM Spec, Pages 19-25.
//

//
// This structure needs to be packed on a two-byte boundary or the
// SCB pointer will be off during the loop that sends the initialization
// bytes to the card.
//

typedef struct _ADAPTER_INITIALIZATION {

    //
    // Initialization options as defined below
    //
    USHORT Options;

    //
    // Reserved USHORTs
    //
    USHORT Reserved1;
    USHORT Reserved2;
    USHORT Reserved3;

    //
    // Size of DMA bursts on receives
    //
    USHORT ReceiveBurstSize;

    //
    // Size of DMA bursts on transmits
    //
    USHORT TransmitBurstSize;

    //
    // Number of retries on DMA errors before giving up
    //
    USHORT DMAAbortThresholds;

    //
    // Pointer to the SCB (physical pointer), split into two words
    // because we are writing them to the adaper in words
    //
    USHORT SCBHigh;
    USHORT SCBLow;

    //
    // Pointer to the SSB (physical pointer), split into words because
    // we are writing them to the adapter in words
    //
    USHORT SSBHigh;
    USHORT SSBLow;

} ADAPTER_INITIALIZATION, *PADAPTER_INITIALIZATION;

//
// Initialization options
//
#define INIT_OPTIONS_RESERVED             0x8000
#define INIT_OPTIONS_SCBSSB_BURST         0x1000
#define INIT_OPTIONS_SCBSSB_CYCLE         0x0000
#define INIT_OPTIONS_LIST_BURST           0x0800
#define INIT_OPTIONS_LIST_CYCLE           0x0000
#define INIT_OPTIONS_LIST_STATUS_BURST    0x0400
#define INIT_OPTIONS_LIST_STATUS_CYCLE    0x0000
#define INIT_OPTIONS_RECEIVE_BURST        0x0200
#define INIT_OPTIONS_RECEIVE_CYCLE        0x0000
#define INIT_OPTIONS_XMIT_BURST           0x0100
#define INIT_OPTIONS_XMIT_CYCLE           0x0000
#define INIT_OPTIONS_SPEED_16             0x0040
#define INIT_OPTIONS_SPEED_4              0x0000
#define INIT_OPTIONS_DISABLE_ETR          0x0020
#define INIT_OPTIONS_ENABLE_ETR           0x0000

//
// Starting address on card of where to write the init block
//
// IBM Spec, Page 22.
//
#define INIT_ADAPTER_PORT_OFFSET          0x0200

//
// Value to write to the command register after the init block has been
// downloaded.
//
#define INIT_ADAPTER_INTERRUPT            0x9080

//
// Bit masks for initialization results.
//
// IBM Spec, Page 23.
//
#define STATUS_INIT_INITIALIZE            0x0040
#define STATUS_INIT_TEST                  0x0020
#define STATUS_INIT_ERROR                 0x0010

//
// Bring-Up Error Codes
//
// IBM Spec, Pages 23-24
//
#define BRING_UP_ERR_INIT_TEST            0x0000
#define BRING_UP_ERR_CRC                  0x0001
#define BRING_UP_ERR_RAM                  0x0002
#define BRING_UP_ERR_INSTRUCTION_TEST     0x0003
#define BRING_UP_ERR_INT_TEST             0x0004
#define BRING_UP_ERR_PROTOCOL_HANDLER     0x0005
#define BRING_UP_ERR_SYSTEM_INTERFACE_REG 0x0006

//
// Initialize Error Codes
//
// IBM Spec, Page 24.
//
#define INITIALIZE_ERR_PARM_LEN           0x0001
#define INITIALIZE_ERR_INV_OPTIONS        0x0002
#define INITIALIZE_ERR_INV_RCV_BURST      0x0003
#define INITIALIZE_ERR_INV_XMIT_BURST     0x0004
#define INITIALIZE_ERR_INV_DMA_ABORT      0x0005
#define INITIALIZE_ERR_INV_SCB            0x0006
#define INITIALIZE_ERR_INV_SSB            0x0007
#define INITIALIZE_ERR_DMA_TIMEOUT        0x0009
#define INITIALIZE_ERR_DMA_BUS            0x000B
#define INITIALIZE_ERR_DMA_DATA           0x000C
#define INITIALIZE_ERR_ADAPTER_CHECK      0x000D

//
// Recommended burst sizes.
//
// IBM Spec, Page 25.
//
#define DEFAULT_BURST_SIZE_FAST           0x004C
#define DEFAULT_BURST_SIZE_NORMAL         0x0040

//
// TOK162 ErrorLog structure.
//
// IBM Spec, Page 35.
//
typedef struct _TOK162_ERRORLOG {

    //
    // These are error count fields. The adapter resets the internal
    // counters after they are read into this structure.
    //
    UCHAR   LineError;
    UCHAR   InternalError;
    UCHAR   BurstError;
    UCHAR   ARIFCIError;
    UCHAR   AbortDelimeter;
    UCHAR   Reserved1;
    UCHAR   LostFrameError;
    UCHAR   ReceiveCongestionError;
    UCHAR   FrameCopiedError;
    UCHAR   Reserved2;
    UCHAR   TokenError;
    UCHAR   Reserved3;
    UCHAR   DMABusError;
    UCHAR   Reserved4;

} TOK162_ERRORLOG, *PTOK162_ERRORLOG;

//
// TOK162 Read Adapter Log structure. Used to get permanent address, current
// addresses (network, group, functional), the microcode level, and the MAC
// buffer.
//
// IBM Spec, Pages 32-33.
//
typedef struct _TOK162_READADAPTERBUF {

    //
    // Number of bytes to be read from the adapter
    //
    USHORT  DataCount;

    //
    // Offset for buffer
    //
    USHORT  DataAddress;

    //
    // Buffer space
    //
    UCHAR   BufferSpace[68-6];

} TOK162_READADAPTERBUF, *PTOK162_READADAPTERBUF;

//
// TOK162 Address Block
//
// IBM Spec, Page 33.
//
typedef struct _TOK162_ADDRESSBLOCK {

    //
    // The node address. Used for both the current address and the permanent
    // address (depending on the read call).
    //
    UCHAR   NodeAddress[6];

    //
    // The current group address.
    //
    UCHAR   GroupAddress[4];

    //
    // The current functional address.
    //
    UCHAR   FunctionalAddress[4];

} TOK162_ADDRESSBLOCK, *PTOK162_ADDRESSBLOCK;

//
// TOK162 Receive List
//
// IBM Spec, Pages 36-40.
//
typedef struct _TOK162_RECEIVE_LIST {

    //
    // This is the physical address of the next entry
    // in the Receive Ring.
    //
    TOK162_PHYSICAL_ADDRESS ForwardPointer;

    //
    // List entry characteristics
    //
    USHORT CSTAT;

    //
    // This is the total size of the received frame.
    //
    USHORT FrameSize;

    //
    // This is the length (in bytes) of the buffer associated. IBM Format.
    //
    USHORT DataCount1;

    //
    // This is the address of the buffer associated. IBM Format.
    //
    ULONG   PhysicalAddress1;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount2;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    ULONG   PhysicalAddress2;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount3;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    ULONG   PhysicalAddress3;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount4;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    ULONG   PhysicalAddress4;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCoun5;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    ULONG   PhysicalAddress5;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount6;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    ULONG   PhysicalAddress6;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount7;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    ULONG   PhysicalAddress7;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount8;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    ULONG   PhysicalAddress8;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount9;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    ULONG   PhysicalAddress9;

} TOK162_RECEIVE_LIST, *PTOK162_RECEIVE_LIST;

//
// Receive and Transmit buffer sizes, depending on the ring speed.
//
// IBM Spec, Page 13.
//
#define RECEIVE_LIST_BUFFER_SIZE_4        4500
#define RECEIVE_LIST_BUFFER_SIZE_16       17986

//
// The number of receive lists/buffers
//
#define RECEIVE_LIST_COUNT                3

//
// Receive CSTAT bit masks
//
// IBM Spec, Pages 38-39.
//
#define RECEIVE_CSTAT_REQUEST_RESET       0x0088   // Valid bit + frame int
#define RECEIVE_CSTAT_VALID               0x0080   // Valid bit

//
// Transmit list entry. This is exactly like the receive list entry.
//
// IBM Spec, Pages 46-55.
//
typedef struct _TOK162_TRANSMIT_LIST {

    //
    // This is the physical address of the next entry
    // in the Transmit Chain.
    //
    TOK162_PHYSICAL_ADDRESS ForwardPointer;

    //
    // List entry characteristics. IBM Format.
    //
    USHORT CSTAT;

    //
    // This is the total size of the received frame. IBM Format.
    //
    USHORT FrameSize;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount1;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress1;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount2;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress2;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount3;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress3;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount4;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress4;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCoun5;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress5;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount6;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress6;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount7;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress7;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount8;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress8;

    //
    // This is the length (in bytes) of this block. Stored in IBM format
    //
    USHORT DataCount9;

    //
    // This is the physical address of this block. Stored in IBM Format
    //
    TOK162_PHYSICAL_ADDRESS PhysicalAddress9;

} TOK162_TRANSMIT_LIST, *PTOK162_TRANSMIT_LIST;

//
// The number of transmit lists
//
#define TRANSMIT_LIST_COUNT               0x0002

//
// The maximum number of transmit list scatter-gathers
//
#define TOK162_MAX_SG                     0x0003

//
// Transmit CSTAT bit masks
//
#define TRANSMIT_CSTAT_REQUEST            0x00B0
#define TRANSMIT_CSTAT_XMIT_ERROR         0x0004

//
// TOK162 Command Block. Contains all of the fields necessary to support
// both commands and transmits.
//
typedef struct _TOK162_COMMAND_BLOCK {

    //
    // Transmit List Entry
    //
    TOK162_TRANSMIT_LIST TransmitEntry;

    //
    // This is the state of this Command Block.
    //
    USHORT State;

    //
    // This is the status of this Command Block.
    //
    USHORT Status;

    //
    // This is the physical address of the next Command Block
    // to be executed.  If this address == -1, then there are
    // no more commands to be executed.
    //
    UNALIGNED TOK162_PHYSICAL_ADDRESS NextPending;

    //
    // This is the TOK162 Command Code.
    //
    USHORT CommandCode;

    //
    // Pointer used by different commands
    //
    ULONG   ParmPointer;

    //
    // This is the immediate data to be used by all commands
    // other than transmit.
    //
    ULONG ImmediateData;

} TOK162_COMMAND_BLOCK, *PTOK162_COMMAND_BLOCK;


//
// Data block pointer
// Used only to reference the different fields of the transmit list entry.
// Allows code to access the transmit list entries in a for loop rather than
// having code for each specific entry.
//
// Must be packed on a 2 byte boundary.
//
typedef struct _TOK162_DATA_BLOCK {

    //
    // size of the block. IBM format.
    //
    USHORT Size;

    //
    // physical pointer to the buffer. IBM format.
    //
    TOK162_PHYSICAL_ADDRESS IBMPhysicalAddress;

} TOK162_DATA_BLOCK,*PTOK162_DATA_BLOCK;

//
// Numerical values for switches
// (e.g. - Interrupt 5 instead of 00 [switch value])
//
// IBM Spec, Pages 8-10.
//

//
// Adapter mode values
//
#define CFG_ADAPTERMODE_NORMAL            0x0000
#define CFG_ADAPTERMODE_TEST              0x0001

//
// Wait state values
//
#define CFG_WAITSTATE_NORMAL              0x0000
#define CFG_WAITSTATE_FAST                0x0001

//
// DMA channel values
//
#define CFG_DMACHANNEL_5                  0x0005
#define CFG_DMACHANNEL_6                  0x0006
#define CFG_DMACHANNEL_7                  0x0007

//
// Connector type values
//
#define CFG_MEDIATYPE_STP                 0x0000
#define CFG_MEDIATYPE_UTP                 0x0001

//
// Adapter interrupt values
//
#define CFG_INT_9                         0x0009
#define CFG_INT_10                        0x000A
#define CFG_INT_11                        0x000B
#define CFG_INT_15                        0x000F

//
// RPL address values
//
#define CFG_RPLADDR_C0000                 0xC0000
#define CFG_RPLADDR_C4000                 0xC4000
#define CFG_RPLADDR_C8000                 0xC8000
#define CFG_RPLADDR_CC000                 0xCC000
#define CFG_RPLADDR_D0000                 0xD0000
#define CFG_RPLADDR_D4000                 0xD4000
#define CFG_RPLADDR_D8000                 0xD8000
#define CFG_RPLADDR_DC000                 0xDC000

//
// Ring speed values
//
#define CFG_RINGSPEED_4                   0x0004
#define CFG_RINGSPEED_16                  0x0010

//
// command and result structures
//

//
// Open command structure. Submitted to the card to insert the system in
// the Token Ring.
//
// IBM Spec, Pages 27-32.
//
typedef struct _OPEN_COMMAND {

    //
    // Open options. Defined below.
    //
    USHORT  Options;

    //
    // Address to insert ourselves into the ring under.
    //
    UCHAR   NodeAddress[6];

    //
    // Group address adapter should respond to.
    //
    ULONG   GroupAddress;

    //
    // Functional address adapter should respond to.
    //
    ULONG   FunctionalAddress;

    //
    // Size of the receive list structure
    //
    USHORT  ReceiveListSize;
    //
    // Size of the transmit list structure
    //
    USHORT  TransmitListSize;

    //
    // Adapter buffer size.
    //
    USHORT  BufferSize;

    //
    // Unused.
    //
    USHORT  Reserved1;
    USHORT  Reserved2;

    //
    // Minimum number of buffers to reserve for transmits
    //
    UCHAR   TransmitBufCountMin;

    //
    // Maximum number of buffers to reserve for transmits
    //
    UCHAR   TransmitBufCountMax;

    //
    // Pointer to the system product ID
    //
    ULONG   ProdIDAddress;

} OPEN_COMMAND, *POPEN_COMMAND;

#define OPEN_OPTION_PASS_BEACON_FRAMES    0x8000
#define OPEN_OPTION_DISABLE_DMA_TIMEOUT   0x4000
#define OPEN_OPTION_ENABLE_DMA_TIMEOUT    0x0000
#define OPEN_OPTION_WRAP_INTERFACE        0x0080
#define OPEN_OPTION_DISABLE_HARD_ERROR    0x0040
#define OPEN_OPTION_ENABLE_HARD_ERROR     0x0000
#define OPEN_OPTION_DISABLE_SOFT_ERROR    0x0020
#define OPEN_OPTION_ENABLE_SOFT_ERROR     0x0000
#define OPEN_OPTION_PASS_ADAPTER_FRAMES   0x0010
#define OPEN_OPTION_PASS_ATTENTION_FRAMES 0x0008
#define OPEN_OPTION_PAD_ROUTING_FIELD     0x0004
#define OPEN_OPTION_FRAME_HOLD            0x0002
#define OPEN_OPTION_CONTENDER             0x0001

//
// Values to set the open parameters to
//
#define OPEN_RECEIVE_LIST_SIZE            0x000e
#define OPEN_TRANSMIT_LIST_SIZE           0x001A
#define OPEN_BUFFER_SIZE                  512

//
// Open completion structure (SSB)
//
// IBM Spec, Pages 31-32.
//
typedef struct _OPEN_COMPLETION {

    //
    // Better be CMD_DMA_OPEN.
    //
    USHORT  Command;

    //
    // Completion code. Bitmasks defined below.
    //
    USHORT  Completion;

    //
    // Not used.
    //
    USHORT  Reserved1;
    USHORT  Reserved2;

} OPEN_COMPLETION, *POPEN_COMPLETION;

#define OPEN_COMPLETION_MASK_PHASE        0xF000
#define OPEN_COMPLETION_MASK_ERROR        0x0F00
#define OPEN_COMPLETION_MASK_RESULT       0x00FF

#define OPEN_COMPLETION_PHASE_LOBE        0x1000
#define OPEN_COMPLETION_PHASE_INSERTION   0x2000
#define OPEN_COMPLETION_PHASE_VERIFY      0x3000
#define OPEN_COMPLETION_PHASE_RING        0x4000
#define OPEN_COMPLETION_PHASE_PARMS       0x5000

#define OPEN_COMPLETION_ERROR_FUNCTION    0x0100
#define OPEN_COMPLETION_ERROR_SIGLOSS     0x0200
#define OPEN_COMPLETION_ERROR_TIMEOUT     0x0500
#define OPEN_COMPLETION_ERROR_RINGFAIL    0x0600
#define OPEN_COMPLETION_ERROR_RINGBEACON  0x0700
#define OPEN_COMPLETION_ERROR_DUPLICATE   0x0800
#define OPEN_COMPLETION_ERROR_REQPARMS    0x0900
#define OPEN_COMPLETION_ERROR_REMOVE_REC  0x0A00
#define OPEN_COMPLETION_ERROR_IMPL_REC    0x0B00
#define OPEN_COMPLETION_ERROR_DUPMOD      0x0C00

#define OPEN_RESULT_ADAPTER_OPEN          0x0080
#define OPEN_RESULT_NODE_ADDR_ERROR       0x0040
#define OPEN_RESULT_LIST_SIZE_ERROR       0x0020
#define OPEN_RESULT_BUF_SIZE_ERROR        0x0010
#define OPEN_RESULT_EXT_RAM_ERROR         0x0008
#define OPEN_RESULT_XMIT_CNT_ERROR        0x0004
#define OPEN_RESULT_OPEN_ERROR            0x0002

//
// The adapter requires many of the WORD values and almost all of the
// DWORD values to be in IBM format, versus Intel Format. The difference
// between the two is as follows:
//
// If you are storing the value 0x1234, a word value, memory would look like:
//
//              ---------     ---------
//             |         |   |         |
//   Intel     |   34    |   |   12    |
//             |         |   |         |
//              ---------     ---------
// Address        100            101
//
//
//              ---------     ---------
//             |         |   |         |
//   IBM       |   12    |   |   34    |
//             |         |   |         |
//              ---------     ---------
// Address        100            101
//
//
// If you are storing the value 0x12345678, a dword value, memory would look
// like:
//
//              ---------     ---------     ---------     ---------
//             |         |   |         |   |         |   |         |
//   Intel     |   78    |   |   56    |   |   34    |   |   12    |
//             |         |   |         |   |         |   |         |
//              ---------     ---------     ---------     ---------
// Address        100            101
//
//
//              ---------     ---------     ---------     ---------
//             |         |   |         |   |         |   |         |
//   IBM       |   12    |   |   34    |   |   56    |   |   78    |
//             |         |   |         |   |         |   |         |
//              ---------     ---------     ---------     ---------
// Address        100            101
//
//
// To convert "Intel" WORDs and DWORDs to "IBM" format, the following macros
// are used.
//

//
// Macro to byte swap a word.
//
#define BYTE_SWAP(_word) (\
            (USHORT) (((_word) >> 8) | ((_word) << 8)) )

//
// Macro to byte swap a word.
//
#define WORD_SWAP(_dword) (\
            (ULONG) (((_dword) >> 16) | ((_dword) << 16)) )

//
// Macro to get low byte of a word.
//
#define LOW_BYTE(_word) (\
            (UCHAR) ((_word) & 0x00FF) )

//
// Macro to get high byte of a word.
//
#define HIGH_BYTE(_word) (\
            (UCHAR) (((_word) >> 8) & 0x00FF) )

//
// Macro to get low word of a dword.
//
#define LOW_WORD(_dword) (\
            (USHORT) ((_dword) & 0x0000FFFF) )

//
// Macro to get high word of a dword.
//
#define HIGH_WORD(_dword) (\
            (USHORT) (((_dword) >> 16) & 0x0000FFFF) )

//
// Macro to create a dword from two words.
//
#define MAKE_LONG(_highword,_lowword) (\
            (ULONG) ((((ULONG)_highword) << 16) + _lowword))

//
// Macro to byte swap a dword.
//
#define BYTE_SWAP_ULONG(_ulong) (\
    (ULONG)((ULONG)(BYTE_SWAP(LOW_WORD(_ulong)) << 16) + \
             BYTE_SWAP(HIGH_WORD(_ulong))))

//
// End the packing
//
#include <poppack.h>