Print this page
remove support for non-ANSI compilation
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/scsi/impl/commands.h
+++ new/usr/src/uts/common/sys/scsi/impl/commands.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 + * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23 24 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
24 25 */
25 26
26 27 #ifndef _SYS_SCSI_IMPL_COMMANDS_H
27 28 #define _SYS_SCSI_IMPL_COMMANDS_H
28 29
29 30 #ifdef __cplusplus
30 31 extern "C" {
31 32 #endif
32 33
33 34 /*
34 35 * Implementation dependent command definitions.
35 36 * This file is included by <sys/scsi/generic/commands.h>
36 37 */
37 38
38 39 /*
39 40 * Implementation dependent view of a SCSI command descriptor block
40 41 */
41 42
42 43 /*
43 44 * Standard SCSI control blocks definitions.
44 45 *
45 46 * These go in or out over the SCSI bus.
46 47 *
47 48 * The first 8 bits of the command block are the same for all
48 49 * defined command groups. The first byte is an operation which consists
49 50 * of a command code component and a group code component.
50 51 *
51 52 * The group code determines the length of the rest of the command.
52 53 * Group 0 commands are 6 bytes, Group 1 and 2 are 10 bytes, Group 4
53 54 * are 16 bytes, and Group 5 are 12 bytes. Groups 3 is Reserved.
54 55 * Groups 6 and 7 are Vendor Unique.
55 56 *
56 57 */
57 58 #define CDB_SIZE CDB_GROUP5 /* deprecated, do not use */
58 59 #define SCSI_CDB_SIZE CDB_GROUP4 /* sizeof (union scsi_cdb) */
59 60
60 61 union scsi_cdb { /* scsi command description block */
61 62 struct {
62 63 uchar_t cmd; /* cmd code (byte 0) */
63 64 #if defined(_BIT_FIELDS_LTOH)
64 65 uchar_t tag :5; /* rest of byte 1 */
65 66 uchar_t lun :3; /* lun (byte 1) (reserved in SCSI-3) */
66 67 #elif defined(_BIT_FIELDS_HTOL)
67 68 uchar_t lun :3, /* lun (byte 1) (reserved in SCSI-3) */
68 69 tag :5; /* rest of byte 1 */
69 70 #else
70 71 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
71 72 #endif /* _BIT_FIELDS_LTOH */
72 73 union {
73 74
74 75 uchar_t scsi[SCSI_CDB_SIZE-2];
75 76 /*
76 77 * G R O U P 0 F O R M A T (6 bytes)
77 78 */
78 79 #define scc_cmd cdb_un.cmd
79 80 #define scc_lun cdb_un.lun
80 81 #define g0_addr2 cdb_un.tag
81 82 #define g0_addr1 cdb_un.sg.g0.addr1
82 83 #define g0_addr0 cdb_un.sg.g0.addr0
83 84 #define g0_count0 cdb_un.sg.g0.count0
84 85 #define g0_vu_1 cdb_un.sg.g0.vu_57
85 86 #define g0_vu_0 cdb_un.sg.g0.vu_56
86 87 #define g0_naca cdb_un.sg.g0.naca
87 88 #define g0_flag cdb_un.sg.g0.flag
88 89 #define g0_link cdb_un.sg.g0.link
89 90 /*
90 91 * defines for SCSI tape cdb.
91 92 */
92 93 #define t_code cdb_un.tag
93 94 #define high_count cdb_un.sg.g0.addr1
94 95 #define mid_count cdb_un.sg.g0.addr0
95 96 #define low_count cdb_un.sg.g0.count0
96 97 struct scsi_g0 {
97 98 uchar_t addr1; /* middle part of address */
98 99 uchar_t addr0; /* low part of address */
99 100 uchar_t count0; /* usually block count */
100 101 #if defined(_BIT_FIELDS_LTOH)
101 102 uchar_t link :1; /* another command follows */
102 103 uchar_t flag :1; /* interrupt when done */
103 104 uchar_t naca :1; /* normal ACA */
104 105 uchar_t rsvd :3; /* reserved */
105 106 uchar_t vu_56 :1; /* vendor unique (byte 5 bit6) */
106 107 uchar_t vu_57 :1; /* vendor unique (byte 5 bit7) */
107 108 #elif defined(_BIT_FIELDS_HTOL)
108 109 uchar_t vu_57 :1; /* vendor unique (byte 5 bit 7) */
109 110 uchar_t vu_56 :1; /* vendor unique (byte 5 bit 6) */
110 111 uchar_t rsvd :3; /* reserved */
111 112 uchar_t naca :1; /* normal ACA */
112 113 uchar_t flag :1; /* interrupt when done */
113 114 uchar_t link :1; /* another command follows */
114 115 #else
115 116 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
116 117 #endif /* _BIT_FIELDS_LTOH */
117 118 } g0;
118 119
119 120
120 121 /*
121 122 * G R O U P 1, 2 F O R M A T (10 byte)
122 123 */
123 124 #define g1_reladdr cdb_un.tag
124 125 #define g1_rsvd0 cdb_un.sg.g1.rsvd1
125 126 #define g1_addr3 cdb_un.sg.g1.addr3 /* msb */
126 127 #define g1_addr2 cdb_un.sg.g1.addr2
127 128 #define g1_addr1 cdb_un.sg.g1.addr1
128 129 #define g1_addr0 cdb_un.sg.g1.addr0 /* lsb */
129 130 #define g1_count1 cdb_un.sg.g1.count1 /* msb */
130 131 #define g1_count0 cdb_un.sg.g1.count0 /* lsb */
131 132 #define g1_vu_1 cdb_un.sg.g1.vu_97
132 133 #define g1_vu_0 cdb_un.sg.g1.vu_96
133 134 #define g1_naca cdb_un.sg.g1.naca
134 135 #define g1_flag cdb_un.sg.g1.flag
135 136 #define g1_link cdb_un.sg.g1.link
136 137 struct scsi_g1 {
137 138 uchar_t addr3; /* most sig. byte of address */
138 139 uchar_t addr2;
139 140 uchar_t addr1;
140 141 uchar_t addr0;
141 142 uchar_t rsvd1; /* reserved (byte 6) */
142 143 uchar_t count1; /* transfer length (msb) */
143 144 uchar_t count0; /* transfer length (lsb) */
144 145 #if defined(_BIT_FIELDS_LTOH)
145 146 uchar_t link :1; /* another command follows */
146 147 uchar_t flag :1; /* interrupt when done */
147 148 uchar_t naca :1; /* normal ACA */
148 149 uchar_t rsvd0 :3; /* reserved */
149 150 uchar_t vu_96 :1; /* vendor unique (byte 9 bit6) */
150 151 uchar_t vu_97 :1; /* vendor unique (byte 9 bit7) */
151 152 #elif defined(_BIT_FIELDS_HTOL)
152 153 uchar_t vu_97 :1; /* vendor unique (byte 9 bit 7) */
153 154 uchar_t vu_96 :1; /* vendor unique (byte 9 bit 6) */
154 155 uchar_t rsvd0 :3; /* reserved */
155 156 uchar_t naca :1; /* normal ACA */
156 157 uchar_t flag :1; /* interrupt when done */
157 158 uchar_t link :1; /* another command follows */
158 159 #else
159 160 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
160 161 #endif /* _BIT_FIELDS_LTOH */
161 162 } g1;
162 163
163 164 /*
164 165 * G R O U P 4 F O R M A T (16 byte)
165 166 */
166 167 #define g4_reladdr cdb_un.tag
167 168 #define g4_addr3 cdb_un.sg.g4.addr3 /* msb */
168 169 #define g4_addr2 cdb_un.sg.g4.addr2
169 170 #define g4_addr1 cdb_un.sg.g4.addr1
170 171 #define g4_addr0 cdb_un.sg.g4.addr0 /* lsb */
171 172 #define g4_addtl_cdb_data3 cdb_un.sg.g4.addtl_cdb_data3
172 173 #define g4_addtl_cdb_data2 cdb_un.sg.g4.addtl_cdb_data2
173 174 #define g4_addtl_cdb_data1 cdb_un.sg.g4.addtl_cdb_data1
174 175 #define g4_addtl_cdb_data0 cdb_un.sg.g4.addtl_cdb_data0
175 176 #define g4_count3 cdb_un.sg.g4.count3 /* msb */
176 177 #define g4_count2 cdb_un.sg.g4.count2
177 178 #define g4_count1 cdb_un.sg.g4.count1
178 179 #define g4_count0 cdb_un.sg.g4.count0 /* lsb */
179 180 #define g4_rsvd0 cdb_un.sg.g4.rsvd1
180 181 #define g4_vu_1 cdb_un.sg.g4.vu_157
181 182 #define g4_vu_0 cdb_un.sg.g4.vu_156
182 183 #define g4_naca cdb_un.sg.g4.naca
183 184 #define g4_flag cdb_un.sg.g4.flag
184 185 #define g4_link cdb_un.sg.g4.link
185 186 struct scsi_g4 {
186 187 uchar_t addr3; /* most sig. byte of address */
187 188 uchar_t addr2;
188 189 uchar_t addr1;
189 190 uchar_t addr0;
190 191 uchar_t addtl_cdb_data3;
191 192 uchar_t addtl_cdb_data2;
192 193 uchar_t addtl_cdb_data1;
193 194 uchar_t addtl_cdb_data0;
194 195 uchar_t count3; /* transfer length (msb) */
195 196 uchar_t count2;
196 197 uchar_t count1;
197 198 uchar_t count0; /* transfer length (lsb) */
198 199 uchar_t rsvd1; /* reserved */
199 200 #if defined(_BIT_FIELDS_LTOH)
200 201 uchar_t link :1; /* another command follows */
201 202 uchar_t flag :1; /* interrupt when done */
202 203 uchar_t naca :1; /* normal ACA */
203 204 uchar_t rsvd0 :3; /* reserved */
204 205 uchar_t vu_156 :1; /* vendor unique (byte 15 bit6) */
205 206 uchar_t vu_157 :1; /* vendor unique (byte 15 bit7) */
206 207 #elif defined(_BIT_FIELDS_HTOL)
207 208 uchar_t vu_157 :1; /* vendor unique (byte 15 bit 7) */
208 209 uchar_t vu_156 :1; /* vendor unique (byte 15 bit 6) */
209 210 uchar_t rsvd0 :3; /* reserved */
210 211 uchar_t naca :1; /* normal ACA */
211 212 uchar_t flag :1; /* interrupt when done */
212 213 uchar_t link :1; /* another command follows */
213 214 #else
214 215 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
215 216 #endif /* _BIT_FIELDS_LTOH */
216 217 } g4;
217 218
218 219 /*
219 220 * G R O U P 5 F O R M A T (12 byte)
220 221 */
221 222 #define scc5_reladdr cdb_un.tag
222 223 #define scc5_addr3 cdb_un.sg.g5.addr3 /* msb */
223 224 #define scc5_addr2 cdb_un.sg.g5.addr2
224 225 #define scc5_addr1 cdb_un.sg.g5.addr1
225 226 #define scc5_addr0 cdb_un.sg.g5.addr0 /* lsb */
226 227 #define scc5_count3 cdb_un.sg.g5.count3 /* msb */
227 228 #define scc5_count2 cdb_un.sg.g5.count2
228 229 #define scc5_count1 cdb_un.sg.g5.count1
229 230 #define scc5_count0 cdb_un.sg.g5.count0 /* lsb */
230 231 #define scc5_rsvd0 cdb_un.sg.g5.rsvd1
231 232 #define scc5_vu_1 cdb_un.sg.g5.v117
232 233 #define scc5_vu_0 cdb_un.sg.g5.v116
233 234 #define scc5_naca cdb_un.sg.g5.naca
234 235 #define scc5_flag cdb_un.sg.g5.flag
235 236 #define scc5_link cdb_un.sg.g5.link
236 237 struct scsi_g5 {
237 238 uchar_t addr3; /* most sig. byte of address */
238 239 uchar_t addr2;
239 240 uchar_t addr1;
240 241 uchar_t addr0;
241 242 uchar_t count3; /* most sig. byte of count */
242 243 uchar_t count2;
243 244 uchar_t count1;
244 245 uchar_t count0;
245 246 uchar_t rsvd1; /* reserved */
246 247 #if defined(_BIT_FIELDS_LTOH)
247 248 uchar_t link :1; /* another command follows */
248 249 uchar_t flag :1; /* interrupt when done */
249 250 uchar_t naca :1; /* normal ACA */
250 251 uchar_t rsvd0 :3; /* reserved */
251 252 uchar_t vu_116 :1; /* vendor unique (byte 11 bit6) */
252 253 uchar_t vu_117 :1; /* vendor unique (byte 11 bit7) */
253 254 #elif defined(_BIT_FIELDS_HTOL)
254 255 uchar_t vu_117 :1; /* vendor unique (byte 11 bit 7) */
255 256 uchar_t vu_116 :1; /* vendor unique (byte 11 bit 6) */
256 257 uchar_t rsvd0 :3; /* reserved */
257 258 uchar_t naca :1; /* normal ACA */
258 259 uchar_t flag :1; /* interrupt when done */
259 260 uchar_t link :1; /* another command follows */
260 261 #else
261 262 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
262 263 #endif /* _BIT_FIELDS_LTOH */
263 264 } g5;
264 265 }sg;
265 266 } cdb_un;
266 267 uchar_t cdb_opaque[SCSI_CDB_SIZE]; /* addressed as opaque char array */
267 268 uint_t cdb_long[SCSI_CDB_SIZE / sizeof (uint_t)]; /* as a word array */
268 269 };
269 270
270 271
271 272 /*
272 273 * Various useful Macros for SCSI commands
273 274 */
274 275
275 276 /*
276 277 * defines for getting/setting fields in data received from or destined for
277 278 * a SCSI device. These macros are necessary (in place of BE16/BE32/BE64)
278 279 * because the address to be read or written may not be on a proper alignment.
279 280 */
280 281
281 282 #define SCSI_READ16(Sr16_Addr) \
282 283 (((uint16_t)*((uint8_t *)(Sr16_Addr)) << 8) | \
283 284 ((uint16_t)*((uint8_t *)(Sr16_Addr)+1)))
284 285
285 286 #define SCSI_READ24(Sr32_Addr) \
286 287 (((uint32_t)*((uint8_t *)(Sr32_Addr)) << 16) | \
287 288 ((uint32_t)*((uint8_t *)(Sr32_Addr)+1) << 8) | \
288 289 ((uint32_t)*((uint8_t *)(Sr32_Addr)+2)))
289 290
290 291 #define SCSI_READ32(Sr32_Addr) \
291 292 (((uint32_t)*((uint8_t *)(Sr32_Addr)) << 24) | \
292 293 ((uint32_t)*((uint8_t *)(Sr32_Addr)+1) << 16) | \
293 294 ((uint32_t)*((uint8_t *)(Sr32_Addr)+2) << 8) | \
294 295 ((uint32_t)*((uint8_t *)(Sr32_Addr)+3)))
295 296
296 297 #define SCSI_READ40(Sr64_Addr) \
297 298 (((uint64_t)*((uint8_t *)(Sr64_Addr)) << 32) | \
298 299 ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 24) | \
299 300 ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 16) | \
300 301 ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 8) | \
301 302 ((uint64_t)*((uint8_t *)(Sr64_Addr)+4)))
302 303
303 304 #define SCSI_READ48(Sr64_Addr) \
304 305 (((uint64_t)*((uint8_t *)(Sr64_Addr)) << 40) | \
305 306 ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 32) | \
306 307 ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 24) | \
307 308 ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 16) | \
308 309 ((uint64_t)*((uint8_t *)(Sr64_Addr)+4) << 8) | \
309 310 ((uint64_t)*((uint8_t *)(Sr64_Addr)+5)))
310 311
311 312 #define SCSI_READ64(Sr64_Addr) \
312 313 (((uint64_t)*((uint8_t *)(Sr64_Addr)) << 56) | \
313 314 ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 48) | \
314 315 ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 40) | \
315 316 ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 32) | \
316 317 ((uint64_t)*((uint8_t *)(Sr64_Addr)+4) << 24) | \
317 318 ((uint64_t)*((uint8_t *)(Sr64_Addr)+5) << 16) | \
318 319 ((uint64_t)*((uint8_t *)(Sr64_Addr)+6) << 8) | \
319 320 ((uint64_t)*((uint8_t *)(Sr64_Addr)+7)))
320 321
321 322 #define SCSI_WRITE16(Sr16_Addr, Sr16_Val) \
322 323 *((uint8_t *)(Sr16_Addr)) = (((uint16_t)(Sr16_Val) >> 8) & 0xff), \
323 324 *((uint8_t *)(Sr16_Addr)+1) = ((uint16_t)(Sr16_Val) & 0xff)
324 325
325 326 #define SCSI_WRITE24(Sr24_Addr, Sr24_Val) \
326 327 SCSI_WRITE16((Sr24_Addr), ((Sr24_Val) & 0xffff00) >> 8), \
327 328 *((uint8_t *)(Sr24_Addr)+2) = ((uint8_t)((Sr24_Val) & 0xff))
328 329
329 330 #define SCSI_WRITE32(Sr32_Addr, Sr32_Val) \
330 331 *(uint8_t *)(Sr32_Addr) = (((uint32_t)(Sr32_Val) >> 24) & 0xff), \
331 332 *((uint8_t *)(Sr32_Addr)+1) = \
332 333 (((uint32_t)(Sr32_Val) >> 16) & 0xff), \
333 334 *((uint8_t *)(Sr32_Addr)+2) = (((uint32_t)(Sr32_Val) >> 8) & 0xff), \
334 335 *((uint8_t *)(Sr32_Addr)+3) = (((uint32_t)(Sr32_Val)) & 0xff)
335 336
336 337 #define SCSI_WRITE40(Sr40_Addr, Sr40_Val) \
337 338 SCSI_WRITE32((Sr40_Addr), ((Sr40_Val) & 0xffffffff00ULL) >> 8), \
338 339 *((uint8_t *)(Sr40_Addr)+4) = ((uint8_t)(Sr40_Val) & 0xff)
339 340
340 341 #define SCSI_WRITE48(Sr48_Addr, Sr40_Val) \
341 342 SCSI_WRITE32((Sr48_Addr), ((Sr48_Val) & 0xffffffff0000ULL) >> 16), \
342 343 SCSI_WRITE16((uint8_t *)(Sr48_Addr)+4, (Sr40_Val) & 0xffff)
343 344
344 345 #define SCSI_WRITE64(Sr64_Addr, Sr64_Val) \
345 346 *(uint8_t *)(Sr64_Addr) = (((uint64_t)(Sr64_Val) >> 56) & 0xff), \
346 347 *((uint8_t *)(Sr64_Addr)+1) = \
347 348 (((uint64_t)(Sr64_Val) >> 48) & 0xff), \
348 349 *((uint8_t *)(Sr64_Addr)+2) = \
349 350 (((uint64_t)(Sr64_Val) >> 40) & 0xff), \
350 351 *((uint8_t *)(Sr64_Addr)+3) = \
351 352 (((uint64_t)(Sr64_Val) >> 32) & 0xff), \
352 353 *((uint8_t *)(Sr64_Addr)+4) = \
353 354 (((uint64_t)(Sr64_Val) >> 24) & 0xff), \
354 355 *((uint8_t *)(Sr64_Addr)+5) = \
355 356 (((uint64_t)(Sr64_Val) >> 16) & 0xff), \
356 357 *((uint8_t *)(Sr64_Addr)+6) = \
357 358 (((uint64_t)(Sr64_Val) >> 8) & 0xff), \
358 359 *((uint8_t *)(Sr64_Addr)+7) = (((uint64_t)(Sr64_Val)) & 0xff)
359 360
360 361 /*
361 362 * These macros deal with unaligned data that crosses a byte boundary.
362 363 */
363 364 #define SCSI_MK8(ms, ls) \
364 365 (((uint8_t)(ms) << 4) | (uint8_t)ls)
365 366
366 367 #define SCSI_MK12_4_8(ms, ls) \
367 368 (((uint16_t)(ms) << 8) | (uint16_t)(ls))
368 369 #define SCSI_MK12_8_4(ms, ls) \
369 370 (((uint16_t)(ms) << 4) | (uint16_t)(ls))
370 371
371 372 #define SCSI_MK16_4_8_4(hi, mid, lo) \
372 373 (((uint16_t)(hi) << 12) | ((uint16_t)(mid) << 4) | (uint16_t)(lo))
373 374
374 375 #define SCSI_MK20_4_16(ms, ls) \
375 376 (((uint32_t)(ms) << 16) | ((uint32_t)(ls)))
376 377 #define SCSI_MK20_16_4(ms, ls) \
377 378 (((uint32_t)(ms) << 4) | ((uint32_t)(ls)))
378 379
379 380 #define SCSI_MK24_4_16_4(hi, mid, lo) \
380 381 (((uint32_t)(hi) << 20) | ((uint32_t)(mid) << 4) | (uint32_t)(lo))
381 382
382 383 #define SCSI_MK36_4_32(ms, ls) \
383 384 (((uint64_t)(ms) << 32) | (uint64_t)(ls))
384 385 #define SCSI_MK36_32_4(ms, ls) \
385 386 (((uint64_t)(ms) << 4) | (uint64_t)(ls))
386 387
387 388 /*
388 389 * defines for getting/setting fields within the various command groups
389 390 */
390 391
391 392 #define GETCMD(cdb) ((cdb)->scc_cmd & 0x1F)
392 393 #define GETGROUP(cdb) (CDB_GROUPID((cdb)->scc_cmd))
393 394
394 395 #define FORMG0COUNT(cdb, cnt) (cdb)->g0_count0 = (cnt)
395 396
396 397 #define FORMG0ADDR(cdb, addr) (cdb)->g0_addr2 = (addr) >> 16; \
397 398 (cdb)->g0_addr1 = ((addr) >> 8) & 0xFF; \
398 399 (cdb)->g0_addr0 = (addr) & 0xFF
399 400
400 401 #define GETG0COUNT(cdb) (cdb)->g0_count0
401 402
402 403 #define GETG0ADDR(cdb) ((((cdb)->g0_addr2 & 0x1F) << 16) + \
403 404 ((cdb)->g0_addr1 << 8) + ((cdb)->g0_addr0))
404 405
405 406 #define GETG0TAG(cdb) ((cdb)->g0_addr2)
406 407
407 408 #define FORMG0COUNT_S(cdb, cnt) (cdb)->high_count = (cnt) >> 16; \
408 409 (cdb)->mid_count = ((cnt) >> 8) & 0xFF; \
409 410 (cdb)->low_count = (cnt) & 0xFF
410 411
411 412 #define FORMG1COUNT(cdb, cnt) (cdb)->g1_count1 = ((cnt) >> 8); \
412 413 (cdb)->g1_count0 = (cnt) & 0xFF
413 414
414 415 #define FORMG1ADDR(cdb, addr) (cdb)->g1_addr3 = (addr) >> 24; \
415 416 (cdb)->g1_addr2 = ((addr) >> 16) & 0xFF; \
416 417 (cdb)->g1_addr1 = ((addr) >> 8) & 0xFF; \
417 418 (cdb)->g1_addr0 = (addr) & 0xFF
418 419
419 420 #define GETG1COUNT(cdb) (((cdb)->g1_count1 << 8) + ((cdb)->g1_count0))
420 421
421 422 #define GETG1ADDR(cdb) (((cdb)->g1_addr3 << 24) + \
422 423 ((cdb)->g1_addr2 << 16) + \
423 424 ((cdb)->g1_addr1 << 8) + \
424 425 ((cdb)->g1_addr0))
425 426
426 427 #define GETG1TAG(cdb) (cdb)->g1_reladdr
427 428
428 429 #define FORMG4COUNT(cdb, cnt) (cdb)->g4_count3 = ((cnt) >> 24); \
429 430 (cdb)->g4_count2 = ((cnt) >> 16) & 0xFF; \
430 431 (cdb)->g4_count1 = ((cnt) >> 8) & 0xFF; \
431 432 (cdb)->g4_count0 = (cnt) & 0xFF
432 433
433 434 #define FORMG4LONGADDR(cdb, addr) (cdb)->g4_addr3 = (addr) >> 56; \
434 435 (cdb)->g4_addr2 = \
435 436 ((addr) >> 48) & 0xFF; \
436 437 (cdb)->g4_addr1 = \
437 438 ((addr) >> 40) & 0xFF; \
438 439 (cdb)->g4_addr0 = \
439 440 ((addr) >> 32) & 0xFF; \
440 441 (cdb)->g4_addtl_cdb_data3 = \
441 442 ((addr) >> 24) & 0xFF; \
442 443 (cdb)->g4_addtl_cdb_data2 = \
443 444 ((addr) >> 16) & 0xFF; \
444 445 (cdb)->g4_addtl_cdb_data1 = \
445 446 ((addr) >> 8) & 0xFF; \
446 447 (cdb)->g4_addtl_cdb_data0 = \
447 448 (addr) & 0xFF
448 449
449 450 #define GETG4COUNT(cdb) (((cdb)->g4_count3 << 24) + \
450 451 ((cdb)->g4_count2 << 16) + \
451 452 ((cdb)->g4_count1 << 8) + \
452 453 ((cdb)->g4_count0))
453 454
454 455 #define GETG4LONGADDR(cdb) (((diskaddr_t)(cdb)->g4_addr3 << 56) + \
455 456 ((diskaddr_t)(cdb)->g4_addr2 << 48) + \
456 457 ((diskaddr_t)(cdb)->g4_addr1 << 40) + \
457 458 ((diskaddr_t)(cdb)->g4_addr0 << 32) + \
458 459 ((diskaddr_t)(cdb)->g4_addtl_cdb_data3 << 24) + \
459 460 ((diskaddr_t)(cdb)->g4_addtl_cdb_data2 << 16) + \
460 461 ((diskaddr_t)(cdb)->g4_addtl_cdb_data1 << 8) + \
461 462 ((diskaddr_t)(cdb)->g4_addtl_cdb_data0))
462 463
463 464 #define FORMG4ADDR(cdb, addr) (cdb)->g4_addr3 = (addr) >> 24; \
464 465 (cdb)->g4_addr2 = ((addr) >> 16) & 0xFF; \
465 466 (cdb)->g4_addr1 = ((addr) >> 8) & 0xFF; \
466 467 (cdb)->g4_addr0 = (addr) & 0xFF
467 468
468 469 #define FORMG4ADDTL(cdb, addtl_cdb_data) (cdb)->g4_addtl_cdb_data3 = \
469 470 (addtl_cdb_data) >> 24; \
470 471 (cdb)->g4_addtl_cdb_data2 = \
471 472 ((addtl_cdb_data) >> 16) & 0xFF; \
472 473 (cdb)->g4_addtl_cdb_data1 = \
473 474 ((addtl_cdb_data) >> 8) & 0xFF; \
474 475 (cdb)->g4_addtl_cdb_data0 = \
475 476 (addtl_cdb_data) & 0xFF
476 477
477 478 #define GETG4ADDR(cdb) ((cdb)->g4_addr3 << 24) + \
478 479 ((cdb)->g4_addr2 << 16) + \
479 480 ((cdb)->g4_addr1 << 8) + \
480 481 ((cdb)->g4_addr0)
481 482
482 483 #define GETG4ADDRTL(cdb) (((cdb)->g4_addtl_cdb_data3 << 24) + \
483 484 ((cdb)->g4_addtl_cdb_data2 << 16) + \
484 485 ((cdb)->g4_addtl_cdb_data1 << 8) + \
485 486 (cdb)->g4_addtl_cdb_data0)
486 487
487 488 #define GETG4TAG(cdb) (cdb)->g4_reladdr
488 489
489 490 #define FORMG5COUNT(cdb, cnt) (cdb)->scc5_count3 = ((cnt) >> 24); \
490 491 (cdb)->scc5_count2 = ((cnt) >> 16) & 0xFF; \
491 492 (cdb)->scc5_count1 = ((cnt) >> 8) & 0xFF; \
492 493 (cdb)->scc5_count0 = (cnt) & 0xFF
493 494
494 495 #define FORMG5ADDR(cdb, addr) (cdb)->scc5_addr3 = (addr) >> 24; \
495 496 (cdb)->scc5_addr2 = ((addr) >> 16) & 0xFF; \
496 497 (cdb)->scc5_addr1 = ((addr) >> 8) & 0xFF; \
497 498 (cdb)->scc5_addr0 = (addr) & 0xFF
498 499
499 500 #define GETG5ADDR(cdb) ((cdb)->scc5_addr3 << 24) + \
500 501 ((cdb)->scc5_addr2 << 16) + \
501 502 ((cdb)->scc5_addr1 << 8) + \
502 503 ((cdb)->scc5_addr0)
503 504
504 505 #define GETG5COUNT(cdb) ((cdb)->scc5_count3 << 24) + \
505 506 ((cdb)->scc5_count2 << 16) + \
506 507 ((cdb)->scc5_count1 << 8) + \
507 508 ((cdb)->scc5_count0)
508 509
509 510 #define GETG5TAG(cdb) (cdb)->scc5_reladdr
510 511
511 512
512 513 /*
513 514 * Shorthand macros for forming commands
514 515 *
515 516 * Works only with pre-SCSI-3 because they put lun as part of CDB.
516 517 * scsi_setup_cdb() is the recommended interface.
517 518 */
518 519
519 520 #define MAKECOM_COMMON(pktp, devp, flag, cmd) \
520 521 (pktp)->pkt_address = (devp)->sd_address, \
521 522 (pktp)->pkt_flags = (flag), \
522 523 ((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \
523 524 ((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \
524 525 (pktp)->pkt_address.a_lun
525 526
526 527 #define MAKECOM_G0(pktp, devp, flag, cmd, addr, cnt) \
527 528 MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \
528 529 FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
529 530 FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
530 531
531 532 #define MAKECOM_G0_S(pktp, devp, flag, cmd, cnt, fixbit) \
532 533 MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \
533 534 FORMG0COUNT_S(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt)), \
534 535 ((union scsi_cdb *)(pktp)->pkt_cdbp)->t_code = (fixbit)
535 536
536 537 #define MAKECOM_G1(pktp, devp, flag, cmd, addr, cnt) \
537 538 MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \
538 539 FORMG1ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
539 540 FORMG1COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
540 541
541 542 #define MAKECOM_G5(pktp, devp, flag, cmd, addr, cnt) \
542 543 MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \
543 544 FORMG5ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
544 545 FORMG5COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
545 546
546 547
547 548 /*
548 549 * Direct access disk format defines and parameters.
549 550 *
550 551 * This is still pretty ugly and is mostly derived
551 552 * from Emulex MD21 specific formatting.
552 553 */
553 554
554 555 #define fmt_parm_bits g0_addr2 /* for format options */
555 556 #define fmt_interleave g0_count0 /* for encode interleave */
556 557 #define defect_list_descrip g1_addr3 /* list description bits */
557 558
558 559 /*
559 560 * defines for value of fmt_parm_bits.
560 561 */
561 562
562 563 #define FPB_BFI 0x04 /* bytes-from-index fmt */
563 564 #define FPB_CMPLT 0x08 /* full defect list provided */
564 565 #define FPB_DATA 0x10 /* defect list data provided */
565 566
566 567 /*
567 568 * Defines for value of defect_list_descrip.
568 569 */
569 570
570 571 #define DLD_MAN_DEF_LIST 0x10 /* manufacturer's defect list */
571 572 #define DLD_GROWN_DEF_LIST 0x08 /* grown defect list */
572 573 #define DLD_BLOCK_FORMAT 0x00 /* block format */
573 574 #define DLD_BFI_FORMAT 0x04 /* bytes-from-index format */
574 575 #define DLD_PS_FORMAT 0x05 /* physical sector format */
575 576
576 577 /*
577 578 * Defines for value of CONTROL byte of cdb.
578 579 */
579 580 #define CDB_FLAG_NACA 0x04 /* naca flag */
580 581
581 582 /*
582 583 * Disk defect list - used by format command.
583 584 */
584 585 #define RDEF_ALL 0 /* read all defects */
585 586 #define RDEF_MANUF 1 /* read manufacturer's defects */
586 587 #define RDEF_CKLEN 2 /* check length of manufacturer's list */
587 588 #define ST506_NDEFECT 127 /* must fit in 1K controller buffer... */
588 589 #define ESDI_NDEFECT ST506_NDEFECT
589 590
590 591 struct scsi_bfi_defect { /* defect in bytes from index format */
591 592 unsigned cyl : 24;
592 593 unsigned head : 8;
593 594 int bytes_from_index;
594 595 };
595 596
596 597 struct scsi_format_params { /* BFI format list */
597 598 ushort_t reserved;
598 599 ushort_t length;
599 600 struct scsi_bfi_defect list[ESDI_NDEFECT];
600 601 };
601 602
602 603 /*
603 604 * Defect list returned by READ_DEFECT_LIST command.
604 605 */
605 606 struct scsi_defect_hdr { /* For getting defect list size */
606 607 uchar_t reserved;
607 608 uchar_t descriptor;
608 609 ushort_t length;
609 610 };
610 611
611 612 struct scsi_defect_list { /* BFI format list */
612 613 uchar_t reserved;
613 614 uchar_t descriptor;
614 615 ushort_t length;
615 616 struct scsi_bfi_defect list[ESDI_NDEFECT];
616 617 };
617 618
618 619 /*
619 620 *
620 621 * Direct Access device Reassign Block parameter
621 622 *
622 623 * Defect list format used by reassign block command (logical block format).
623 624 *
624 625 * This defect list is limited to 1 defect, as that is the only way we use it.
625 626 *
626 627 */
627 628
628 629 struct scsi_reassign_blk {
629 630 ushort_t reserved;
630 631 ushort_t length; /* defect length in bytes (defects * 4) */
631 632 uint_t defect; /* Logical block address of defect */
632 633 };
633 634
634 635 /*
635 636 * Direct Access Device Capacity Structure -- 8 byte version
636 637 */
637 638
638 639 struct scsi_capacity {
639 640 uint_t capacity;
640 641 uint_t lbasize;
641 642 };
642 643
643 644 /*
644 645 * Direct Access Device Capacity Structure -- 16 byte version
645 646 */
646 647
647 648 struct scsi_capacity_16 {
648 649 uint64_t sc_capacity;
649 650 uint_t sc_lbasize;
650 651 #if defined(_BIT_FIELDS_LTOH)
651 652 uchar_t sc_rto_en :1;
652 653 uchar_t sc_prot_en :1;
653 654 uchar_t sc_rsvd0 :6;
654 655 #elif defined(_BIT_FIELDS_HTOL)
655 656 uchar_t sc_rsvd0 :6;
656 657 uchar_t sc_prot_en :1;
657 658 uchar_t sc_rto_en :1;
658 659 #else
659 660 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
660 661 #endif /* _BIT_FIELDS_LTOH */
661 662 uchar_t sc_rsvd1[19];
↓ open down ↓ |
629 lines elided |
↑ open up ↑ |
662 663 };
663 664
664 665 #ifdef _KERNEL
665 666
666 667 /*
667 668 * Functional versions of the above macros, and other functions.
668 669 * the makecom functions have been deprecated. Please use
669 670 * scsi_setup_cdb()
670 671 */
671 672
672 -#ifdef __STDC__
673 673 extern void makecom_g0(struct scsi_pkt *pkt, struct scsi_device *devp,
674 674 int flag, int cmd, int addr, int cnt);
675 675 extern void makecom_g0_s(struct scsi_pkt *pkt, struct scsi_device *devp,
676 676 int flag, int cmd, int cnt, int fixbit);
677 677 extern void makecom_g1(struct scsi_pkt *pkt, struct scsi_device *devp,
678 678 int flag, int cmd, int addr, int cnt);
679 679 extern void makecom_g5(struct scsi_pkt *pkt, struct scsi_device *devp,
680 680 int flag, int cmd, int addr, int cnt);
681 681 extern int scsi_setup_cdb(union scsi_cdb *cdbp, uchar_t cmd, uint_t addr,
682 682 uint_t cnt, uint_t addtl_cdb_data);
683 683
684 -#else /* __STDC__ */
685 -
686 -extern void makecom_g0();
687 -extern void makecom_g0_s();
688 -extern void makecom_g1();
689 -extern void makecom_g5();
690 -extern int scsi_setup_cdb();
691 -
692 -#endif /* __STDC__ */
693 -
694 684 #endif /* _KERNEL */
695 685
696 686 #ifdef __cplusplus
697 687 }
698 688 #endif
699 689
700 690 #endif /* _SYS_SCSI_IMPL_COMMANDS_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX