summaryrefslogblamecommitdiff
path: root/drivers/scsi/bfa/include/protocol/scsi.h
blob: b220e6b4f6e1e12798448b26e87a1b2a5f0243bc (plain) (tree)
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
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                
/*
 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
 * All rights reserved
 * www.brocade.com
 *
 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License (GPL) Version 2 as
 * published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

#ifndef __SCSI_H__
#define __SCSI_H__

#include <protocol/types.h>

#pragma pack(1)

/*
 * generic SCSI cdb definition
 */
#define SCSI_MAX_CDBLEN     16
struct scsi_cdb_s{
	u8         scsi_cdb[SCSI_MAX_CDBLEN];
};

/*
 * scsi lun serial number definition
 */
#define SCSI_LUN_SN_LEN     32
struct scsi_lun_sn_s{
	u8         lun_sn[SCSI_LUN_SN_LEN];
};

/*
 * SCSI Direct Access Commands
 */
enum {
	SCSI_OP_TEST_UNIT_READY		= 0x00,
	SCSI_OP_REQUEST_SENSE		= 0x03,
	SCSI_OP_FORMAT_UNIT		= 0x04,
	SCSI_OP_READ6			= 0x08,
	SCSI_OP_WRITE6			= 0x0A,
	SCSI_OP_WRITE_FILEMARKS		= 0x10,
	SCSI_OP_INQUIRY			= 0x12,
	SCSI_OP_MODE_SELECT6		= 0x15,
	SCSI_OP_RESERVE6		= 0x16,
	SCSI_OP_RELEASE6		= 0x17,
	SCSI_OP_MODE_SENSE6		= 0x1A,
	SCSI_OP_START_STOP_UNIT		= 0x1B,
	SCSI_OP_SEND_DIAGNOSTIC		= 0x1D,
	SCSI_OP_READ_CAPACITY		= 0x25,
	SCSI_OP_READ10			= 0x28,
	SCSI_OP_WRITE10			= 0x2A,
	SCSI_OP_VERIFY10		= 0x2F,
	SCSI_OP_READ_DEFECT_DATA	= 0x37,
	SCSI_OP_LOG_SELECT		= 0x4C,
	SCSI_OP_LOG_SENSE		= 0x4D,
	SCSI_OP_MODE_SELECT10		= 0x55,
	SCSI_OP_RESERVE10		= 0x56,
	SCSI_OP_RELEASE10		= 0x57,
	SCSI_OP_MODE_SENSE10		= 0x5A,
	SCSI_OP_PER_RESERVE_IN		= 0x5E,
	SCSI_OP_PER_RESERVE_OUR		= 0x5E,
	SCSI_OP_READ16			= 0x88,
	SCSI_OP_WRITE16			= 0x8A,
	SCSI_OP_VERIFY16		= 0x8F,
	SCSI_OP_READ_CAPACITY16		= 0x9E,
	SCSI_OP_REPORT_LUNS		= 0xA0,
	SCSI_OP_READ12			= 0xA8,
	SCSI_OP_WRITE12			= 0xAA,
	SCSI_OP_UNDEF			= 0xFF,
};

/*
 * SCSI START_STOP_UNIT command
 */
struct scsi_start_stop_unit_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         lun:3;
	u8         reserved1:4;
	u8         immed:1;
#else
	u8         immed:1;
	u8         reserved1:4;
	u8         lun:3;
#endif
	u8         reserved2;
	u8         reserved3;
#ifdef __BIGENDIAN
	u8         power_conditions:4;
	u8         reserved4:2;
	u8         loEj:1;
	u8         start:1;
#else
	u8         start:1;
	u8         loEj:1;
	u8         reserved4:2;
	u8         power_conditions:4;
#endif
	u8         control;
};

/*
 * SCSI SEND_DIAGNOSTIC command
 */
struct scsi_send_diagnostic_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         self_test_code:3;
	u8         pf:1;
	u8         reserved1:1;
	u8         self_test:1;
	u8         dev_offl:1;
	u8         unit_offl:1;
#else
	u8         unit_offl:1;
	u8         dev_offl:1;
	u8         self_test:1;
	u8         reserved1:1;
	u8         pf:1;
	u8         self_test_code:3;
#endif
	u8         reserved2;

	u8         param_list_length[2];	/* MSB first */
	u8         control;

};

/*
 * SCSI READ10/WRITE10 commands
 */
struct scsi_rw10_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         lun:3;
	u8         dpo:1;	/* Disable Page Out */
	u8         fua:1;	/* Force Unit Access */
	u8         reserved1:2;
	u8         rel_adr:1;	/* relative address */
#else
	u8         rel_adr:1;
	u8         reserved1:2;
	u8         fua:1;
	u8         dpo:1;
	u8         lun:3;
#endif
	u8         lba0;	/* logical block address - MSB */
	u8         lba1;
	u8         lba2;
	u8         lba3;	/* LSB */
	u8         reserved3;
	u8         xfer_length0;	/* transfer length in blocks - MSB */
	u8         xfer_length1;	/* LSB */
	u8         control;
};

#define SCSI_CDB10_GET_LBA(cdb)                     \
    (((cdb)->lba0 << 24) | ((cdb)->lba1 << 16) |    \
     ((cdb)->lba2 << 8) | (cdb)->lba3)

#define SCSI_CDB10_SET_LBA(cdb, lba) {      \
    (cdb)->lba0 = lba >> 24;            \
    (cdb)->lba1 = (lba >> 16) & 0xFF;   \
    (cdb)->lba2 = (lba >> 8) & 0xFF;    \
    (cdb)->lba3 = lba & 0xFF;           \
}

#define SCSI_CDB10_GET_TL(cdb)  \
    ((cdb)->xfer_length0 << 8 | (cdb)->xfer_length1)
#define SCSI_CDB10_SET_TL(cdb, tl) {      \
    (cdb)->xfer_length0 = tl >> 8;       \
    (cdb)->xfer_length1 = tl & 0xFF;     \
}

/*
 * SCSI READ6/WRITE6 commands
 */
struct scsi_rw6_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         lun:3;
	u8         lba0:5;		/* MSb */
#else
	u8         lba0:5;		/* MSb */
	u8         lun:3;
#endif
	u8         lba1;
	u8         lba2;		/* LSB */
	u8         xfer_length;
	u8         control;
};

#define SCSI_TAPE_CDB6_GET_TL(cdb)              \
    (((cdb)->tl0 << 16) | ((cdb)->tl1 << 8) | (cdb)->tl2)

