Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/iscsi/iscsitgtd/t10_spc.h
+++ new/usr/src/cmd/iscsi/iscsitgtd/t10_spc.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 *
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
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #ifndef _T10_SPC_H
28 28 #define _T10_SPC_H
29 29
30 -#pragma ident "%Z%%M% %I% %E% SMI"
31 -
32 30 #ifdef __cplusplus
33 31 extern "C" {
34 32 #endif
35 33
36 34 /*
37 35 * []------------------------------------------------------------------[]
38 36 * | SPC-3 |
39 37 * []------------------------------------------------------------------[]
40 38 */
41 39
42 40 /*
43 41 * FIXED_SENSE_ADDL_INFO_LEN is the length of INFORMATION field
44 42 * in fixed format sense data
45 43 */
46 44 #define FIXED_SENSE_ADDL_INFO_LEN 0xFFFFFFFF
47 45 #define INFORMATION_SENSE_DESCR sizeof (struct scsi_information_sense_descr)
48 46
47 +#include <sys/types.h>
48 +#include <netinet/in.h>
49 49 #include <sys/scsi/generic/inquiry.h>
50 50 #include <sys/scsi/generic/mode.h>
51 51
52 52 /*
53 53 * SPC Command Functions
54 54 */
55 55 void spc_tur(struct t10_cmd *cmd, uint8_t *cdb, size_t cdb_len);
56 56 void spc_request_sense(struct t10_cmd *cmd, uint8_t *cdb, size_t cdb_len);
57 57 void spc_unsupported(struct t10_cmd *cmd, uint8_t *cdb, size_t cdb_len);
58 58 void spc_inquiry(t10_cmd_t *cmd, uint8_t *cdb, size_t cdb_len);
59 59 void spc_mselect(t10_cmd_t *cmd, uint8_t *cdb, size_t cdb_len);
60 60 void spc_mselect_data(t10_cmd_t *cmd, emul_handle_t id, size_t offset,
61 61 char *data, size_t data_len);
62 62 void spc_report_luns(t10_cmd_t *cmd, uint8_t *cdb, size_t cdb_len);
63 63 void spc_report_tpgs(t10_cmd_t *cmd, uint8_t *cdb, size_t cdb_len);
64 64 void spc_msense(t10_cmd_t *cmd, uint8_t *cdb, size_t cdb_len);
65 65 void spc_startstop(t10_cmd_t *cmd, uint8_t *cdb, size_t cdb_len);
66 66 void spc_send_diag(t10_cmd_t *cmd, uint8_t *cdb, size_t cdb_len);
67 67
68 68 /*
69 69 * SPC Support Functions
70 70 */
71 71 void spc_cmd_offline(t10_cmd_t *cmd, uint8_t *cdb, size_t cdb_len);
72 72 void spc_sense_create(struct t10_cmd *cmd, int sense_key, int addl_sense_len);
73 73 void spc_sense_ascq(struct t10_cmd *cmd, int asc, int ascq);
74 74 void spc_sense_info(t10_cmd_t *cmd, uint64_t info);
75 75 void spc_sense_flags(t10_cmd_t *cmd, int flags);
76 76 void spc_sense_raw(t10_cmd_t *cmd, uchar_t *sense_buf, size_t sense_len);
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
77 77 Boolean_t spc_decode_lu_addr(uint8_t *buf, int len, uint32_t *val);
78 78 Boolean_t spc_encode_lu_addr(uint8_t *buf, int select_field, uint32_t lun);
79 79
80 80 /*
81 81 * SPC flags to use when setting various sense code flags
82 82 */
83 83 #define SPC_SENSE_EOM 0x01
84 84 #define SPC_SENSE_FM 0x02
85 85 #define SPC_SENSE_ILI 0x04
86 86
87 -#ifdef _BIG_ENDIAN
88 -#define htonll(x) (x)
89 -#define ntohll(x) (x)
90 -#else
91 -#define htonll(x) ((((unsigned long long)htonl(x & 0xffffffff)) << 32) + \
92 - htonl(x >> 32))
93 -#define ntohll(x) ((((unsigned long long)ntohl(x)) << 32) + ntohl(x >> 32))
94 -#endif
95 -
96 87 /*
97 88 * []------------------------------------------------------------------[]
98 89 * | SPC-3, revision 21c -- ASC/ASCQ values |
99 90 * | The full tables can be found in Appendix D (numerical order) or |
100 91 * | section 4.5.6 (alphabetical order). There are close to fifteen |
101 92 * | pages of values which will not be included here. Only those used |
102 93 * | by the code. |
103 94 * []------------------------------------------------------------------[]
104 95 */
105 96 #define SPC_ASC_FM_DETECTED 0x00 /* file-mark detected */
106 97 #define SPC_ASCQ_FM_DETECTED 0x01
107 98
108 99 #define SPC_ASC_EOP 0x00 /* end-of-partition/medium detected */
109 100 #define SPC_ASCQ_EOP 0x02
110 101
111 102 #define SPC_ASC_IN_PROG 0x04
112 103 #define SPC_ASCQ_IN_PROG 0x07
113 104
114 105 #define SPC_ASC_WRITE_ERROR 0x0c
115 106 #define SPC_ASCQ_WRITE_ERROR 0x00
116 107
117 108 #define SPC_ASC_PARAM_LIST_LEN 0x1a /* Parameter List Length Error */
118 109 #define SPC_ASCQ_PARAM_LIST_LEN 0x00
119 110
120 111 #define SPC_ASC_MISCOMPARE 0x1d
121 112 #define SPC_ASCQ_MISCOMPARE 0x00
122 113
123 114 #define SPC_ASC_INVALID_LU 0x20
124 115 #define SPC_ASCQ_INVALID_LU 0x09
125 116
126 117 #define SPC_ASC_BLOCK_RANGE 0x21
127 118 #define SPC_ASCQ_BLOCK_RANGE 0x00
128 119
129 120 #define SPC_ASC_INVALID_FIELD_IN_PARAMETER_LIST 0x26
130 121 #define SPC_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST 0x00
131 122
132 123 #define SPC_ASC_INVALID_CDB 0x24
133 124 #define SPC_ASCQ_INVALID_CDB 0x00
134 125
135 126 #define SPC_ASC_PARAMETERS_CHANGED 0x2a
136 127 #define SPC_ASCQ_RES_PREEMPTED 0x03
137 128 #define SPC_ASCQ_RES_RELEASED 0x04
138 129
139 130 #define SPC_ASC_PWR_RESET 0x29
140 131 #define SPC_ASCQ_PWR_RESET 0x00
141 132
142 133 #define SPC_ASC_PWR_ON 0x29
143 134 #define SPC_ASCQ_PWR_ON 0x01
144 135
145 136 #define SPC_ASC_BUS_RESET 0x29
146 137 #define SPC_ASCQ_BUS_RESET 0x02
147 138
148 139 #define SPC_ASC_CAP_CHANGE 0x2a
149 140 #define SPC_ASCQ_CAP_CHANGE 0x09
150 141
151 142 #define SPC_ASC_DATA_PATH 0x41
152 143 #define SPC_ASCQ_DATA_PATH 0x00
153 144
154 145 #define SPC_ASC_MEMORY_OUT_OF 0x55 /* Auxillary Memory Out Of Space */
155 146 #define SPC_ASCQ_MEMORY_OUT_OF 0x00
156 147 #define SPC_ASCQ_RESERVATION_FAIL 0x02
157 148
158 149
159 150 /*
160 151 * []------------------------------------------------------------------[]
161 152 * | SAM-3, revision 14, section 5.2 - Command descriptor block (CDB) |
162 153 * | |
163 154 * | "All CDBs shall contain a CONTROL byte (see table 21). The |
164 155 * | location of the CONTROL byte within a CDB depends on the CDB |
165 156 * | format (see SPC-3)." |
166 157 * | |
167 158 * | bits meaning |
168 159 * | 6-7 vendor specific (we don't use so must be zero) |
169 160 * | 3-5 reserved must be zero |
170 161 * | 2 NACA (currently we don't support so must be zero) |
171 162 * | 1 Obsolete |
172 163 * | 0 Link (currently we don't support so must be zero) |
173 164 * | |
174 165 * | So, this means the control byte must be zero and therefore if |
175 166 * | this macro returns a non-zero value the emulation code should |
176 167 * | return a CHECK CONDITION with status set to ILLEGAL REQUEST |
177 168 * | and the additional sense code set to INVALID FIELD IN CDB. |
178 169 * | |
179 170 * | In the future this will likely change with support routines |
180 171 * | added for dealing with NACA and Linked commands. |
181 172 * []------------------------------------------------------------------[]
182 173 */
183 174 #define SAM_CONTROL_BYTE_RESERVED(byte) (byte)
184 175
185 176 /* ---- Disable Block Descriptors ---- */
186 177 #define SPC_MODE_SENSE_DBD 0x8
187 178
188 179 #define SPC_GROUP4_SERVICE_ACTION_MASK 0x1f
189 180
190 181 #define SPC_SEND_DIAG_SELFTEST 0x04
191 182
192 183 /*
193 184 * []------------------------------------------------------------------[]
194 185 * | SPC-3 revision 21c, section 6.4 -- INQUIRY |
195 186 * | Various defines. The structure for the inquiry command can be |
196 187 * | found in /usr/include/sys/scsi/generic/inquiry.h |
197 188 * []------------------------------------------------------------------[]
198 189 */
199 190 #define SPC_INQUIRY_CODE_SET_BINARY 1
200 191 #define SPC_INQUIRY_CODE_SET_ASCII 2
201 192 #define SPC_INQUIRY_CODE_SET_UTF8 3
202 193
203 194 /* ---- Table 82: Inquiry Version ---- */
204 195 #define SPC_INQ_VERS_NONE 0x00
205 196 #define SPC_INQ_VERS_OBSOLETE 0x02
206 197 #define SPC_INQ_VERS_SPC_1 0x03
207 198 #define SPC_INQ_VERS_SPC_2 0x04
208 199 #define SPC_INQ_VERS_SPC_3 0x05
209 200
210 201 /* ---- INQUIRY Response Data Format field ---- */
211 202 #define SPC_INQ_RDF 0x02 /* all other values are OBSOLETE */
212 203
213 204 /*
214 205 * Table 85 -- Version descriptor values
215 206 * There are many, many different values available, so we'll only include
216 207 * those that we actually use.
217 208 */
218 209 #define SPC_INQ_VD_SAM3 0x0076
219 210 #define SPC_INQ_VD_SPC3 0x0307
220 211 #define SPC_INQ_VD_SBC2 0x0322
221 212 #define SPC_INQ_VD_SSC3 0x0400
222 213 #define SPC_INQ_VD_OSD 0x0355
223 214
224 215 /* --- Version Descriptor length details --- */
225 216 #define SPC_INQ_VD_IDX 0x3A
226 217 #define SPC_INQ_VD_LEN 0x10
227 218
228 219 #define SPC_INQ_PAGE0 0x00
229 220 #define SPC_INQ_PAGE80 0x80
230 221 #define SPC_INQ_PAGE83 0x83
231 222 #define SPC_INQ_PAGE86 0x86
232 223
233 224 /* ---- REPORT LUNS select report has valid values of 0, 1, or 2 ---- */
234 225 #define SPC_RPT_LUNS_SELECT_MASK 0x03
235 226
236 227 /* ---- Table 293: IDENTIFIER TYPE field ---- */
237 228 #define SPC_INQUIRY_ID_TYPE_T10ID 1 /* ref 7.6.4.3 */
238 229 #define SPC_INQUIRY_ID_TYPE_EUI 2 /* ref 7.6.4.4 */
239 230 #define SPC_INQUIRY_ID_TYPE_NAA 3 /* ref 7.6.4.5 */
240 231 #define SPC_INQUIRY_ID_TYPE_RELATIVE 4 /* ref 7.6.4.6 */
241 232 #define SPC_INQUIRY_ID_TYPE_TARG_PORT 5 /* ref 7.6.4.7 */
242 233 #define SPC_INQUIRY_ID_TYPE_LUN 6 /* ref 7.6.4.8 */
243 234 #define SPC_INQUIRY_ID_TYPE_MD5 7 /* ref 7.6.4.9 */
244 235 #define SPC_INQUIRY_ID_TYPE_SCSI 8 /* ref 7.6.4.10 */
245 236
246 237 /* ---- Table 292: ASSOCIATION field ---- */
247 238 #define SPC_INQUIRY_ASSOC_LUN 0
248 239 #define SPC_INQUIRY_ASSOC_TARGPORT 1
249 240 #define SPC_INQUIRY_ASSOC_TARG 2
250 241
251 242 /* ---- Table 80: Peripheral qualifier ---- */
252 243 #define SPC_INQUIRY_PERIPH_CONN 0
253 244 #define SPC_INQUIRY_PERIPH_DISCONN 1
254 245 #define SPC_INQUIRY_PERIPH_INVALID 3
255 246
256 247 /* ---- Table 256: PROTOCOL IDENTIFIER values ---- */
257 248 #define SPC_INQUIRY_PROTOCOL_FC 0
258 249 #define SPC_INQUIRY_PROTOCOL_PSCSI 1
259 250 #define SPC_INQUIRY_PROTOCOL_SSA 2
260 251 #define SPC_INQUIRY_PROTOCOL_IEEE1394 3
261 252 #define SPC_INQUIRY_PROTOCOL_SCSIRDMA 4
262 253 #define SPC_INQUIRY_PROTOCOL_ISCSI 5
263 254 #define SPC_INQUIRY_PROTOCOL_SAS 6
264 255 #define SPC_INQUIRY_PROTOCOL_ADT 7
265 256 #define SPC_INQUIRY_PROTOCOL_ATA 8
266 257
267 258 #define SPC_DEFAULT_TPG 1
268 259
269 260 /*
270 261 * SPC-3, revision 21c, section 7.6.5
271 262 * Extended INQUIRY Data VPD page
272 263 */
273 264 typedef struct extended_inq_data {
274 265 struct vpd_hdr ei_hdr;
275 266 #if defined(_BIT_FIELDS_LTOH)
276 267 uchar_t ei_ref_chk : 1,
277 268 ei_app_chk : 1,
278 269 ei_grd_chk : 1,
279 270 ei_rto : 1,
280 271 ei_rsvd1 : 4;
281 272 uchar_t ei_simpsup : 1,
282 273 ei_ordsup : 1,
283 274 ei_headsup : 1,
284 275 ei_prior_sup : 1,
285 276 ei_group_sup : 1,
286 277 ei_rsvd2 : 3;
287 278 uchar_t ei_v_sup : 1,
288 279 ei_nv_sup : 1,
289 280 ei_rsvd3 : 6;
290 281 #elif defined(_BIT_FIELDS_HTOL)
291 282 uchar_t ei_ref_rsvd1 : 4,
292 283 ei_rto : 1,
293 284 ei_grd_chk : 1,
294 285 ei_app_chk : 1,
295 286 ei_ref_chk : 1;
296 287 uchar_t ei_rsvd2 : 2,
297 288 ei_group_sup : 1,
298 289 ei_prior_sup : 1,
299 290 ei_headsup : 1,
300 291 ei_ordsup : 1,
301 292 ei_simpsup : 1;
302 293 uchar_t ei_rsvd3 : 6,
303 294 ei_nv_sup : 1,
304 295 ei_v_sup : 1;
305 296 #else
306 297 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
307 298 #endif
308 299 uchar_t ei_rsv4[57];
309 300 } extended_inq_data_t;
310 301
311 302
312 303 /*
313 304 * []------------------------------------------------------------------[]
314 305 * | SPC-4 revision 1a, section 6.25 -- REPORT TARGET PORT GROUPS |
315 306 * | Structures and defines |
316 307 * []------------------------------------------------------------------[]
317 308 */
318 309 /*
319 310 * The service action must be set to 0x0A. This command is really a
320 311 * MAINTENANCE_IN command with a specific service action.
321 312 */
322 313 #define SPC_MI_SVC_MASK 0x1f
323 314 #define SPC_MI_SVC_RTPG 0x0a
324 315
325 316 /* ---- Table 167: Target port descriptor format ---- */
326 317 typedef struct rtpg_targ_desc {
327 318 uchar_t obsolete[2],
328 319 rel_tpi[2];
329 320 } rtpg_targ_desc_t;
330 321
331 322 /* ---- Table 164: Target port group descript format ---- */
332 323 typedef struct rtpg_desc {
333 324 #if defined(_BIT_FIELDS_LTOH)
334 325 uchar_t access_state : 4,
335 326 : 3,
336 327 pref : 1;
337 328 uchar_t ao_sup : 1,
338 329 an_sup : 1,
339 330 s_sup : 1,
340 331 u_sup : 1,
341 332 : 3,
342 333 t_sup : 1;
343 334 #elif defined(_BIT_FIELDS_HTOL)
344 335 uchar_t pref : 1,
345 336 : 3,
346 337 access_state : 4;
347 338 uchar_t t_sup : 1,
348 339 : 3,
349 340 u_sup : 1,
350 341 s_sup : 1,
351 342 an_sup : 1,
352 343 ao_sup : 1;
353 344 #else
354 345 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
355 346 #endif
356 347 uchar_t tpg[2],
357 348 reserve_1,
358 349 status_code,
359 350 vendor_spec,
360 351 tpg_cnt;
361 352 rtpg_targ_desc_t targ_list[1];
362 353 } rtpg_desc_t;
363 354
364 355 /* ---- Table 163: parameter data format. ---- */
365 356 typedef struct rtpg_data {
366 357 uchar_t len[4];
367 358 rtpg_desc_t desc_list[1];
368 359 } rtpg_hdr_t;
369 360
370 361 /*
371 362 * []------------------------------------------------------------------[]
372 363 * | SPC-3, revision 21c, section 6.6 -- LOG_SENSE |
373 364 * | Structure and defines |
374 365 * []------------------------------------------------------------------[]
375 366 */
376 367 #define SSC_LOG_SP 0x01 /* save parameters */
377 368 #define SSC_LOG_PPC 0x02 /* parameter pointer control */
378 369 #define SPC_LOG_PAGE_MASK 0x3f
379 370
380 371 /* ---- section 7.2.1, Table 192: Log Parameter ---- */
381 372 typedef struct spc_log_select_param {
382 373 char param_code[2];
383 374 #if defined(_BIT_FIELDS_LTOH)
384 375 char lp : 1, /* list parameter */
385 376 lbin : 1,
386 377 tmc : 2, /* threshold met criteria */
387 378 etc : 1, /* enable threshold comparison */
388 379 tsd : 1, /* target save disable */
389 380 ds : 1, /* disable save */
390 381 du : 1; /* disable update */
391 382 #elif defined(_BIT_FIELDS_HTOL)
392 383 char du : 1, /* disable update */
393 384 ds : 1, /* disable save */
394 385 tsd : 1, /* target save disable */
395 386 etc : 1, /* enable threshold comparison */
396 387 tmc : 2, /* threshold met criteria */
397 388 lbin : 1,
398 389 lp : 1; /* list parameter */
399 390 #else
400 391 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
401 392 #endif
402 393 char len; /* length of bytes to follow */
403 394 } spc_log_select_param_t;
404 395
405 396 /* ---- section 7.2.12, table 218: Supported log pages ---- */
406 397 typedef struct spc_log_supported_pages {
407 398 char page_code,
408 399 resvd,
409 400 length[2],
410 401 list[1];
411 402 } spc_log_supported_pages_t;
412 403
413 404 /*
414 405 * []------------------------------------------------------------------[]
415 406 * | SPC-3, revision 21c, section 6.9 -- MODE_SENSE |
416 407 * | Structures and defines |
417 408 * []------------------------------------------------------------------[]
418 409 */
419 410 /* ---- Section 7.4.6, Table 241: Queue Algorithm Modifer field ---- */
420 411 #define SPC_QUEUE_RESTRICTED 0x00
421 412 #define SPC_QUEUE_UNRESTRICTED 0x01
422 413
423 414 /* ---- Section 7.4.11, Table 250: Information Controller Page ---- */
424 415 struct mode_info_ctrl {
425 416 struct mode_page mode_page;
426 417 /*
427 418 * Currently we don't sent any of this information and it's set
428 419 * to zero's. We only care about the size.
429 420 */
430 421 char info_data[10];
431 422 };
432 423
433 424 #define MODE_SENSE_PAGE3_CODE 0x03
434 425 #define MODE_SENSE_PAGE4_CODE 0x04
435 426 #define MODE_SENSE_CACHE 0x08
436 427 #define MODE_SENSE_CONTROL 0x0a
437 428 #define MODE_SENSE_COMPRESSION 0x0f
438 429 #define MODE_SENSE_DEV_CONFIG 0x10
439 430 #define MODE_SENSE_INFO_CTRL 0x1c
440 431 #define MODE_SENSE_SEND_ALL 0x3f
441 432
442 433 /* -- Page Control Mask for Mode Sense -- */
443 434 #define SPC_MODE_SENSE_PAGE_CODE_MASK 0x3f
444 435 #define SPC_MODE_SENSE_PC_MASK 0xc0
445 436 #define SPC_MODE_SENSE_PC_SHIFT 6
446 437
447 438 #define SPC_PC_CURRENT_VALUES 0
448 439 #define SPC_PC_MODIFIABLE_VALUES 1
449 440 #define SPC_PC_DEFAULT_VALUES 2
450 441 #define SPC_PC_SAVED_VALUES 3
451 442
452 443 #define SCSI_REPORTLUNS_ADDRESS_SIZE 8
453 444 #define SCSI_REPORTLUNS_ADDRESS_MASK 0xC0
454 445 #define SCSI_REPORTLUNS_ADDRESS_PERIPHERAL 0x00
455 446 #define SCSI_REPORTLUNS_ADDRESS_FLAT_SPACE 0x40
456 447 #define SCSI_REPORTLUNS_ADDRESS_LOGICAL_UNIT 0x80
457 448 #define SCSI_REPORTLUNS_ADDRESS_EXTENDED_UNIT 0xC0
458 449 #define SCSI_REPORTLUNS_ADDRESS_EXTENDED_2B 0x00
459 450 #define SCSI_REPORTLUNS_ADDRESS_EXTENDED_4B 0x10
460 451 #define SCSI_REPORTLUNS_ADDRESS_EXTENDED_6B 0x20
461 452 #define SCSI_REPORTLUNS_ADDRESS_EXTENDED_8B 0x30
462 453 #define SCSI_REPORTLUNS_ADDRESS_EXTENDED_MASK 0x30
463 454 #define SCSI_REPORTLUNS_SELECT_ALL 0x02
464 455
465 456 #ifdef __cplusplus
466 457 }
467 458 #endif
468 459
469 460 #endif /* _T10_SPC_H */
↓ open down ↓ |
364 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX