17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55c46c6a0Spd144616 * Common Development and Distribution License (the "License"). 65c46c6a0Spd144616 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 215bd3d017SNikko He 227c478bd9Sstevel@tonic-gate /* 23*ba3594baSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org> 245bd3d017SNikko He * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_SCSI_IMPL_COMMANDS_H 287c478bd9Sstevel@tonic-gate #define _SYS_SCSI_IMPL_COMMANDS_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate /* 357c478bd9Sstevel@tonic-gate * Implementation dependent command definitions. 367c478bd9Sstevel@tonic-gate * This file is included by <sys/scsi/generic/commands.h> 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* 407c478bd9Sstevel@tonic-gate * Implementation dependent view of a SCSI command descriptor block 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * Standard SCSI control blocks definitions. 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate * These go in or out over the SCSI bus. 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate * The first 8 bits of the command block are the same for all 497c478bd9Sstevel@tonic-gate * defined command groups. The first byte is an operation which consists 507c478bd9Sstevel@tonic-gate * of a command code component and a group code component. 517c478bd9Sstevel@tonic-gate * 527c478bd9Sstevel@tonic-gate * The group code determines the length of the rest of the command. 537c478bd9Sstevel@tonic-gate * Group 0 commands are 6 bytes, Group 1 and 2 are 10 bytes, Group 4 547c478bd9Sstevel@tonic-gate * are 16 bytes, and Group 5 are 12 bytes. Groups 3 is Reserved. 557c478bd9Sstevel@tonic-gate * Groups 6 and 7 are Vendor Unique. 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate #define CDB_SIZE CDB_GROUP5 /* deprecated, do not use */ 597c478bd9Sstevel@tonic-gate #define SCSI_CDB_SIZE CDB_GROUP4 /* sizeof (union scsi_cdb) */ 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate union scsi_cdb { /* scsi command description block */ 627c478bd9Sstevel@tonic-gate struct { 637c478bd9Sstevel@tonic-gate uchar_t cmd; /* cmd code (byte 0) */ 647c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH) 657c478bd9Sstevel@tonic-gate uchar_t tag :5; /* rest of byte 1 */ 667c478bd9Sstevel@tonic-gate uchar_t lun :3; /* lun (byte 1) (reserved in SCSI-3) */ 677c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL) 687c478bd9Sstevel@tonic-gate uchar_t lun :3, /* lun (byte 1) (reserved in SCSI-3) */ 697c478bd9Sstevel@tonic-gate tag :5; /* rest of byte 1 */ 707c478bd9Sstevel@tonic-gate #else 717c478bd9Sstevel@tonic-gate #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 727c478bd9Sstevel@tonic-gate #endif /* _BIT_FIELDS_LTOH */ 737c478bd9Sstevel@tonic-gate union { 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate uchar_t scsi[SCSI_CDB_SIZE-2]; 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * G R O U P 0 F O R M A T (6 bytes) 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate #define scc_cmd cdb_un.cmd 807c478bd9Sstevel@tonic-gate #define scc_lun cdb_un.lun 817c478bd9Sstevel@tonic-gate #define g0_addr2 cdb_un.tag 827c478bd9Sstevel@tonic-gate #define g0_addr1 cdb_un.sg.g0.addr1 837c478bd9Sstevel@tonic-gate #define g0_addr0 cdb_un.sg.g0.addr0 847c478bd9Sstevel@tonic-gate #define g0_count0 cdb_un.sg.g0.count0 857c478bd9Sstevel@tonic-gate #define g0_vu_1 cdb_un.sg.g0.vu_57 867c478bd9Sstevel@tonic-gate #define g0_vu_0 cdb_un.sg.g0.vu_56 877c478bd9Sstevel@tonic-gate #define g0_naca cdb_un.sg.g0.naca 887c478bd9Sstevel@tonic-gate #define g0_flag cdb_un.sg.g0.flag 897c478bd9Sstevel@tonic-gate #define g0_link cdb_un.sg.g0.link 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * defines for SCSI tape cdb. 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate #define t_code cdb_un.tag 947c478bd9Sstevel@tonic-gate #define high_count cdb_un.sg.g0.addr1 957c478bd9Sstevel@tonic-gate #define mid_count cdb_un.sg.g0.addr0 967c478bd9Sstevel@tonic-gate #define low_count cdb_un.sg.g0.count0 977c478bd9Sstevel@tonic-gate struct scsi_g0 { 987c478bd9Sstevel@tonic-gate uchar_t addr1; /* middle part of address */ 997c478bd9Sstevel@tonic-gate uchar_t addr0; /* low part of address */ 1007c478bd9Sstevel@tonic-gate uchar_t count0; /* usually block count */ 1017c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH) 1027c478bd9Sstevel@tonic-gate uchar_t link :1; /* another command follows */ 1037c478bd9Sstevel@tonic-gate uchar_t flag :1; /* interrupt when done */ 1047c478bd9Sstevel@tonic-gate uchar_t naca :1; /* normal ACA */ 1057c478bd9Sstevel@tonic-gate uchar_t rsvd :3; /* reserved */ 1067c478bd9Sstevel@tonic-gate uchar_t vu_56 :1; /* vendor unique (byte 5 bit6) */ 1077c478bd9Sstevel@tonic-gate uchar_t vu_57 :1; /* vendor unique (byte 5 bit7) */ 1087c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL) 1097c478bd9Sstevel@tonic-gate uchar_t vu_57 :1; /* vendor unique (byte 5 bit 7) */ 1107c478bd9Sstevel@tonic-gate uchar_t vu_56 :1; /* vendor unique (byte 5 bit 6) */ 1117c478bd9Sstevel@tonic-gate uchar_t rsvd :3; /* reserved */ 1127c478bd9Sstevel@tonic-gate uchar_t naca :1; /* normal ACA */ 1137c478bd9Sstevel@tonic-gate uchar_t flag :1; /* interrupt when done */ 1147c478bd9Sstevel@tonic-gate uchar_t link :1; /* another command follows */ 1157c478bd9Sstevel@tonic-gate #else 1167c478bd9Sstevel@tonic-gate #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 1177c478bd9Sstevel@tonic-gate #endif /* _BIT_FIELDS_LTOH */ 1187c478bd9Sstevel@tonic-gate } g0; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * G R O U P 1, 2 F O R M A T (10 byte) 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate #define g1_reladdr cdb_un.tag 1257c478bd9Sstevel@tonic-gate #define g1_rsvd0 cdb_un.sg.g1.rsvd1 1267c478bd9Sstevel@tonic-gate #define g1_addr3 cdb_un.sg.g1.addr3 /* msb */ 1277c478bd9Sstevel@tonic-gate #define g1_addr2 cdb_un.sg.g1.addr2 1287c478bd9Sstevel@tonic-gate #define g1_addr1 cdb_un.sg.g1.addr1 1297c478bd9Sstevel@tonic-gate #define g1_addr0 cdb_un.sg.g1.addr0 /* lsb */ 1307c478bd9Sstevel@tonic-gate #define g1_count1 cdb_un.sg.g1.count1 /* msb */ 1317c478bd9Sstevel@tonic-gate #define g1_count0 cdb_un.sg.g1.count0 /* lsb */ 1327c478bd9Sstevel@tonic-gate #define g1_vu_1 cdb_un.sg.g1.vu_97 1337c478bd9Sstevel@tonic-gate #define g1_vu_0 cdb_un.sg.g1.vu_96 1347c478bd9Sstevel@tonic-gate #define g1_naca cdb_un.sg.g1.naca 1357c478bd9Sstevel@tonic-gate #define g1_flag cdb_un.sg.g1.flag 1367c478bd9Sstevel@tonic-gate #define g1_link cdb_un.sg.g1.link 1377c478bd9Sstevel@tonic-gate struct scsi_g1 { 1387c478bd9Sstevel@tonic-gate uchar_t addr3; /* most sig. byte of address */ 1397c478bd9Sstevel@tonic-gate uchar_t addr2; 1407c478bd9Sstevel@tonic-gate uchar_t addr1; 1417c478bd9Sstevel@tonic-gate uchar_t addr0; 1427c478bd9Sstevel@tonic-gate uchar_t rsvd1; /* reserved (byte 6) */ 1437c478bd9Sstevel@tonic-gate uchar_t count1; /* transfer length (msb) */ 1447c478bd9Sstevel@tonic-gate uchar_t count0; /* transfer length (lsb) */ 1457c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH) 1467c478bd9Sstevel@tonic-gate uchar_t link :1; /* another command follows */ 1477c478bd9Sstevel@tonic-gate uchar_t flag :1; /* interrupt when done */ 1487c478bd9Sstevel@tonic-gate uchar_t naca :1; /* normal ACA */ 1497c478bd9Sstevel@tonic-gate uchar_t rsvd0 :3; /* reserved */ 1507c478bd9Sstevel@tonic-gate uchar_t vu_96 :1; /* vendor unique (byte 9 bit6) */ 1517c478bd9Sstevel@tonic-gate uchar_t vu_97 :1; /* vendor unique (byte 9 bit7) */ 1527c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL) 1537c478bd9Sstevel@tonic-gate uchar_t vu_97 :1; /* vendor unique (byte 9 bit 7) */ 1547c478bd9Sstevel@tonic-gate uchar_t vu_96 :1; /* vendor unique (byte 9 bit 6) */ 1557c478bd9Sstevel@tonic-gate uchar_t rsvd0 :3; /* reserved */ 1567c478bd9Sstevel@tonic-gate uchar_t naca :1; /* normal ACA */ 1577c478bd9Sstevel@tonic-gate uchar_t flag :1; /* interrupt when done */ 1587c478bd9Sstevel@tonic-gate uchar_t link :1; /* another command follows */ 1597c478bd9Sstevel@tonic-gate #else 1607c478bd9Sstevel@tonic-gate #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 1617c478bd9Sstevel@tonic-gate #endif /* _BIT_FIELDS_LTOH */ 1627c478bd9Sstevel@tonic-gate } g1; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * G R O U P 4 F O R M A T (16 byte) 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate #define g4_reladdr cdb_un.tag 1687c478bd9Sstevel@tonic-gate #define g4_addr3 cdb_un.sg.g4.addr3 /* msb */ 1697c478bd9Sstevel@tonic-gate #define g4_addr2 cdb_un.sg.g4.addr2 1707c478bd9Sstevel@tonic-gate #define g4_addr1 cdb_un.sg.g4.addr1 1717c478bd9Sstevel@tonic-gate #define g4_addr0 cdb_un.sg.g4.addr0 /* lsb */ 1727c478bd9Sstevel@tonic-gate #define g4_addtl_cdb_data3 cdb_un.sg.g4.addtl_cdb_data3 1737c478bd9Sstevel@tonic-gate #define g4_addtl_cdb_data2 cdb_un.sg.g4.addtl_cdb_data2 1747c478bd9Sstevel@tonic-gate #define g4_addtl_cdb_data1 cdb_un.sg.g4.addtl_cdb_data1 1757c478bd9Sstevel@tonic-gate #define g4_addtl_cdb_data0 cdb_un.sg.g4.addtl_cdb_data0 1767c478bd9Sstevel@tonic-gate #define g4_count3 cdb_un.sg.g4.count3 /* msb */ 1777c478bd9Sstevel@tonic-gate #define g4_count2 cdb_un.sg.g4.count2 1787c478bd9Sstevel@tonic-gate #define g4_count1 cdb_un.sg.g4.count1 1797c478bd9Sstevel@tonic-gate #define g4_count0 cdb_un.sg.g4.count0 /* lsb */ 1807c478bd9Sstevel@tonic-gate #define g4_rsvd0 cdb_un.sg.g4.rsvd1 1817c478bd9Sstevel@tonic-gate #define g4_vu_1 cdb_un.sg.g4.vu_157 1827c478bd9Sstevel@tonic-gate #define g4_vu_0 cdb_un.sg.g4.vu_156 1837c478bd9Sstevel@tonic-gate #define g4_naca cdb_un.sg.g4.naca 1847c478bd9Sstevel@tonic-gate #define g4_flag cdb_un.sg.g4.flag 1857c478bd9Sstevel@tonic-gate #define g4_link cdb_un.sg.g4.link 1867c478bd9Sstevel@tonic-gate struct scsi_g4 { 1877c478bd9Sstevel@tonic-gate uchar_t addr3; /* most sig. byte of address */ 1887c478bd9Sstevel@tonic-gate uchar_t addr2; 1897c478bd9Sstevel@tonic-gate uchar_t addr1; 1907c478bd9Sstevel@tonic-gate uchar_t addr0; 1917c478bd9Sstevel@tonic-gate uchar_t addtl_cdb_data3; 1927c478bd9Sstevel@tonic-gate uchar_t addtl_cdb_data2; 1937c478bd9Sstevel@tonic-gate uchar_t addtl_cdb_data1; 1947c478bd9Sstevel@tonic-gate uchar_t addtl_cdb_data0; 1957c478bd9Sstevel@tonic-gate uchar_t count3; /* transfer length (msb) */ 1967c478bd9Sstevel@tonic-gate uchar_t count2; 1977c478bd9Sstevel@tonic-gate uchar_t count1; 1987c478bd9Sstevel@tonic-gate uchar_t count0; /* transfer length (lsb) */ 1997c478bd9Sstevel@tonic-gate uchar_t rsvd1; /* reserved */ 2007c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH) 2017c478bd9Sstevel@tonic-gate uchar_t link :1; /* another command follows */ 2027c478bd9Sstevel@tonic-gate uchar_t flag :1; /* interrupt when done */ 2037c478bd9Sstevel@tonic-gate uchar_t naca :1; /* normal ACA */ 2047c478bd9Sstevel@tonic-gate uchar_t rsvd0 :3; /* reserved */ 2057c478bd9Sstevel@tonic-gate uchar_t vu_156 :1; /* vendor unique (byte 15 bit6) */ 2067c478bd9Sstevel@tonic-gate uchar_t vu_157 :1; /* vendor unique (byte 15 bit7) */ 2077c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL) 2087c478bd9Sstevel@tonic-gate uchar_t vu_157 :1; /* vendor unique (byte 15 bit 7) */ 2097c478bd9Sstevel@tonic-gate uchar_t vu_156 :1; /* vendor unique (byte 15 bit 6) */ 2107c478bd9Sstevel@tonic-gate uchar_t rsvd0 :3; /* reserved */ 2117c478bd9Sstevel@tonic-gate uchar_t naca :1; /* normal ACA */ 2127c478bd9Sstevel@tonic-gate uchar_t flag :1; /* interrupt when done */ 2137c478bd9Sstevel@tonic-gate uchar_t link :1; /* another command follows */ 2147c478bd9Sstevel@tonic-gate #else 2157c478bd9Sstevel@tonic-gate #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 2167c478bd9Sstevel@tonic-gate #endif /* _BIT_FIELDS_LTOH */ 2177c478bd9Sstevel@tonic-gate } g4; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate /* 2207c478bd9Sstevel@tonic-gate * G R O U P 5 F O R M A T (12 byte) 2217c478bd9Sstevel@tonic-gate */ 2227c478bd9Sstevel@tonic-gate #define scc5_reladdr cdb_un.tag 2237c478bd9Sstevel@tonic-gate #define scc5_addr3 cdb_un.sg.g5.addr3 /* msb */ 2247c478bd9Sstevel@tonic-gate #define scc5_addr2 cdb_un.sg.g5.addr2 2257c478bd9Sstevel@tonic-gate #define scc5_addr1 cdb_un.sg.g5.addr1 2267c478bd9Sstevel@tonic-gate #define scc5_addr0 cdb_un.sg.g5.addr0 /* lsb */ 2277c478bd9Sstevel@tonic-gate #define scc5_count3 cdb_un.sg.g5.count3 /* msb */ 2287c478bd9Sstevel@tonic-gate #define scc5_count2 cdb_un.sg.g5.count2 2297c478bd9Sstevel@tonic-gate #define scc5_count1 cdb_un.sg.g5.count1 2307c478bd9Sstevel@tonic-gate #define scc5_count0 cdb_un.sg.g5.count0 /* lsb */ 2317c478bd9Sstevel@tonic-gate #define scc5_rsvd0 cdb_un.sg.g5.rsvd1 2327c478bd9Sstevel@tonic-gate #define scc5_vu_1 cdb_un.sg.g5.v117 2337c478bd9Sstevel@tonic-gate #define scc5_vu_0 cdb_un.sg.g5.v116 2347c478bd9Sstevel@tonic-gate #define scc5_naca cdb_un.sg.g5.naca 2357c478bd9Sstevel@tonic-gate #define scc5_flag cdb_un.sg.g5.flag 2367c478bd9Sstevel@tonic-gate #define scc5_link cdb_un.sg.g5.link 2377c478bd9Sstevel@tonic-gate struct scsi_g5 { 2387c478bd9Sstevel@tonic-gate uchar_t addr3; /* most sig. byte of address */ 2397c478bd9Sstevel@tonic-gate uchar_t addr2; 2407c478bd9Sstevel@tonic-gate uchar_t addr1; 2417c478bd9Sstevel@tonic-gate uchar_t addr0; 2427c478bd9Sstevel@tonic-gate uchar_t count3; /* most sig. byte of count */ 2437c478bd9Sstevel@tonic-gate uchar_t count2; 2447c478bd9Sstevel@tonic-gate uchar_t count1; 2457c478bd9Sstevel@tonic-gate uchar_t count0; 2467c478bd9Sstevel@tonic-gate uchar_t rsvd1; /* reserved */ 2477c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH) 2487c478bd9Sstevel@tonic-gate uchar_t link :1; /* another command follows */ 2497c478bd9Sstevel@tonic-gate uchar_t flag :1; /* interrupt when done */ 2507c478bd9Sstevel@tonic-gate uchar_t naca :1; /* normal ACA */ 2517c478bd9Sstevel@tonic-gate uchar_t rsvd0 :3; /* reserved */ 2527c478bd9Sstevel@tonic-gate uchar_t vu_116 :1; /* vendor unique (byte 11 bit6) */ 2537c478bd9Sstevel@tonic-gate uchar_t vu_117 :1; /* vendor unique (byte 11 bit7) */ 2547c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL) 2557c478bd9Sstevel@tonic-gate uchar_t vu_117 :1; /* vendor unique (byte 11 bit 7) */ 2567c478bd9Sstevel@tonic-gate uchar_t vu_116 :1; /* vendor unique (byte 11 bit 6) */ 2577c478bd9Sstevel@tonic-gate uchar_t rsvd0 :3; /* reserved */ 2587c478bd9Sstevel@tonic-gate uchar_t naca :1; /* normal ACA */ 2597c478bd9Sstevel@tonic-gate uchar_t flag :1; /* interrupt when done */ 2607c478bd9Sstevel@tonic-gate uchar_t link :1; /* another command follows */ 2617c478bd9Sstevel@tonic-gate #else 2627c478bd9Sstevel@tonic-gate #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 2637c478bd9Sstevel@tonic-gate #endif /* _BIT_FIELDS_LTOH */ 2647c478bd9Sstevel@tonic-gate } g5; 2657c478bd9Sstevel@tonic-gate }sg; 2667c478bd9Sstevel@tonic-gate } cdb_un; 2677c478bd9Sstevel@tonic-gate uchar_t cdb_opaque[SCSI_CDB_SIZE]; /* addressed as opaque char array */ 2687c478bd9Sstevel@tonic-gate uint_t cdb_long[SCSI_CDB_SIZE / sizeof (uint_t)]; /* as a word array */ 2697c478bd9Sstevel@tonic-gate }; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate /* 2737c478bd9Sstevel@tonic-gate * Various useful Macros for SCSI commands 2747c478bd9Sstevel@tonic-gate */ 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate /* 2775c46c6a0Spd144616 * defines for getting/setting fields in data received from or destined for 2785c46c6a0Spd144616 * a SCSI device. These macros are necessary (in place of BE16/BE32/BE64) 2795c46c6a0Spd144616 * because the address to be read or written may not be on a proper alignment. 2805c46c6a0Spd144616 */ 2815c46c6a0Spd144616 2825c46c6a0Spd144616 #define SCSI_READ16(Sr16_Addr) \ 2835c46c6a0Spd144616 (((uint16_t)*((uint8_t *)(Sr16_Addr)) << 8) | \ 284275c9da8Seschrock ((uint16_t)*((uint8_t *)(Sr16_Addr)+1))) 285275c9da8Seschrock 286275c9da8Seschrock #define SCSI_READ24(Sr32_Addr) \ 287275c9da8Seschrock (((uint32_t)*((uint8_t *)(Sr32_Addr)) << 16) | \ 288275c9da8Seschrock ((uint32_t)*((uint8_t *)(Sr32_Addr)+1) << 8) | \ 289275c9da8Seschrock ((uint32_t)*((uint8_t *)(Sr32_Addr)+2))) 2905c46c6a0Spd144616 2915c46c6a0Spd144616 #define SCSI_READ32(Sr32_Addr) \ 2925c46c6a0Spd144616 (((uint32_t)*((uint8_t *)(Sr32_Addr)) << 24) | \ 293275c9da8Seschrock ((uint32_t)*((uint8_t *)(Sr32_Addr)+1) << 16) | \ 294275c9da8Seschrock ((uint32_t)*((uint8_t *)(Sr32_Addr)+2) << 8) | \ 295275c9da8Seschrock ((uint32_t)*((uint8_t *)(Sr32_Addr)+3))) 296275c9da8Seschrock 297275c9da8Seschrock #define SCSI_READ40(Sr64_Addr) \ 298275c9da8Seschrock (((uint64_t)*((uint8_t *)(Sr64_Addr)) << 32) | \ 299275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 24) | \ 300275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 16) | \ 301275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 8) | \ 302275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+4))) 303275c9da8Seschrock 304275c9da8Seschrock #define SCSI_READ48(Sr64_Addr) \ 305275c9da8Seschrock (((uint64_t)*((uint8_t *)(Sr64_Addr)) << 40) | \ 306275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 32) | \ 307275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 24) | \ 308275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 16) | \ 309275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+4) << 8) | \ 310275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+5))) 3115c46c6a0Spd144616 3125c46c6a0Spd144616 #define SCSI_READ64(Sr64_Addr) \ 3135c46c6a0Spd144616 (((uint64_t)*((uint8_t *)(Sr64_Addr)) << 56) | \ 314275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 48) | \ 315275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 40) | \ 316275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 32) | \ 317275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+4) << 24) | \ 318275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+5) << 16) | \ 319275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+6) << 8) | \ 320275c9da8Seschrock ((uint64_t)*((uint8_t *)(Sr64_Addr)+7))) 3215c46c6a0Spd144616 3225c46c6a0Spd144616 #define SCSI_WRITE16(Sr16_Addr, Sr16_Val) \ 323275c9da8Seschrock *((uint8_t *)(Sr16_Addr)) = (((uint16_t)(Sr16_Val) >> 8) & 0xff), \ 324275c9da8Seschrock *((uint8_t *)(Sr16_Addr)+1) = ((uint16_t)(Sr16_Val) & 0xff) 325275c9da8Seschrock 326275c9da8Seschrock #define SCSI_WRITE24(Sr24_Addr, Sr24_Val) \ 327275c9da8Seschrock SCSI_WRITE16((Sr24_Addr), ((Sr24_Val) & 0xffff00) >> 8), \ 328275c9da8Seschrock *((uint8_t *)(Sr24_Addr)+2) = ((uint8_t)((Sr24_Val) & 0xff)) 3295c46c6a0Spd144616 3305c46c6a0Spd144616 #define SCSI_WRITE32(Sr32_Addr, Sr32_Val) \ 331275c9da8Seschrock *(uint8_t *)(Sr32_Addr) = (((uint32_t)(Sr32_Val) >> 24) & 0xff), \ 332275c9da8Seschrock *((uint8_t *)(Sr32_Addr)+1) = \ 333275c9da8Seschrock (((uint32_t)(Sr32_Val) >> 16) & 0xff), \ 334275c9da8Seschrock *((uint8_t *)(Sr32_Addr)+2) = (((uint32_t)(Sr32_Val) >> 8) & 0xff), \ 335275c9da8Seschrock *((uint8_t *)(Sr32_Addr)+3) = (((uint32_t)(Sr32_Val)) & 0xff) 336275c9da8Seschrock 337275c9da8Seschrock #define SCSI_WRITE40(Sr40_Addr, Sr40_Val) \ 338275c9da8Seschrock SCSI_WRITE32((Sr40_Addr), ((Sr40_Val) & 0xffffffff00ULL) >> 8), \ 339275c9da8Seschrock *((uint8_t *)(Sr40_Addr)+4) = ((uint8_t)(Sr40_Val) & 0xff) 340275c9da8Seschrock 341275c9da8Seschrock #define SCSI_WRITE48(Sr48_Addr, Sr40_Val) \ 342275c9da8Seschrock SCSI_WRITE32((Sr48_Addr), ((Sr48_Val) & 0xffffffff0000ULL) >> 16), \ 343275c9da8Seschrock SCSI_WRITE16((uint8_t *)(Sr48_Addr)+4, (Sr40_Val) & 0xffff) 3445c46c6a0Spd144616 3455c46c6a0Spd144616 #define SCSI_WRITE64(Sr64_Addr, Sr64_Val) \ 346275c9da8Seschrock *(uint8_t *)(Sr64_Addr) = (((uint64_t)(Sr64_Val) >> 56) & 0xff), \ 347275c9da8Seschrock *((uint8_t *)(Sr64_Addr)+1) = \ 348275c9da8Seschrock (((uint64_t)(Sr64_Val) >> 48) & 0xff), \ 349275c9da8Seschrock *((uint8_t *)(Sr64_Addr)+2) = \ 350275c9da8Seschrock (((uint64_t)(Sr64_Val) >> 40) & 0xff), \ 351275c9da8Seschrock *((uint8_t *)(Sr64_Addr)+3) = \ 352275c9da8Seschrock (((uint64_t)(Sr64_Val) >> 32) & 0xff), \ 353275c9da8Seschrock *((uint8_t *)(Sr64_Addr)+4) = \ 354275c9da8Seschrock (((uint64_t)(Sr64_Val) >> 24) & 0xff), \ 355275c9da8Seschrock *((uint8_t *)(Sr64_Addr)+5) = \ 356275c9da8Seschrock (((uint64_t)(Sr64_Val) >> 16) & 0xff), \ 357275c9da8Seschrock *((uint8_t *)(Sr64_Addr)+6) = \ 358275c9da8Seschrock (((uint64_t)(Sr64_Val) >> 8) & 0xff), \ 359275c9da8Seschrock *((uint8_t *)(Sr64_Addr)+7) = (((uint64_t)(Sr64_Val)) & 0xff) 360275c9da8Seschrock 361275c9da8Seschrock /* 362275c9da8Seschrock * These macros deal with unaligned data that crosses a byte boundary. 363275c9da8Seschrock */ 364275c9da8Seschrock #define SCSI_MK8(ms, ls) \ 365275c9da8Seschrock (((uint8_t)(ms) << 4) | (uint8_t)ls) 366275c9da8Seschrock 367275c9da8Seschrock #define SCSI_MK12_4_8(ms, ls) \ 368275c9da8Seschrock (((uint16_t)(ms) << 8) | (uint16_t)(ls)) 369275c9da8Seschrock #define SCSI_MK12_8_4(ms, ls) \ 370275c9da8Seschrock (((uint16_t)(ms) << 4) | (uint16_t)(ls)) 371275c9da8Seschrock 372275c9da8Seschrock #define SCSI_MK16_4_8_4(hi, mid, lo) \ 373275c9da8Seschrock (((uint16_t)(hi) << 12) | ((uint16_t)(mid) << 4) | (uint16_t)(lo)) 374275c9da8Seschrock 375275c9da8Seschrock #define SCSI_MK20_4_16(ms, ls) \ 376275c9da8Seschrock (((uint32_t)(ms) << 16) | ((uint32_t)(ls))) 377275c9da8Seschrock #define SCSI_MK20_16_4(ms, ls) \ 378275c9da8Seschrock (((uint32_t)(ms) << 4) | ((uint32_t)(ls))) 379275c9da8Seschrock 380275c9da8Seschrock #define SCSI_MK24_4_16_4(hi, mid, lo) \ 381275c9da8Seschrock (((uint32_t)(hi) << 20) | ((uint32_t)(mid) << 4) | (uint32_t)(lo)) 382275c9da8Seschrock 383275c9da8Seschrock #define SCSI_MK36_4_32(ms, ls) \ 384275c9da8Seschrock (((uint64_t)(ms) << 32) | (uint64_t)(ls)) 385275c9da8Seschrock #define SCSI_MK36_32_4(ms, ls) \ 386275c9da8Seschrock (((uint64_t)(ms) << 4) | (uint64_t)(ls)) 3875c46c6a0Spd144616 3885c46c6a0Spd144616 /* 3897c478bd9Sstevel@tonic-gate * defines for getting/setting fields within the various command groups 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate #define GETCMD(cdb) ((cdb)->scc_cmd & 0x1F) 3937c478bd9Sstevel@tonic-gate #define GETGROUP(cdb) (CDB_GROUPID((cdb)->scc_cmd)) 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate #define FORMG0COUNT(cdb, cnt) (cdb)->g0_count0 = (cnt) 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate #define FORMG0ADDR(cdb, addr) (cdb)->g0_addr2 = (addr) >> 16; \ 3987c478bd9Sstevel@tonic-gate (cdb)->g0_addr1 = ((addr) >> 8) & 0xFF; \ 3997c478bd9Sstevel@tonic-gate (cdb)->g0_addr0 = (addr) & 0xFF 4007c478bd9Sstevel@tonic-gate 40136c5fee3Smcneal #define GETG0COUNT(cdb) (cdb)->g0_count0 40236c5fee3Smcneal 40336c5fee3Smcneal #define GETG0ADDR(cdb) ((((cdb)->g0_addr2 & 0x1F) << 16) + \ 40436c5fee3Smcneal ((cdb)->g0_addr1 << 8) + ((cdb)->g0_addr0)) 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate #define GETG0TAG(cdb) ((cdb)->g0_addr2) 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate #define FORMG0COUNT_S(cdb, cnt) (cdb)->high_count = (cnt) >> 16; \ 4097c478bd9Sstevel@tonic-gate (cdb)->mid_count = ((cnt) >> 8) & 0xFF; \ 4107c478bd9Sstevel@tonic-gate (cdb)->low_count = (cnt) & 0xFF 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate #define FORMG1COUNT(cdb, cnt) (cdb)->g1_count1 = ((cnt) >> 8); \ 4137c478bd9Sstevel@tonic-gate (cdb)->g1_count0 = (cnt) & 0xFF 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate #define FORMG1ADDR(cdb, addr) (cdb)->g1_addr3 = (addr) >> 24; \ 4167c478bd9Sstevel@tonic-gate (cdb)->g1_addr2 = ((addr) >> 16) & 0xFF; \ 4177c478bd9Sstevel@tonic-gate (cdb)->g1_addr1 = ((addr) >> 8) & 0xFF; \ 4187c478bd9Sstevel@tonic-gate (cdb)->g1_addr0 = (addr) & 0xFF 4197c478bd9Sstevel@tonic-gate 42036c5fee3Smcneal #define GETG1COUNT(cdb) (((cdb)->g1_count1 << 8) + ((cdb)->g1_count0)) 42136c5fee3Smcneal 42236c5fee3Smcneal #define GETG1ADDR(cdb) (((cdb)->g1_addr3 << 24) + \ 4237c478bd9Sstevel@tonic-gate ((cdb)->g1_addr2 << 16) + \ 4247c478bd9Sstevel@tonic-gate ((cdb)->g1_addr1 << 8) + \ 42536c5fee3Smcneal ((cdb)->g1_addr0)) 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate #define GETG1TAG(cdb) (cdb)->g1_reladdr 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate #define FORMG4COUNT(cdb, cnt) (cdb)->g4_count3 = ((cnt) >> 24); \ 4307c478bd9Sstevel@tonic-gate (cdb)->g4_count2 = ((cnt) >> 16) & 0xFF; \ 4317c478bd9Sstevel@tonic-gate (cdb)->g4_count1 = ((cnt) >> 8) & 0xFF; \ 4327c478bd9Sstevel@tonic-gate (cdb)->g4_count0 = (cnt) & 0xFF 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate #define FORMG4LONGADDR(cdb, addr) (cdb)->g4_addr3 = (addr) >> 56; \ 4357c478bd9Sstevel@tonic-gate (cdb)->g4_addr2 = \ 4367c478bd9Sstevel@tonic-gate ((addr) >> 48) & 0xFF; \ 4377c478bd9Sstevel@tonic-gate (cdb)->g4_addr1 = \ 4387c478bd9Sstevel@tonic-gate ((addr) >> 40) & 0xFF; \ 4397c478bd9Sstevel@tonic-gate (cdb)->g4_addr0 = \ 4407c478bd9Sstevel@tonic-gate ((addr) >> 32) & 0xFF; \ 4417c478bd9Sstevel@tonic-gate (cdb)->g4_addtl_cdb_data3 = \ 4427c478bd9Sstevel@tonic-gate ((addr) >> 24) & 0xFF; \ 4437c478bd9Sstevel@tonic-gate (cdb)->g4_addtl_cdb_data2 = \ 4447c478bd9Sstevel@tonic-gate ((addr) >> 16) & 0xFF; \ 4457c478bd9Sstevel@tonic-gate (cdb)->g4_addtl_cdb_data1 = \ 4467c478bd9Sstevel@tonic-gate ((addr) >> 8) & 0xFF; \ 4477c478bd9Sstevel@tonic-gate (cdb)->g4_addtl_cdb_data0 = \ 4487c478bd9Sstevel@tonic-gate (addr) & 0xFF 4497c478bd9Sstevel@tonic-gate 45036c5fee3Smcneal #define GETG4COUNT(cdb) (((cdb)->g4_count3 << 24) + \ 45136c5fee3Smcneal ((cdb)->g4_count2 << 16) + \ 45236c5fee3Smcneal ((cdb)->g4_count1 << 8) + \ 45336c5fee3Smcneal ((cdb)->g4_count0)) 45436c5fee3Smcneal 45536c5fee3Smcneal #define GETG4LONGADDR(cdb) (((diskaddr_t)(cdb)->g4_addr3 << 56) + \ 45636c5fee3Smcneal ((diskaddr_t)(cdb)->g4_addr2 << 48) + \ 45736c5fee3Smcneal ((diskaddr_t)(cdb)->g4_addr1 << 40) + \ 45836c5fee3Smcneal ((diskaddr_t)(cdb)->g4_addr0 << 32) + \ 45936c5fee3Smcneal ((diskaddr_t)(cdb)->g4_addtl_cdb_data3 << 24) + \ 46036c5fee3Smcneal ((diskaddr_t)(cdb)->g4_addtl_cdb_data2 << 16) + \ 46136c5fee3Smcneal ((diskaddr_t)(cdb)->g4_addtl_cdb_data1 << 8) + \ 46236c5fee3Smcneal ((diskaddr_t)(cdb)->g4_addtl_cdb_data0)) 46336c5fee3Smcneal 4647c478bd9Sstevel@tonic-gate #define FORMG4ADDR(cdb, addr) (cdb)->g4_addr3 = (addr) >> 24; \ 4657c478bd9Sstevel@tonic-gate (cdb)->g4_addr2 = ((addr) >> 16) & 0xFF; \ 4667c478bd9Sstevel@tonic-gate (cdb)->g4_addr1 = ((addr) >> 8) & 0xFF; \ 4677c478bd9Sstevel@tonic-gate (cdb)->g4_addr0 = (addr) & 0xFF 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate #define FORMG4ADDTL(cdb, addtl_cdb_data) (cdb)->g4_addtl_cdb_data3 = \ 4707c478bd9Sstevel@tonic-gate (addtl_cdb_data) >> 24; \ 4717c478bd9Sstevel@tonic-gate (cdb)->g4_addtl_cdb_data2 = \ 4727c478bd9Sstevel@tonic-gate ((addtl_cdb_data) >> 16) & 0xFF; \ 4737c478bd9Sstevel@tonic-gate (cdb)->g4_addtl_cdb_data1 = \ 4747c478bd9Sstevel@tonic-gate ((addtl_cdb_data) >> 8) & 0xFF; \ 4757c478bd9Sstevel@tonic-gate (cdb)->g4_addtl_cdb_data0 = \ 4767c478bd9Sstevel@tonic-gate (addtl_cdb_data) & 0xFF 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate #define GETG4ADDR(cdb) ((cdb)->g4_addr3 << 24) + \ 4797c478bd9Sstevel@tonic-gate ((cdb)->g4_addr2 << 16) + \ 4807c478bd9Sstevel@tonic-gate ((cdb)->g4_addr1 << 8) + \ 4817c478bd9Sstevel@tonic-gate ((cdb)->g4_addr0) 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate #define GETG4ADDRTL(cdb) (((cdb)->g4_addtl_cdb_data3 << 24) + \ 4847c478bd9Sstevel@tonic-gate ((cdb)->g4_addtl_cdb_data2 << 16) + \ 4857c478bd9Sstevel@tonic-gate ((cdb)->g4_addtl_cdb_data1 << 8) + \ 4867c478bd9Sstevel@tonic-gate (cdb)->g4_addtl_cdb_data0) 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate #define GETG4TAG(cdb) (cdb)->g4_reladdr 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate #define FORMG5COUNT(cdb, cnt) (cdb)->scc5_count3 = ((cnt) >> 24); \ 4917c478bd9Sstevel@tonic-gate (cdb)->scc5_count2 = ((cnt) >> 16) & 0xFF; \ 4927c478bd9Sstevel@tonic-gate (cdb)->scc5_count1 = ((cnt) >> 8) & 0xFF; \ 4937c478bd9Sstevel@tonic-gate (cdb)->scc5_count0 = (cnt) & 0xFF 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate #define FORMG5ADDR(cdb, addr) (cdb)->scc5_addr3 = (addr) >> 24; \ 4967c478bd9Sstevel@tonic-gate (cdb)->scc5_addr2 = ((addr) >> 16) & 0xFF; \ 4977c478bd9Sstevel@tonic-gate (cdb)->scc5_addr1 = ((addr) >> 8) & 0xFF; \ 4987c478bd9Sstevel@tonic-gate (cdb)->scc5_addr0 = (addr) & 0xFF 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate #define GETG5ADDR(cdb) ((cdb)->scc5_addr3 << 24) + \ 5017c478bd9Sstevel@tonic-gate ((cdb)->scc5_addr2 << 16) + \ 5027c478bd9Sstevel@tonic-gate ((cdb)->scc5_addr1 << 8) + \ 5037c478bd9Sstevel@tonic-gate ((cdb)->scc5_addr0) 5047c478bd9Sstevel@tonic-gate 5058a16ae8fSmcneal #define GETG5COUNT(cdb) ((cdb)->scc5_count3 << 24) + \ 5068a16ae8fSmcneal ((cdb)->scc5_count2 << 16) + \ 5078a16ae8fSmcneal ((cdb)->scc5_count1 << 8) + \ 5088a16ae8fSmcneal ((cdb)->scc5_count0) 5098a16ae8fSmcneal 5107c478bd9Sstevel@tonic-gate #define GETG5TAG(cdb) (cdb)->scc5_reladdr 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate /* 5147c478bd9Sstevel@tonic-gate * Shorthand macros for forming commands 5157c478bd9Sstevel@tonic-gate * 5167c478bd9Sstevel@tonic-gate * Works only with pre-SCSI-3 because they put lun as part of CDB. 5177c478bd9Sstevel@tonic-gate * scsi_setup_cdb() is the recommended interface. 5187c478bd9Sstevel@tonic-gate */ 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate #define MAKECOM_COMMON(pktp, devp, flag, cmd) \ 5217c478bd9Sstevel@tonic-gate (pktp)->pkt_address = (devp)->sd_address, \ 5227c478bd9Sstevel@tonic-gate (pktp)->pkt_flags = (flag), \ 5237c478bd9Sstevel@tonic-gate ((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \ 5247c478bd9Sstevel@tonic-gate ((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \ 5257c478bd9Sstevel@tonic-gate (pktp)->pkt_address.a_lun 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate #define MAKECOM_G0(pktp, devp, flag, cmd, addr, cnt) \ 5287c478bd9Sstevel@tonic-gate MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \ 5297c478bd9Sstevel@tonic-gate FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \ 5307c478bd9Sstevel@tonic-gate FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt)) 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate #define MAKECOM_G0_S(pktp, devp, flag, cmd, cnt, fixbit) \ 5337c478bd9Sstevel@tonic-gate MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \ 5347c478bd9Sstevel@tonic-gate FORMG0COUNT_S(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt)), \ 5357c478bd9Sstevel@tonic-gate ((union scsi_cdb *)(pktp)->pkt_cdbp)->t_code = (fixbit) 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate #define MAKECOM_G1(pktp, devp, flag, cmd, addr, cnt) \ 5387c478bd9Sstevel@tonic-gate MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \ 5397c478bd9Sstevel@tonic-gate FORMG1ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \ 5407c478bd9Sstevel@tonic-gate FORMG1COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt)) 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate #define MAKECOM_G5(pktp, devp, flag, cmd, addr, cnt) \ 5437c478bd9Sstevel@tonic-gate MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \ 5447c478bd9Sstevel@tonic-gate FORMG5ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \ 5457c478bd9Sstevel@tonic-gate FORMG5COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt)) 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate /* 5497c478bd9Sstevel@tonic-gate * Direct access disk format defines and parameters. 5507c478bd9Sstevel@tonic-gate * 5517c478bd9Sstevel@tonic-gate * This is still pretty ugly and is mostly derived 5527c478bd9Sstevel@tonic-gate * from Emulex MD21 specific formatting. 5537c478bd9Sstevel@tonic-gate */ 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate #define fmt_parm_bits g0_addr2 /* for format options */ 5567c478bd9Sstevel@tonic-gate #define fmt_interleave g0_count0 /* for encode interleave */ 5577c478bd9Sstevel@tonic-gate #define defect_list_descrip g1_addr3 /* list description bits */ 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate /* 5607c478bd9Sstevel@tonic-gate * defines for value of fmt_parm_bits. 5617c478bd9Sstevel@tonic-gate */ 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate #define FPB_BFI 0x04 /* bytes-from-index fmt */ 5647c478bd9Sstevel@tonic-gate #define FPB_CMPLT 0x08 /* full defect list provided */ 5657c478bd9Sstevel@tonic-gate #define FPB_DATA 0x10 /* defect list data provided */ 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate /* 5687c478bd9Sstevel@tonic-gate * Defines for value of defect_list_descrip. 5697c478bd9Sstevel@tonic-gate */ 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate #define DLD_MAN_DEF_LIST 0x10 /* manufacturer's defect list */ 5727c478bd9Sstevel@tonic-gate #define DLD_GROWN_DEF_LIST 0x08 /* grown defect list */ 5737c478bd9Sstevel@tonic-gate #define DLD_BLOCK_FORMAT 0x00 /* block format */ 5747c478bd9Sstevel@tonic-gate #define DLD_BFI_FORMAT 0x04 /* bytes-from-index format */ 5757c478bd9Sstevel@tonic-gate #define DLD_PS_FORMAT 0x05 /* physical sector format */ 5767c478bd9Sstevel@tonic-gate 5775bd3d017SNikko He /* 5785bd3d017SNikko He * Defines for value of CONTROL byte of cdb. 5795bd3d017SNikko He */ 5805bd3d017SNikko He #define CDB_FLAG_NACA 0x04 /* naca flag */ 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate /* 5837c478bd9Sstevel@tonic-gate * Disk defect list - used by format command. 5847c478bd9Sstevel@tonic-gate */ 5857c478bd9Sstevel@tonic-gate #define RDEF_ALL 0 /* read all defects */ 5867c478bd9Sstevel@tonic-gate #define RDEF_MANUF 1 /* read manufacturer's defects */ 5877c478bd9Sstevel@tonic-gate #define RDEF_CKLEN 2 /* check length of manufacturer's list */ 5887c478bd9Sstevel@tonic-gate #define ST506_NDEFECT 127 /* must fit in 1K controller buffer... */ 5897c478bd9Sstevel@tonic-gate #define ESDI_NDEFECT ST506_NDEFECT 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate struct scsi_bfi_defect { /* defect in bytes from index format */ 5927c478bd9Sstevel@tonic-gate unsigned cyl : 24; 5937c478bd9Sstevel@tonic-gate unsigned head : 8; 5947c478bd9Sstevel@tonic-gate int bytes_from_index; 5957c478bd9Sstevel@tonic-gate }; 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate struct scsi_format_params { /* BFI format list */ 5987c478bd9Sstevel@tonic-gate ushort_t reserved; 5997c478bd9Sstevel@tonic-gate ushort_t length; 6007c478bd9Sstevel@tonic-gate struct scsi_bfi_defect list[ESDI_NDEFECT]; 6017c478bd9Sstevel@tonic-gate }; 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate /* 6047c478bd9Sstevel@tonic-gate * Defect list returned by READ_DEFECT_LIST command. 6057c478bd9Sstevel@tonic-gate */ 6067c478bd9Sstevel@tonic-gate struct scsi_defect_hdr { /* For getting defect list size */ 6077c478bd9Sstevel@tonic-gate uchar_t reserved; 6087c478bd9Sstevel@tonic-gate uchar_t descriptor; 6097c478bd9Sstevel@tonic-gate ushort_t length; 6107c478bd9Sstevel@tonic-gate }; 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate struct scsi_defect_list { /* BFI format list */ 6137c478bd9Sstevel@tonic-gate uchar_t reserved; 6147c478bd9Sstevel@tonic-gate uchar_t descriptor; 6157c478bd9Sstevel@tonic-gate ushort_t length; 6167c478bd9Sstevel@tonic-gate struct scsi_bfi_defect list[ESDI_NDEFECT]; 6177c478bd9Sstevel@tonic-gate }; 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate /* 6207c478bd9Sstevel@tonic-gate * 6217c478bd9Sstevel@tonic-gate * Direct Access device Reassign Block parameter 6227c478bd9Sstevel@tonic-gate * 6237c478bd9Sstevel@tonic-gate * Defect list format used by reassign block command (logical block format). 6247c478bd9Sstevel@tonic-gate * 6257c478bd9Sstevel@tonic-gate * This defect list is limited to 1 defect, as that is the only way we use it. 6267c478bd9Sstevel@tonic-gate * 6277c478bd9Sstevel@tonic-gate */ 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate struct scsi_reassign_blk { 6307c478bd9Sstevel@tonic-gate ushort_t reserved; 6317c478bd9Sstevel@tonic-gate ushort_t length; /* defect length in bytes (defects * 4) */ 6327c478bd9Sstevel@tonic-gate uint_t defect; /* Logical block address of defect */ 6337c478bd9Sstevel@tonic-gate }; 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate /* 6367c478bd9Sstevel@tonic-gate * Direct Access Device Capacity Structure -- 8 byte version 6377c478bd9Sstevel@tonic-gate */ 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate struct scsi_capacity { 6407c478bd9Sstevel@tonic-gate uint_t capacity; 6417c478bd9Sstevel@tonic-gate uint_t lbasize; 6427c478bd9Sstevel@tonic-gate }; 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate /* 6457c478bd9Sstevel@tonic-gate * Direct Access Device Capacity Structure -- 16 byte version 6467c478bd9Sstevel@tonic-gate */ 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate struct scsi_capacity_16 { 6497c478bd9Sstevel@tonic-gate uint64_t sc_capacity; 6507c478bd9Sstevel@tonic-gate uint_t sc_lbasize; 6517c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH) 6527c478bd9Sstevel@tonic-gate uchar_t sc_rto_en :1; 6537c478bd9Sstevel@tonic-gate uchar_t sc_prot_en :1; 6547c478bd9Sstevel@tonic-gate uchar_t sc_rsvd0 :6; 6557c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL) 6567c478bd9Sstevel@tonic-gate uchar_t sc_rsvd0 :6; 6577c478bd9Sstevel@tonic-gate uchar_t sc_prot_en :1; 6587c478bd9Sstevel@tonic-gate uchar_t sc_rto_en :1; 6597c478bd9Sstevel@tonic-gate #else 6607c478bd9Sstevel@tonic-gate #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 6617c478bd9Sstevel@tonic-gate #endif /* _BIT_FIELDS_LTOH */ 6627c478bd9Sstevel@tonic-gate uchar_t sc_rsvd1[19]; 6637c478bd9Sstevel@tonic-gate }; 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate #ifdef _KERNEL 6667c478bd9Sstevel@tonic-gate 6677c478bd9Sstevel@tonic-gate /* 6687c478bd9Sstevel@tonic-gate * Functional versions of the above macros, and other functions. 6697c478bd9Sstevel@tonic-gate * the makecom functions have been deprecated. Please use 6707c478bd9Sstevel@tonic-gate * scsi_setup_cdb() 6717c478bd9Sstevel@tonic-gate */ 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate extern void makecom_g0(struct scsi_pkt *pkt, struct scsi_device *devp, 6747c478bd9Sstevel@tonic-gate int flag, int cmd, int addr, int cnt); 6757c478bd9Sstevel@tonic-gate extern void makecom_g0_s(struct scsi_pkt *pkt, struct scsi_device *devp, 6767c478bd9Sstevel@tonic-gate int flag, int cmd, int cnt, int fixbit); 6777c478bd9Sstevel@tonic-gate extern void makecom_g1(struct scsi_pkt *pkt, struct scsi_device *devp, 6787c478bd9Sstevel@tonic-gate int flag, int cmd, int addr, int cnt); 6797c478bd9Sstevel@tonic-gate extern void makecom_g5(struct scsi_pkt *pkt, struct scsi_device *devp, 6807c478bd9Sstevel@tonic-gate int flag, int cmd, int addr, int cnt); 6817c478bd9Sstevel@tonic-gate extern int scsi_setup_cdb(union scsi_cdb *cdbp, uchar_t cmd, uint_t addr, 6827c478bd9Sstevel@tonic-gate uint_t cnt, uint_t addtl_cdb_data); 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate #ifdef __cplusplus 6877c478bd9Sstevel@tonic-gate } 6887c478bd9Sstevel@tonic-gate #endif 6897c478bd9Sstevel@tonic-gate 6907c478bd9Sstevel@tonic-gate #endif /* _SYS_SCSI_IMPL_COMMANDS_H */ 691