#define SCSI_TAPE_CDB6_SET_TL(cdb, tl) {      \
    (cdb)->tl0 = tl >> 16;            \
    (cdb)->tl1 = (tl >> 8) & 0xFF;    \
    (cdb)->tl2 = tl & 0xFF;           \
}

/*
 * SCSI sequential (TAPE) wrtie command
 */
struct scsi_tape_wr_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         rsvd:7;
	u8         fixed:1;	/* MSb */
#else
	u8         fixed:1;	/* MSb */
	u8         rsvd:7;
#endif
	u8         tl0;		/* Msb */
	u8         tl1;
	u8         tl2;		/* Lsb */

	u8         control;
};

#define SCSI_CDB6_GET_LBA(cdb)              \
    (((cdb)->lba0 << 16) | ((cdb)->lba1 << 8) | (cdb)->lba2)

#define SCSI_CDB6_SET_LBA(cdb, lba) {      \
    (cdb)->lba0 = lba >> 16;            \
    (cdb)->lba1 = (lba >> 8) & 0xFF;    \
    (cdb)->lba2 = lba & 0xFF;           \
}

#define SCSI_CDB6_GET_TL(cdb) ((cdb)->xfer_length)
#define SCSI_CDB6_SET_TL(cdb, tl) {      \
    (cdb)->xfer_length = tl;         \
}

/*
 * SCSI sense data format
 */
struct scsi_sense_s{
#ifdef __BIGENDIAN
	u8         valid:1;
	u8         rsp_code:7;
#else
	u8         rsp_code:7;
	u8         valid:1;
#endif
	u8         seg_num;
#ifdef __BIGENDIAN
	u8         file_mark:1;
	u8         eom:1;		/* end of media */
	u8         ili:1;		/* incorrect length indicator */
	u8         reserved:1;
	u8         sense_key:4;
#else
	u8         sense_key:4;
	u8         reserved:1;
	u8         ili:1;		/* incorrect length indicator */
	u8         eom:1;		/* end of media */
	u8         file_mark:1;
#endif
	u8         information[4];	/* device-type or command specific info
					 */
	u8         add_sense_length;
					/* additional sense length */
	u8         command_info[4];/* command specific information
						 */
	u8         asc;		/* additional sense code */
	u8         ascq;		/* additional sense code qualifier */
	u8         fru_code;	/* field replaceable unit code */
#ifdef __BIGENDIAN
	u8         sksv:1;		/* sense key specific valid */
	u8         c_d:1;		/* command/data bit */
	u8         res1:2;
	u8         bpv:1;		/* bit pointer valid */
	u8         bpointer:3;	/* bit pointer */
#else
	u8         bpointer:3;	/* bit pointer */
	u8         bpv:1;		/* bit pointer valid */
	u8         res1:2;
	u8         c_d:1;		/* command/data bit */
	u8         sksv:1;		/* sense key specific valid */
#endif
	u8         fpointer[2];	/* field pointer */
};

#define SCSI_SENSE_CUR_ERR          0x70
#define SCSI_SENSE_DEF_ERR          0x71

/*
 * SCSI sense key values
 */
#define SCSI_SK_NO_SENSE        0x0
#define SCSI_SK_REC_ERR         0x1	/* recovered error */
#define SCSI_SK_NOT_READY       0x2
#define SCSI_SK_MED_ERR         0x3	/* medium error */
#define SCSI_SK_HW_ERR          0x4	/* hardware error */
#define SCSI_SK_ILLEGAL_REQ     0x5
#define SCSI_SK_UNIT_ATT        0x6	/* unit attention */
#define SCSI_SK_DATA_PROTECT    0x7
#define SCSI_SK_BLANK_CHECK     0x8
#define SCSI_SK_VENDOR_SPEC     0x9
#define SCSI_SK_COPY_ABORTED    0xA
#define SCSI_SK_ABORTED_CMND    0xB
#define SCSI_SK_VOL_OVERFLOW    0xD
#define SCSI_SK_MISCOMPARE      0xE

/*
 * SCSI additional sense codes
 */
#define SCSI_ASC_NO_ADD_SENSE           0x00
#define SCSI_ASC_LUN_NOT_READY          0x04
#define SCSI_ASC_LUN_COMMUNICATION      0x08
#define SCSI_ASC_WRITE_ERROR            0x0C
#define SCSI_ASC_INVALID_CMND_CODE      0x20
#define SCSI_ASC_BAD_LBA                0x21
#define SCSI_ASC_INVALID_FIELD_IN_CDB   0x24
#define SCSI_ASC_LUN_NOT_SUPPORTED      0x25
#define SCSI_ASC_LUN_WRITE_PROTECT      0x27
#define SCSI_ASC_POWERON_BDR            0x29	/* power on reset, bus reset,
						 * bus device reset
						 */
#define SCSI_ASC_PARAMS_CHANGED         0x2A
#define SCSI_ASC_CMND_CLEARED_BY_A_I    0x2F
#define SCSI_ASC_SAVING_PARAM_NOTSUPP   0x39
#define SCSI_ASC_TOCC                   0x3F	/* target operating condtions
						 * changed
						 */
#define SCSI_ASC_PARITY_ERROR           0x47
#define SCSI_ASC_CMND_PHASE_ERROR       0x4A
#define SCSI_ASC_DATA_PHASE_ERROR       0x4B
#define SCSI_ASC_VENDOR_SPEC            0x7F

/*
 * SCSI additional sense code qualifiers
 */
#define SCSI_ASCQ_CAUSE_NOT_REPORT      0x00
#define SCSI_ASCQ_BECOMING_READY        0x01
#define SCSI_ASCQ_INIT_CMD_REQ          0x02
#define SCSI_ASCQ_FORMAT_IN_PROGRESS    0x04
#define SCSI_ASCQ_OPERATION_IN_PROGRESS 0x07
#define SCSI_ASCQ_SELF_TEST_IN_PROGRESS 0x09
#define SCSI_ASCQ_WR_UNEXP_UNSOL_DATA   0x0C
#define SCSI_ASCQ_WR_NOTENG_UNSOL_DATA  0x0D

#define SCSI_ASCQ_LBA_OUT_OF_RANGE      0x00
#define SCSI_ASCQ_INVALID_ELEMENT_ADDR  0x01

#define SCSI_ASCQ_LUN_WRITE_PROTECTED       0x00
#define SCSI_ASCQ_LUN_HW_WRITE_PROTECTED    0x01
#define SCSI_ASCQ_LUN_SW_WRITE_PROTECTED    0x02

#define SCSI_ASCQ_POR   0x01	/* power on reset */
#define SCSI_ASCQ_SBR   0x02	/* scsi bus reset */
#define SCSI_ASCQ_BDR   0x03	/* bus device reset */
#define SCSI_ASCQ_DIR   0x04	/* device internal reset */

#define SCSI_ASCQ_MODE_PARAMS_CHANGED       0x01
#define SCSI_ASCQ_LOG_PARAMS_CHANGED        0x02
#define SCSI_ASCQ_RESERVATIONS_PREEMPTED    0x03
#define SCSI_ASCQ_RESERVATIONS_RELEASED     0x04
#define SCSI_ASCQ_REGISTRATIONS_PREEMPTED   0x05

#define SCSI_ASCQ_MICROCODE_CHANGED 0x01
#define SCSI_ASCQ_CHANGED_OPER_COND 0x02
#define SCSI_ASCQ_INQ_CHANGED       0x03	/* inquiry data changed */
#define SCSI_ASCQ_DI_CHANGED        0x05	/* device id changed */
#define SCSI_ASCQ_RL_DATA_CHANGED   0x0E	/* report luns data changed */

#define SCSI_ASCQ_DP_CRC_ERR            0x01	/* data phase crc error */
#define SCSI_ASCQ_DP_SCSI_PARITY_ERR    0x02	/* data phase scsi parity error
						 */
#define SCSI_ASCQ_IU_CRC_ERR            0x03	/* information unit crc error */
#define SCSI_ASCQ_PROTO_SERV_CRC_ERR    0x05

#define SCSI_ASCQ_LUN_TIME_OUT          0x01

/* ------------------------------------------------------------
 * SCSI INQUIRY
 * ------------------------------------------------------------*/

struct scsi_inquiry_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         lun:3;
	u8         reserved1:3;
	u8         cmd_dt:1;
	u8         evpd:1;
#else
	u8         evpd:1;
	u8         cmd_dt:1;
	u8         reserved1:3;
	u8         lun:3;
#endif
	u8         page_code;
	u8         reserved2;
	u8         alloc_length;
	u8         control;
};

struct scsi_inquiry_vendor_s{
	u8         vendor_id[8];
};

struct scsi_inquiry_prodid_s{
	u8         product_id[16];
};

struct scsi_inquiry_prodrev_s{
	u8         product_rev[4];
};

struct scsi_inquiry_data_s{
#ifdef __BIGENDIAN
	u8         peripheral_qual:3;	/* peripheral qualifier */
	u8         device_type:5;		/* peripheral device type */

	u8         rmb:1;			/* removable medium bit */
	u8         device_type_mod:7;	/* device type modifier */

	u8         version;

	u8         aenc:1;		/* async event notification capability
					 */
	u8         trm_iop:1;	/* terminate I/O process */
	u8         norm_aca:1;	/* normal ACA supported */
	u8         hi_support:1;	/* SCSI-3: supports REPORT LUNS */
	u8         rsp_data_format:4;

	u8         additional_len;
	u8         sccs:1;
	u8         reserved1:7;

	u8         reserved2:1;
	u8         enc_serv:1;	/* enclosure service component */
	u8         reserved3:1;
	u8         multi_port:1;	/* multi-port device */
	u8         m_chngr:1;	/* device in medium transport element */
	u8         ack_req_q:1;	/* SIP specific bit */
	u8         addr32:1;	/* SIP specific bit */
	u8         addr16:1;	/* SIP specific bit */

	u8         rel_adr:1;	/* relative address */
	u8         w_bus32:1;
	u8         w_bus16:1;
	u8         synchronous:1;
	u8         linked_commands:1;
	u8         trans_dis:1;
	u8         cmd_queue:1;	/* command queueing supported */
	u8         soft_reset:1;	/* soft reset alternative (VS) */
#else
	u8         device_type:5;	/* peripheral device type */
	u8         peripheral_qual:3;
					/* peripheral qualifier */

	u8         device_type_mod:7;
					/* device type modifier */
	u8         rmb:1;		/* removable medium bit */

	u8         version;

	u8         rsp_data_format:4;
	u8         hi_support:1;	/* SCSI-3: supports REPORT LUNS */
	u8         norm_aca:1;	/* normal ACA supported */
	u8         terminate_iop:1;/* terminate I/O process */
	u8         aenc:1;		/* async event notification capability
					 */

	u8         additional_len;
	u8         reserved1:7;
	u8         sccs:1;

	u8         addr16:1;	/* SIP specific bit */
	u8         addr32:1;	/* SIP specific bit */
	u8         ack_req_q:1;	/* SIP specific bit */
	u8         m_chngr:1;	/* device in medium transport element */
	u8         multi_port:1;	/* multi-port device */
	u8         reserved3:1;	/* TBD - Vendor Specific */
	u8         enc_serv:1;	/* enclosure service component */
	u8         reserved2:1;

	u8         soft_seset:1;	/* soft reset alternative (VS) */
	u8         cmd_queue:1;	/* command queueing supported */
	u8         trans_dis:1;
	u8         linked_commands:1;
	u8         synchronous:1;
	u8         w_bus16:1;
	u8         w_bus32:1;
	u8         rel_adr:1;	/* relative address */
#endif
	struct scsi_inquiry_vendor_s vendor_id;
	struct scsi_inquiry_prodid_s product_id;
	struct scsi_inquiry_prodrev_s product_rev;
	u8         vendor_specific[20];
	u8         reserved4[40];
};

/*
 * inquiry.peripheral_qual field values
 */
#define SCSI_DEVQUAL_DEFAULT        0
#define SCSI_DEVQUAL_NOT_CONNECTED  1
#define SCSI_DEVQUAL_NOT_SUPPORTED  3

/*
 * inquiry.device_type field values
 */
#define SCSI_DEVICE_DIRECT_ACCESS       0x00
#define SCSI_DEVICE_SEQ_ACCESS          0x01
#define SCSI_DEVICE_ARRAY_CONTROLLER    0x0C
#define SCSI_DEVICE_UNKNOWN             0x1F

/*
 * inquiry.version
 */
#define SCSI_VERSION_ANSI_X3131     2	/* ANSI X3.131 SCSI-2 */
#define SCSI_VERSION_SPC            3	/* SPC (SCSI-3), ANSI X3.301:1997 */
#define SCSI_VERSION_SPC_2          4	/* SPC-2 */

/*
 * response data format
 */
#define SCSI_RSP_DATA_FORMAT        2	/* SCSI-2 & SPC */

/*
 * SCSI inquiry page codes
 */
#define SCSI_INQ_PAGE_VPD_PAGES     0x00	/* supported vpd pages */
#define SCSI_INQ_PAGE_USN_PAGE      0x80	/* unit serial number page */
#define SCSI_INQ_PAGE_DEV_IDENT     0x83	/* device indentification page
						 */
#define SCSI_INQ_PAGES_MAX          3

/*
 * supported vital product data pages
 */
struct scsi_inq_page_vpd_pages_s{
#ifdef __BIGENDIAN
	u8         peripheral_qual:3;
	u8         device_type:5;
#else
	u8         device_type:5;
	u8         peripheral_qual:3;
#endif
	u8         page_code;
	u8         reserved;
	u8         page_length;
	u8         pages[SCSI_INQ_PAGES_MAX];
};

/*
 * Unit serial number page
 */
#define SCSI_INQ_USN_LEN 32

struct scsi_inq_usn_s{
	char            usn[SCSI_INQ_USN_LEN];
};

struct scsi_inq_page_usn_s{
#ifdef __BIGENDIAN
	u8         peripheral_qual:3;
	u8         device_type:5;
#else
	u8         device_type:5;
	u8         peripheral_qual:3;
#endif
	u8         page_code;
	u8         reserved1;
	u8         page_length;
	struct scsi_inq_usn_s  usn;
};

enum {
	SCSI_INQ_DIP_CODE_BINARY = 1,	/* identifier has binary value */
	SCSI_INQ_DIP_CODE_ASCII = 2,	/* identifier has ascii value */
};

enum {
	SCSI_INQ_DIP_ASSOC_LUN = 0,	/* id is associated with device */
	SCSI_INQ_DIP_ASSOC_PORT = 1,	/* id is associated with port that
					 * received the request
					 */
};

enum {
	SCSI_INQ_ID_TYPE_VENDOR = 1,
	SCSI_INQ_ID_TYPE_IEEE = 2,
	SCSI_INQ_ID_TYPE_FC_FS = 3,
	SCSI_INQ_ID_TYPE_OTHER = 4,
};

struct scsi_inq_dip_desc_s{
#ifdef __BIGENDIAN
	u8         res0:4;
	u8         code_set:4;
	u8         res1:2;
	u8         association:2;
	u8         id_type:4;
#else
	u8         code_set:4;
	u8         res0:4;
	u8         id_type:4;
	u8         association:2;
	u8         res1:2;
#endif
	u8         res2;
	u8         id_len;
	struct scsi_lun_sn_s   id;
};

/*
 * Device indentification page
 */
struct scsi_inq_page_dev_ident_s{
#ifdef __BIGENDIAN
	u8         peripheral_qual:3;
	u8         device_type:5;
#else
	u8         device_type:5;
	u8         peripheral_qual:3;
#endif
	u8         page_code;
	u8         reserved1;
	u8         page_length;
	struct scsi_inq_dip_desc_s desc;
};

/* ------------------------------------------------------------
 * READ CAPACITY
 * ------------------------------------------------------------
 */

struct scsi_read_capacity_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         lun:3;
	u8         reserved1:4;
	u8         rel_adr:1;
#else
	u8         rel_adr:1;
	u8         reserved1:4;
	u8         lun:3;
#endif
	u8         lba0;	/* MSB */
	u8         lba1;
	u8         lba2;
	u8         lba3;	/* LSB */
	u8         reserved2;
	u8         reserved3;
#ifdef __BIGENDIAN
	u8         reserved4:7;
	u8         pmi:1;	/* partial medium indicator */
#else
	u8         pmi:1;	/* partial medium indicator */
	u8         reserved4:7;
#endif
	u8         control;
};

struct scsi_read_capacity_data_s{
	u32        max_lba;	/* maximum LBA available */
	u32        block_length;	/* in bytes */
};

struct scsi_read_capacity16_data_s{
	u64        lba;	/* maximum LBA available */
	u32        block_length;	/* in bytes */
#ifdef __BIGENDIAN
	u8         reserved1:4,
			p_type:3,
			prot_en:1;
	u8		reserved2:4,
			lb_pbe:4;	/* logical blocks per physical block
					 * exponent */
	u16	reserved3:2,
			lba_align:14;	/* lowest aligned logical block
					 * address */
#else
	u16	lba_align:14,	/* lowest aligned logical block
					 * address */
			reserved3:2;
	u8		lb_pbe:4,	/* logical blocks per physical block
					 * exponent */
			reserved2:4;
	u8		prot_en:1,
			p_type:3,
			reserved1:4;
#endif
	u64	reserved4;
	u64	reserved5;
};

/* ------------------------------------------------------------
 * REPORT LUNS command
 * ------------------------------------------------------------
 */

struct scsi_report_luns_s{
	u8         opcode;		/* A0h - REPORT LUNS opCode */
	u8         reserved1[5];
	u8         alloc_length[4];/* allocation length MSB first */
	u8         reserved2;
	u8         control;
};

#define SCSI_REPORT_LUN_ALLOC_LENGTH(rl)                		\
    ((rl->alloc_length[0] << 24) | (rl->alloc_length[1] << 16) | 	\
     (rl->alloc_length[2] << 8) | (rl->alloc_length[3]))

#define SCSI_REPORT_LUNS_SET_ALLOCLEN(rl, alloc_len) {      \
    (rl)->alloc_length[0] = (alloc_len) >> 24;      			\
    (rl)->alloc_length[1] = ((alloc_len) >> 16) & 0xFF; 		\
    (rl)->alloc_length[2] = ((alloc_len) >> 8) & 0xFF;  		\
    (rl)->alloc_length[3] = (alloc_len) & 0xFF;     			\
}

struct scsi_report_luns_data_s{
	u32        lun_list_length;	/* length of LUN list length */
	u32        reserved;
	lun_t           lun[1];			/* first LUN in lun list */
};

/* -------------------------------------------------------------
 * SCSI mode  parameters
 * -----------------------------------------------------------
 */
enum {
	SCSI_DA_MEDIUM_DEF = 0,	/* direct access default medium type */
	SCSI_DA_MEDIUM_SS = 1,	/* direct access single sided */
	SCSI_DA_MEDIUM_DS = 2,	/* direct access double sided */
};

/*
 * SCSI Mode Select(6) cdb
 */
struct scsi_mode_select6_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved1:3;
	u8         pf:1;		/* page format */
	u8         reserved2:3;
	u8         sp:1;		/* save pages if set to 1 */
#else
	u8         sp:1;	/* save pages if set to 1 */
	u8         reserved2:3;
	u8         pf:1;	/* page format */
	u8         reserved1:3;
#endif
	u8         reserved3[2];
	u8         alloc_len;
	u8         control;
};

/*
 * SCSI Mode Select(10) cdb
 */
struct scsi_mode_select10_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved1:3;
	u8         pf:1;	/* page format */
	u8         reserved2:3;
	u8         sp:1;	/* save pages if set to 1 */
#else
	u8         sp:1;	/* save pages if set to 1 */
	u8         reserved2:3;
	u8         pf:1;	/* page format */
	u8         reserved1:3;
#endif
	u8         reserved3[5];
	u8         alloc_len_msb;
	u8         alloc_len_lsb;
	u8         control;
};

/*
 * SCSI Mode Sense(6) cdb
 */
struct scsi_mode_sense6_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved1:4;
	u8         dbd:1;	/* disable block discriptors if set to 1 */
	u8         reserved2:3;

	u8         pc:2;	/* page control */
	u8         page_code:6;
#else
	u8         reserved2:3;
	u8         dbd:1;	/* disable block descriptors if set to 1 */
	u8         reserved1:4;

	u8         page_code:6;
	u8         pc:2;	/* page control */
#endif
	u8         reserved3;
	u8         alloc_len;
	u8         control;
};

/*
 * SCSI Mode Sense(10) cdb
 */
struct scsi_mode_sense10_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved1:3;
	u8         LLBAA:1;	/* long LBA accepted if set to 1 */
	u8         dbd:1;		/* disable block descriptors if set
					 * to 1
					 */
	u8         reserved2:3;

	u8         pc:2;		/* page control */
	u8         page_code:6;
#else
	u8         reserved2:3;
	u8         dbd:1;		/* disable block descriptors if set to
					 * 1
					 */
	u8         LLBAA:1;	/* long LBA accepted if set to 1 */
	u8         reserved1:3;

	u8         page_code:6;
	u8         pc:2;		/* page control */
#endif
	u8         reserved3[4];
	u8         alloc_len_msb;
	u8         alloc_len_lsb;
	u8         control;
};

#define SCSI_CDB10_GET_AL(cdb)  					\
    ((cdb)->alloc_len_msb << 8 | (cdb)->alloc_len_lsb)

#define SCSI_CDB10_SET_AL(cdb, al) {      \
    (cdb)->alloc_len_msb = al >> 8;       				\
    (cdb)->alloc_len_lsb = al & 0xFF;     				\
}

#define SCSI_CDB6_GET_AL(cdb) ((cdb)->alloc_len)

#define SCSI_CDB6_SET_AL(cdb, al) {      \
    (cdb)->alloc_len = al;         					\
}

/*
 * page control field values
 */
#define SCSI_PC_CURRENT_VALUES       0x0
#define SCSI_PC_CHANGEABLE_VALUES    0x1
#define SCSI_PC_DEFAULT_VALUES       0x2
#define SCSI_PC_SAVED_VALUES         0x3

/*
 * SCSI mode page codes
 */
#define SCSI_MP_VENDOR_SPEC     0x00
#define SCSI_MP_DISC_RECN       0x02	/* disconnect-reconnect page */
#define SCSI_MP_FORMAT_DEVICE   0x03
#define SCSI_MP_RDG             0x04	/* rigid disk geometry page */
#define SCSI_MP_FDP             0x05	/* flexible disk page */
#define SCSI_MP_CACHING         0x08	/* caching page */
#define SCSI_MP_CONTROL         0x0A	/* control mode page */
#define SCSI_MP_MED_TYPES_SUP   0x0B	/* medium types supported page */
#define SCSI_MP_INFO_EXCP_CNTL  0x1C	/* informational exception control */
#define SCSI_MP_ALL             0x3F	/* return all pages - mode sense only */

/*
 * mode parameter header
 */
struct scsi_mode_param_header6_s{
	u8         mode_datalen;
	u8         medium_type;

	/*
	 * device specific parameters expanded for direct access devices
	 */
#ifdef __BIGENDIAN
	u32        wp:1;		/* write protected */
	u32        reserved1:2;
	u32        dpofua:1;	/* disable page out + force unit access
					 */
	u32        reserved2:4;
#else
	u32        reserved2:4;
	u32        dpofua:1;	/* disable page out + force unit access
					 */
	u32        reserved1:2;
	u32        wp:1;		/* write protected */
#endif

	u8         block_desclen;
};

struct scsi_mode_param_header10_s{
	u32        mode_datalen:16;
	u32        medium_type:8;

	/*
	 * device specific parameters expanded for direct access devices
	 */
#ifdef __BIGENDIAN
	u32        wp:1;		/* write protected */
	u32        reserved1:2;
	u32        dpofua:1;	/* disable page out + force unit access
					 */
	u32        reserved2:4;
#else
	u32        reserved2:4;
	u32        dpofua:1;	/* disable page out + force unit access
					 */
	u32        reserved1:2;
	u32        wp:1;		/* write protected */
#endif

#ifdef __BIGENDIAN
	u32        reserved3:7;
	u32        longlba:1;
#else
	u32        longlba:1;
	u32        reserved3:7;
#endif
	u32        reserved4:8;
	u32        block_desclen:16;
};

/*
 * mode parameter block descriptor
 */
struct scsi_mode_param_desc_s{
	u32        nblks;
	u32        density_code:8;
	u32        block_length:24;
};

/*
 * Disconnect-reconnect mode page format
 */
struct scsi_mp_disc_recn_s{
#ifdef __BIGENDIAN
	u8         ps:1;
	u8         reserved1:1;
	u8         page_code:6;
#else
	u8         page_code:6;
	u8         reserved1:1;
	u8         ps:1;
#endif
	u8         page_len;
	u8         buf_full_ratio;
	u8         buf_empty_ratio;

	u8         bil_msb;	/* bus inactivity limit -MSB */
	u8         bil_lsb;	/* bus inactivity limit -LSB */

	u8         dtl_msb;	/* disconnect time limit - MSB */
	u8         dtl_lsb;	/* disconnect time limit - LSB */

	u8         ctl_msb;	/* connect time limit - MSB */
	u8         ctl_lsb;	/* connect time limit - LSB */

	u8         max_burst_len_msb;
	u8         max_burst_len_lsb;
#ifdef __BIGENDIAN
	u8         emdp:1;	/* enable modify data pointers */
	u8         fa:3;	/* fair arbitration */
	u8         dimm:1;	/* disconnect immediate */
	u8         dtdc:3;	/* data transfer disconnect control */
#else
	u8         dtdc:3;	/* data transfer disconnect control */
	u8         dimm:1;	/* disconnect immediate */
	u8         fa:3;	/* fair arbitration */
	u8         emdp:1;	/* enable modify data pointers */
#endif

	u8         reserved3;

	u8         first_burst_len_msb;
	u8         first_burst_len_lsb;
};

/*
 * SCSI format device mode page
 */
struct scsi_mp_format_device_s{
#ifdef __BIGENDIAN
	u32        ps:1;
	u32        reserved1:1;
	u32        page_code:6;
#else
	u32        page_code:6;
	u32        reserved1:1;
	u32        ps:1;
#endif
	u32        page_len:8;
	u32        tracks_per_zone:16;

	u32        a_sec_per_zone:16;
	u32        a_tracks_per_zone:16;

	u32        a_tracks_per_lun:16;	/* alternate tracks/lun-MSB */
	u32        sec_per_track:16;	/* sectors/track-MSB */

	u32        bytes_per_sector:16;
	u32        interleave:16;

	u32        tsf:16;			/* track skew factor-MSB */
	u32        csf:16;			/* cylinder skew factor-MSB */

#ifdef __BIGENDIAN
	u32        ssec:1;	/* soft sector formatting */
	u32        hsec:1;	/* hard sector formatting */
	u32        rmb:1;	/* removable media */
	u32        surf:1;	/* surface */
	u32        reserved2:4;
#else
	u32        reserved2:4;
	u32        surf:1;	/* surface */
	u32        rmb:1;	/* removable media */
	u32        hsec:1;	/* hard sector formatting */
	u32        ssec:1;	/* soft sector formatting */
#endif
	u32        reserved3:24;
};

/*
 * SCSI rigid disk device geometry page
 */
struct scsi_mp_rigid_device_geometry_s{
#ifdef __BIGENDIAN
	u32        ps:1;
	u32        reserved1:1;
	u32        page_code:6;
#else
	u32        page_code:6;
	u32        reserved1:1;
	u32        ps:1;
#endif
	u32        page_len:8;
	u32        num_cylinders0:8;
	u32        num_cylinders1:8;

	u32        num_cylinders2:8;
	u32        num_heads:8;
	u32        scwp0:8;
	u32        scwp1:8;

	u32        scwp2:8;
	u32        scrwc0:8;
	u32        scrwc1:8;
	u32        scrwc2:8;

	u32        dsr:16;
	u32        lscyl0:8;
	u32        lscyl1:8;

	u32        lscyl2:8;
#ifdef __BIGENDIAN
	u32        reserved2:6;
	u32        rpl:2;	/* rotational position locking */
#else
	u32        rpl:2;	/* rotational position locking */
	u32        reserved2:6;
#endif
	u32        rot_off:8;
	u32        reserved3:8;

	u32        med_rot_rate:16;
	u32        reserved4:16;
};

/*
 * SCSI caching mode page
 */
struct scsi_mp_caching_s{
#ifdef __BIGENDIAN
	u8         ps:1;
	u8         res1:1;
	u8         page_code:6;
#else
	u8         page_code:6;
	u8         res1:1;
	u8         ps:1;
#endif
	u8         page_len;
#ifdef __BIGENDIAN
	u8         ic:1;	/* initiator control */
	u8         abpf:1;	/* abort pre-fetch */
	u8         cap:1;	/* caching analysis permitted */
	u8         disc:1;	/* discontinuity */
	u8         size:1;	/* size enable */
	u8         wce:1;	/* write cache enable */
	u8         mf:1;	/* multiplication factor */
	u8         rcd:1;	/* read cache disable */

	u8         drrp:4;	/* demand read retention priority */
	u8         wrp:4;	/* write retention priority */
#else
	u8         rcd:1;	/* read cache disable */
	u8         mf:1;	/* multiplication factor */
	u8         wce:1;	/* write cache enable */
	u8         size:1;	/* size enable */
	u8         disc:1;	/* discontinuity */
	u8         cap:1;	/* caching analysis permitted */
	u8         abpf:1;	/* abort pre-fetch */
	u8         ic:1;	/* initiator control */

	u8         wrp:4;	/* write retention priority */
	u8         drrp:4;	/* demand read retention priority */
#endif
	u8         dptl[2];/* disable pre-fetch transfer length */
	u8         min_prefetch[2];
	u8         max_prefetch[2];
	u8         max_prefetch_limit[2];
#ifdef __BIGENDIAN
	u8         fsw:1;	/* force sequential write */
	u8         lbcss:1;/* logical block cache segment size */
	u8         dra:1;	/* disable read ahead */
	u8         vs:2;	/* vendor specific */
	u8         res2:3;
#else
	u8         res2:3;
	u8         vs:2;	/* vendor specific */
	u8         dra:1;	/* disable read ahead */
	u8         lbcss:1;/* logical block cache segment size */
	u8         fsw:1;	/* force sequential write */
#endif
	u8         num_cache_segs;

	u8         cache_seg_size[2];
	u8         res3;
	u8         non_cache_seg_size[3];
};

/*
 * SCSI control mode page
 */
struct scsi_mp_control_page_s{
#ifdef __BIGENDIAN
u8         ps:1;
u8         reserved1:1;
u8         page_code:6;
#else
u8         page_code:6;
u8         reserved1:1;
u8         ps:1;
#endif
	u8         page_len;
#ifdef __BIGENDIAN
	u8         tst:3;		/* task set type */
	u8         reserved3:3;
	u8         gltsd:1;	/* global logging target save disable */
	u8         rlec:1;		/* report log exception condition */

	u8         qalgo_mod:4;	/* queue alogorithm modifier */
	u8         reserved4:1;
	u8         qerr:2;		/* queue error management */
	u8         dque:1;		/* disable queuing */

	u8         reserved5:1;
	u8         rac:1;		/* report a check */
	u8         reserved6:2;
	u8         swp:1;		/* software write protect */
	u8         raerp:1;	/* ready AER permission */
	u8         uaaerp:1;	/* unit attenstion AER permission */
	u8         eaerp:1;	/* error AER permission */

	u8         reserved7:5;
	u8         autoload_mod:3;
#else
	u8         rlec:1;		/* report log exception condition */
	u8         gltsd:1;	/* global logging target save disable */
	u8         reserved3:3;
	u8         tst:3;		/* task set type */

	u8         dque:1;		/* disable queuing */
	u8         qerr:2;		/* queue error management */
	u8         reserved4:1;
	u8         qalgo_mod:4;	/* queue alogorithm modifier */

	u8         eaerp:1;	/* error AER permission */
	u8         uaaerp:1;	/* unit attenstion AER permission */
	u8         raerp:1;	/* ready AER permission */
	u8         swp:1;		/* software write protect */
	u8         reserved6:2;
	u8         rac:1;		/* report a check */
	u8         reserved5:1;

	u8         autoload_mod:3;
	u8         reserved7:5;
#endif
	u8         rahp_msb;	/* ready AER holdoff period - MSB */
	u8         rahp_lsb;	/* ready AER holdoff period - LSB */

	u8         busy_timeout_period_msb;
	u8         busy_timeout_period_lsb;

	u8         ext_selftest_compl_time_msb;
	u8         ext_selftest_compl_time_lsb;
};

/*
 * SCSI medium types supported mode page
 */
struct scsi_mp_medium_types_sup_s{
#ifdef __BIGENDIAN
	u8         ps:1;
	u8         reserved1:1;
	u8         page_code:6;
#else
	u8         page_code:6;
	u8         reserved1:1;
	u8         ps:1;
#endif
	u8         page_len;

	u8         reserved3[2];
	u8         med_type1_sup;	/* medium type one supported */
	u8         med_type2_sup;	/* medium type two supported */
	u8         med_type3_sup;	/* medium type three supported */
	u8         med_type4_sup;	/* medium type four supported */
};

/*
 * SCSI informational exception control mode page
 */
struct scsi_mp_info_excpt_cntl_s{
#ifdef __BIGENDIAN
	u8         ps:1;
	u8         reserved1:1;
	u8         page_code:6;
#else
	u8         page_code:6;
	u8         reserved1:1;
	u8         ps:1;
#endif
	u8         page_len;
#ifdef __BIGENDIAN
	u8         perf:1;		/* performance */
	u8         reserved3:1;
	u8         ebf:1;		/* enable background fucntion */
	u8         ewasc:1;	/* enable warning */
	u8         dexcpt:1;	/* disable exception control */
	u8         test:1;		/* enable test device failure
					 * notification
					 */
	u8         reserved4:1;
	u8         log_error:1;

	u8         reserved5:4;
	u8         mrie:4;		/* method of reporting info
					 * exceptions
					 */
#else
	u8         log_error:1;
	u8         reserved4:1;
	u8         test:1;		/* enable test device failure
					 * notification
					 */
	u8         dexcpt:1;	/* disable exception control */
	u8         ewasc:1;	/* enable warning */
	u8         ebf:1;		/* enable background fucntion */
	u8         reserved3:1;
	u8         perf:1;		/* performance */

	u8         mrie:4;		/* method of reporting info
					 * exceptions
					 */
	u8         reserved5:4;
#endif
	u8         interval_timer_msb;
	u8         interval_timer_lsb;

	u8         report_count_msb;
	u8         report_count_lsb;
};

/*
 * Methods of reporting informational exceptions
 */
#define SCSI_MP_IEC_NO_REPORT       0x0	/* no reporting of exceptions */
#define SCSI_MP_IEC_AER             0x1	/* async event reporting */
#define SCSI_MP_IEC_UNIT_ATTN       0x2	/* generate unit attenstion */
#define SCSI_MO_IEC_COND_REC_ERR    0x3	/* conditionally generate recovered
					 * error
					 */
#define SCSI_MP_IEC_UNCOND_REC_ERR  0x4	/* unconditionally generate recovered
					 * error
					 */
#define SCSI_MP_IEC_NO_SENSE        0x5	/* generate no sense */
#define SCSI_MP_IEC_ON_REQUEST      0x6	/* only report exceptions on request */

/*
 * SCSI flexible disk page
 */
struct scsi_mp_flexible_disk_s{
#ifdef __BIGENDIAN
	u8         ps:1;
	u8         reserved1:1;
	u8         page_code:6;
#else
	u8         page_code:6;
	u8         reserved1:1;
	u8         ps:1;
#endif
	u8         page_len;

	u8         transfer_rate_msb;
	u8         transfer_rate_lsb;

	u8         num_heads;
	u8         num_sectors;

	u8         bytes_per_sector_msb;
	u8         bytes_per_sector_lsb;

	u8         num_cylinders_msb;
	u8         num_cylinders_lsb;

	u8         sc_wpc_msb;	/* starting cylinder-write
					 * precompensation msb
					 */
	u8         sc_wpc_lsb;	/* starting cylinder-write
					 * precompensation lsb
					 */
	u8         sc_rwc_msb;	/* starting cylinder-reduced write
					 * current msb
					 */
	u8         sc_rwc_lsb;	/* starting cylinder-reduced write
					 * current lsb
					 */

	u8         dev_step_rate_msb;
	u8         dev_step_rate_lsb;

	u8         dev_step_pulse_width;

	u8         head_sd_msb;	/* head settle delay msb */
	u8         head_sd_lsb;	/* head settle delay lsb */

	u8         motor_on_delay;
	u8         motor_off_delay;
#ifdef __BIGENDIAN
	u8         trdy:1;		/* true ready bit */
	u8         ssn:1;		/* start sector number bit */
	u8         mo:1;		/* motor on bit */
	u8         reserved3:5;

	u8         reserved4:4;
	u8         spc:4;		/* step pulse per cylinder */
#else
	u8         reserved3:5;
	u8         mo:1;		/* motor on bit */
	u8         ssn:1;		/* start sector number bit */
	u8         trdy:1;		/* true ready bit */

	u8         spc:4;		/* step pulse per cylinder */
	u8         reserved4:4;
#endif
	u8         write_comp;
	u8         head_load_delay;
	u8         head_unload_delay;
#ifdef __BIGENDIAN
	u8         pin34:4;	/* pin34 usage */
	u8         pin2:4;		/* pin2 usage */

	u8         pin4:4;		/* pin4 usage */
	u8         pin1:4;		/* pin1 usage */
#else
	u8         pin2:4;		/* pin2 usage */
	u8         pin34:4;	/* pin34 usage */

	u8         pin1:4;		/* pin1 usage */
	u8         pin4:4;		/* pin4 usage */
#endif
	u8         med_rot_rate_msb;
	u8         med_rot_rate_lsb;

	u8         reserved5[2];
};

struct scsi_mode_page_format_data6_s{
	struct scsi_mode_param_header6_s mph;	/* mode page header */
	struct scsi_mode_param_desc_s desc;	/* block descriptor */
	struct scsi_mp_format_device_s format;	/* format device data */
};

struct scsi_mode_page_format_data10_s{
	struct scsi_mode_param_header10_s mph;	/* mode page header */
	struct scsi_mode_param_desc_s desc;	/* block descriptor */
	struct scsi_mp_format_device_s format;	/* format device data */
};

struct scsi_mode_page_rdg_data6_s{
	struct scsi_mode_param_header6_s mph;	/* mode page header */
	struct scsi_mode_param_desc_s desc;	/* block descriptor */
	struct scsi_mp_rigid_device_geometry_s rdg;
					/* rigid geometry data */
};

struct scsi_mode_page_rdg_data10_s{
	struct scsi_mode_param_header10_s mph;	/* mode page header */
	struct scsi_mode_param_desc_s desc;	/* block descriptor */
	struct scsi_mp_rigid_device_geometry_s rdg;
					/* rigid geometry data */
};

struct scsi_mode_page_cache6_s{
	struct scsi_mode_param_header6_s mph;	/* mode page header */
	struct scsi_mode_param_desc_s desc;	/* block descriptor */
	struct scsi_mp_caching_s cache;	/* cache page data */
};

struct scsi_mode_page_cache10_s{
	struct scsi_mode_param_header10_s mph;	/* mode page header */
	struct scsi_mode_param_desc_s desc;	/* block descriptor */
	struct scsi_mp_caching_s cache;	/* cache page data */
};

/* --------------------------------------------------------------
 * Format Unit command
 * ------------------------------------------------------------
 */

/*
 * Format Unit CDB
 */
struct scsi_format_unit_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         res1:3;
	u8         fmtdata:1;	/* if set, data out phase has format
					 * data
					 */
	u8         cmplst:1;	/* if set, defect list is complete */
	u8         def_list:3;	/* format of defect descriptor is
					 * fmtdata =1
					 */
#else
	u8         def_list:3;	/* format of defect descriptor is
					 * fmtdata = 1
					 */
	u8         cmplst:1;	/* if set, defect list is complete */
	u8         fmtdata:1;	/* if set, data out phase has format
					 * data
					 */
	u8         res1:3;
#endif
	u8         interleave_msb;
	u8         interleave_lsb;
	u8         vendor_spec;
	u8         control;
};

/*
 * h
 */
struct scsi_reserve6_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved:3;
	u8         obsolete:4;
	u8         extent:1;
#else
	u8         extent:1;
	u8         obsolete:4;
	u8         reserved:3;
#endif
	u8         reservation_id;
	u16        param_list_len;
	u8         control;
};

/*
 * h
 */
struct scsi_release6_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved1:3;
	u8         obsolete:4;
	u8         extent:1;
#else
	u8         extent:1;
	u8         obsolete:4;
	u8         reserved1:3;
#endif
	u8         reservation_id;
	u16        reserved2;
	u8         control;
};

/*
 * h
 */
struct scsi_reserve10_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved1:3;
	u8         third_party:1;
	u8         reserved2:2;
	u8         long_id:1;
	u8         extent:1;
#else
	u8         extent:1;
	u8         long_id:1;
	u8         reserved2:2;
	u8         third_party:1;
	u8         reserved1:3;
#endif
	u8         reservation_id;
	u8         third_pty_dev_id;
	u8         reserved3;
	u8         reserved4;
	u8         reserved5;
	u16        param_list_len;
	u8         control;
};

struct scsi_release10_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved1:3;
	u8         third_party:1;
	u8         reserved2:2;
	u8         long_id:1;
	u8         extent:1;
#else
	u8         extent:1;
	u8         long_id:1;
	u8         reserved2:2;
	u8         third_party:1;
	u8         reserved1:3;
#endif
	u8         reservation_id;
	u8         third_pty_dev_id;
	u8         reserved3;
	u8         reserved4;
	u8         reserved5;
	u16        param_list_len;
	u8         control;
};

struct scsi_verify10_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         lun:3;
	u8         dpo:1;
	u8         reserved:2;
	u8         bytchk:1;
	u8         reladdr:1;
#else
	u8         reladdr:1;
	u8         bytchk:1;
	u8         reserved:2;
	u8         dpo:1;
	u8         lun:3;
#endif
	u8         lba0;
	u8         lba1;
	u8         lba2;
	u8         lba3;
	u8         reserved1;
	u8         verification_len0;
	u8         verification_len1;
	u8         control_byte;
};

struct scsi_request_sense_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         lun:3;
	u8         reserved:5;
#else
	u8         reserved:5;
	u8         lun:3;
#endif
	u8         reserved0;
	u8         reserved1;
	u8         alloc_len;
	u8         control_byte;
};

/* ------------------------------------------------------------
 * SCSI status byte values
 * ------------------------------------------------------------
 */
#define SCSI_STATUS_GOOD                   0x00
#define SCSI_STATUS_CHECK_CONDITION        0x02
#define SCSI_STATUS_CONDITION_MET          0x04
#define SCSI_STATUS_BUSY                   0x08
#define SCSI_STATUS_INTERMEDIATE           0x10
#define SCSI_STATUS_ICM                    0x14	/* intermediate condition met */
#define SCSI_STATUS_RESERVATION_CONFLICT   0x18
#define SCSI_STATUS_COMMAND_TERMINATED     0x22
#define SCSI_STATUS_QUEUE_FULL             0x28
#define SCSI_STATUS_ACA_ACTIVE             0x30

#define SCSI_MAX_ALLOC_LEN		0xFF	/* maximum allocarion length
						 * in CDBs
						 */

#define SCSI_OP_WRITE_VERIFY10      0x2E
#define SCSI_OP_WRITE_VERIFY12      0xAE
#define SCSI_OP_UNDEF               0xFF

/*
 * SCSI WRITE-VERIFY(10) command
 */
struct scsi_write_verify10_s{
	u8         opcode;
#ifdef __BIGENDIAN
	u8         reserved1:3;
	u8         dpo:1;		/* Disable Page Out */
	u8         reserved2:1;
	u8         ebp:1;		/* erse by-pass */
	u8         bytchk:1;	/* byte check */
	u8         rel_adr:1;	/* relative address */
#else
	u8         rel_adr:1;	/* relative address */
	u8         bytchk:1;	/* byte check */
	u8         ebp:1;		/* erse by-pass */
	u8         reserved2:1;
	u8         dpo:1;		/* Disable Page Out */
	u8         reserved1:3;
#endif
	u8         lba0;		/* logical block address - MSB */
	u8         lba1;
	u8         lba2;
	u8         lba3;		/* LSB */
	u8         reserved3;
	u8         xfer_length0;	/* transfer length in blocks - MSB */
	u8         xfer_length1;	/* LSB */
	u8         control;
};

#pragma pack()

#endif /* __SCSI_H__ */