]>
Commit | Line | Data |
---|---|---|
832b75ed GG |
1 | /* |
2 | * scsicmds.h | |
3 | * | |
a86ec89e | 4 | * Home page of code is: http://www.smartmontools.org |
832b75ed | 5 | * |
a86ec89e | 6 | * Copyright (C) 2002-8 Bruce Allen |
832b75ed | 7 | * Copyright (C) 2000 Michael Cornwell <cornwell@acm.org> |
ff28b140 | 8 | * Copyright (C) 2003-18 Douglas Gilbert <dgilbert@interlog.com> |
832b75ed | 9 | * |
ff28b140 | 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
832b75ed | 11 | * |
832b75ed GG |
12 | * |
13 | * N.B. What was formerly known as "SMART" are now called "informational | |
14 | * exceptions" in recent t10.org drafts (i.e. recent SCSI). | |
15 | * | |
16 | */ | |
17 | ||
18 | ||
19 | #ifndef SCSICMDS_H_ | |
20 | #define SCSICMDS_H_ | |
21 | ||
ff28b140 | 22 | #define SCSICMDS_H_CVSID "$Id: scsicmds.h 4842 2018-12-02 16:07:26Z chrfranke $\n" |
832b75ed GG |
23 | |
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
ff28b140 | 26 | #include <stdint.h> |
832b75ed | 27 | #include <string.h> |
832b75ed GG |
28 | |
29 | /* #define SCSI_DEBUG 1 */ /* Comment out to disable command debugging */ | |
30 | ||
2127e193 GI |
31 | /* Following conditional defines just in case OS already has them defined. |
32 | * If they are defined we hope they are defined correctly (for SCSI). */ | |
832b75ed GG |
33 | #ifndef TEST_UNIT_READY |
34 | #define TEST_UNIT_READY 0x0 | |
35 | #endif | |
2127e193 GI |
36 | #ifndef LOG_SELECT |
37 | #define LOG_SELECT 0x4c | |
38 | #endif | |
832b75ed GG |
39 | #ifndef LOG_SENSE |
40 | #define LOG_SENSE 0x4d | |
41 | #endif | |
42 | #ifndef MODE_SENSE | |
43 | #define MODE_SENSE 0x1a | |
44 | #endif | |
45 | #ifndef MODE_SENSE_10 | |
46 | #define MODE_SENSE_10 0x5a | |
47 | #endif | |
48 | #ifndef MODE_SELECT | |
49 | #define MODE_SELECT 0x15 | |
50 | #endif | |
51 | #ifndef MODE_SELECT_10 | |
52 | #define MODE_SELECT_10 0x55 | |
53 | #endif | |
54 | #ifndef INQUIRY | |
55 | #define INQUIRY 0x12 | |
56 | #endif | |
57 | #ifndef REQUEST_SENSE | |
58 | #define REQUEST_SENSE 0x03 | |
59 | #endif | |
60 | #ifndef RECEIVE_DIAGNOSTIC | |
61 | #define RECEIVE_DIAGNOSTIC 0x1c | |
62 | #endif | |
63 | #ifndef SEND_DIAGNOSTIC | |
64 | #define SEND_DIAGNOSTIC 0x1d | |
65 | #endif | |
66 | #ifndef READ_DEFECT_10 | |
67 | #define READ_DEFECT_10 0x37 | |
68 | #endif | |
ee38a438 GI |
69 | #ifndef READ_DEFECT_12 |
70 | #define READ_DEFECT_12 0xb7 | |
71 | #endif | |
cfbba5b9 GI |
72 | #ifndef START_STOP_UNIT |
73 | #define START_STOP_UNIT 0x1b | |
74 | #endif | |
75 | #ifndef REPORT_LUNS | |
76 | #define REPORT_LUNS 0xa0 | |
77 | #endif | |
78 | #ifndef READ_CAPACITY_10 | |
79 | #define READ_CAPACITY_10 0x25 | |
80 | #endif | |
81 | #ifndef READ_CAPACITY_16 | |
a7e8ffec GI |
82 | #define READ_CAPACITY_16 0x9e |
83 | #endif | |
84 | #ifndef SAI_READ_CAPACITY_16 /* service action for READ_CAPACITY_16 */ | |
85 | #define SAI_READ_CAPACITY_16 0x10 | |
cfbba5b9 | 86 | #endif |
832b75ed | 87 | |
4d59bff9 GG |
88 | #ifndef SAT_ATA_PASSTHROUGH_12 |
89 | #define SAT_ATA_PASSTHROUGH_12 0xa1 | |
90 | #endif | |
91 | #ifndef SAT_ATA_PASSTHROUGH_16 | |
92 | #define SAT_ATA_PASSTHROUGH_16 0x85 | |
93 | #endif | |
94 | ||
832b75ed GG |
95 | |
96 | #define DXFER_NONE 0 | |
97 | #define DXFER_FROM_DEVICE 1 | |
98 | #define DXFER_TO_DEVICE 2 | |
99 | ||
100 | struct scsi_cmnd_io | |
101 | { | |
ff28b140 | 102 | uint8_t * cmnd; /* [in]: ptr to SCSI command block (cdb) */ |
832b75ed | 103 | size_t cmnd_len; /* [in]: number of bytes in SCSI command */ |
ee38a438 | 104 | int dxfer_dir; /* [in]: DXFER_NONE, DXFER_FROM_DEVICE, or |
832b75ed | 105 | DXFER_TO_DEVICE */ |
ff28b140 | 106 | uint8_t * dxferp; /* [in]: ptr to outgoing or incoming data buffer */ |
832b75ed | 107 | size_t dxfer_len; /* [in]: bytes to be transferred to/from dxferp */ |
ff28b140 | 108 | uint8_t * sensep; /* [in]: ptr to sense buffer, filled when |
832b75ed GG |
109 | CHECK CONDITION status occurs */ |
110 | size_t max_sense_len; /* [in]: max number of bytes to write to sensep */ | |
111 | unsigned timeout; /* [in]: seconds, 0-> default timeout (60 seconds?) */ | |
112 | size_t resp_sense_len; /* [out]: sense buffer length written */ | |
ff28b140 | 113 | uint8_t scsi_status; /* [out]: 0->ok, 2->CHECK CONDITION, etc ... */ |
832b75ed GG |
114 | int resid; /* [out]: Number of bytes requested to be transferred |
115 | less actual number transferred (0 if not | |
116 | supported) */ | |
117 | }; | |
118 | ||
119 | struct scsi_sense_disect { | |
ff28b140 TL |
120 | uint8_t resp_code; |
121 | uint8_t sense_key; | |
122 | uint8_t asc; | |
123 | uint8_t ascq; | |
ee38a438 | 124 | int progress; /* -1 -> N/A, 0-65535 -> available */ |
832b75ed GG |
125 | }; |
126 | ||
127 | /* Useful data from Informational Exception Control mode page (0x1c) */ | |
128 | #define SCSI_IECMP_RAW_LEN 64 | |
129 | struct scsi_iec_mode_page { | |
ff28b140 TL |
130 | uint8_t requestedCurrent; |
131 | uint8_t gotCurrent; | |
132 | uint8_t requestedChangeable; | |
133 | uint8_t gotChangeable; | |
134 | uint8_t modese_len; /* 0 (don't know), 6 or 10 */ | |
135 | uint8_t raw_curr[SCSI_IECMP_RAW_LEN]; | |
136 | uint8_t raw_chg[SCSI_IECMP_RAW_LEN]; | |
832b75ed GG |
137 | }; |
138 | ||
139 | /* Carrier for Error counter log pages (e.g. read, write, verify ...) */ | |
140 | struct scsiErrorCounter { | |
ff28b140 TL |
141 | uint8_t gotPC[7]; |
142 | uint8_t gotExtraPC; | |
832b75ed GG |
143 | uint64_t counter[8]; |
144 | }; | |
145 | ||
146 | /* Carrier for Non-medium error log page */ | |
147 | struct scsiNonMediumError { | |
ff28b140 TL |
148 | uint8_t gotPC0; |
149 | uint8_t gotExtraPC; | |
832b75ed | 150 | uint64_t counterPC0; |
ff28b140 | 151 | uint8_t gotTFE_H; |
832b75ed | 152 | uint64_t counterTFE_H; /* Track following errors [Hitachi] */ |
ff28b140 | 153 | uint8_t gotPE_H; |
832b75ed GG |
154 | uint64_t counterPE_H; /* Positioning errors [Hitachi] */ |
155 | }; | |
156 | ||
ff28b140 TL |
157 | struct scsi_readcap_resp { |
158 | uint64_t num_lblocks; /* Number of Logical Blocks on device */ | |
159 | uint32_t lb_size; /* should be available in all non-error cases */ | |
160 | /* following fields from READ CAPACITY(16) or set to 0 */ | |
161 | uint8_t prot_type; /* 0, 1, 2 or 3 protection type, deduced from | |
162 | * READ CAPACITY(16) P_TYPE and PROT_EN fields */ | |
163 | uint8_t p_i_exp; /* Protection information Intervals Exponent */ | |
164 | uint8_t lb_p_pb_exp;/* Logical Blocks per Physical Block Exponent */ | |
165 | bool lbpme; /* Logical Block Provisioning Management Enabled */ | |
166 | bool lbprz; /* Logical Block Provisioning Read Zeros */ | |
167 | uint16_t l_a_lba; /* Lowest Aligned Logical Block Address */ | |
168 | }; | |
169 | ||
832b75ed GG |
170 | /* SCSI Peripheral types (of interest) */ |
171 | #define SCSI_PT_DIRECT_ACCESS 0x0 | |
172 | #define SCSI_PT_SEQUENTIAL_ACCESS 0x1 | |
173 | #define SCSI_PT_CDROM 0x5 | |
174 | #define SCSI_PT_MEDIUM_CHANGER 0x8 | |
175 | #define SCSI_PT_ENCLOSURE 0xd | |
ff28b140 TL |
176 | #define SCSI_PT_HOST_MANAGED 0x14 |
177 | ||
178 | /* Transport protocol identifiers or just Protocol identifiers */ | |
179 | #define SCSI_TPROTO_FCP 0 | |
180 | #define SCSI_TPROTO_SPI 1 | |
181 | #define SCSI_TPROTO_SSA 2 | |
182 | #define SCSI_TPROTO_1394 3 | |
183 | #define SCSI_TPROTO_SRP 4 /* SCSI over RDMA */ | |
184 | #define SCSI_TPROTO_ISCSI 5 | |
185 | #define SCSI_TPROTO_SAS 6 | |
186 | #define SCSI_TPROTO_ADT 7 | |
187 | #define SCSI_TPROTO_ATA 8 | |
188 | #define SCSI_TPROTO_UAS 9 /* USB attached SCSI */ | |
189 | #define SCSI_TPROTO_SOP 0xa /* SCSI over PCIe */ | |
190 | #define SCSI_TPROTO_PCIE 0xb /* includes NVMe */ | |
191 | #define SCSI_TPROTO_NONE 0xf | |
192 | ||
193 | ||
194 | /* SCSI Log Pages retrieved by LOG SENSE. 0x0 to 0x3f, 0x30 to 0x3e vendor */ | |
195 | #define SUPPORTED_LPAGES 0x00 | |
196 | #define BUFFER_OVERRUN_LPAGE 0x01 | |
197 | #define WRITE_ERROR_COUNTER_LPAGE 0x02 | |
198 | #define READ_ERROR_COUNTER_LPAGE 0x03 | |
199 | #define READ_REVERSE_ERROR_COUNTER_LPAGE 0x04 | |
200 | #define VERIFY_ERROR_COUNTER_LPAGE 0x05 | |
201 | #define NON_MEDIUM_ERROR_LPAGE 0x06 | |
202 | #define LAST_N_ERROR_EVENTS_LPAGE 0x07 | |
203 | #define FORMAT_STATUS_LPAGE 0x08 | |
204 | #define LAST_N_DEFERRED_LPAGE 0x0b /* or async events */ | |
205 | #define LB_PROV_LPAGE 0x0c /* SBC-3 */ | |
206 | #define TEMPERATURE_LPAGE 0x0d | |
207 | #define STARTSTOP_CYCLE_COUNTER_LPAGE 0x0e | |
208 | #define APPLICATION_CLIENT_LPAGE 0x0f | |
209 | #define SELFTEST_RESULTS_LPAGE 0x10 | |
210 | #define SS_MEDIA_LPAGE 0x11 /* SBC-3 */ | |
211 | #define BACKGROUND_RESULTS_LPAGE 0x15 /* SBC-3 */ | |
212 | #define ATA_PT_RESULTS_LPAGE 0x16 /* SAT */ | |
213 | #define NONVOL_CACHE_LPAGE 0x17 /* SBC-3 */ | |
214 | #define PROTOCOL_SPECIFIC_LPAGE 0x18 | |
215 | #define GEN_STATS_PERF_LPAGE 0x19 | |
216 | #define POWER_COND_TRANS_LPAGE 0x1a | |
217 | #define IE_LPAGE 0x2f | |
218 | ||
219 | /* SCSI Log subpages (8 bits), added spc4r05 2006, standardized SPC-4 2015 */ | |
220 | #define NO_SUBPAGE_L_SPAGE 0x0 /* 0x0-0x3f,0x0 */ | |
221 | #define LAST_N_INQ_DAT_L_SPAGE 0x1 /* 0xb,0x1 */ | |
222 | #define LAST_N_MODE_PG_L_SPAGE 0x2 /* 0xb,0x2 */ | |
223 | #define ENVIRO_REP_L_SPAGE 0x1 /* 0xd,0x1 */ | |
224 | #define ENVIRO_LIMITS_L_SPAGE 0x2 /* 0xd,0x2 */ | |
225 | #define UTILIZATION_L_SPAGE 0x1 /* 0xe,0x1 */ | |
226 | #define ZB_DEV_STATS_L_SPAGE 0x1 /* 0x14,0x1 */ | |
227 | #define PEND_DEFECTS_L_SPAGE 0x1 /* 0x15,0x1 */ | |
228 | #define BACKGROUND_OP_L_SPAGE 0x2 /* 0x15,0x2 */ | |
229 | #define LPS_MISALIGN_L_SPAGE 0x3 /* 0x15,0x3 */ | |
230 | #define SUPP_SPAGE_L_SPAGE 0xff /* 0x0,0xff pages+subpages */ | |
832b75ed GG |
231 | |
232 | /* Seagate vendor specific log pages. */ | |
ff28b140 TL |
233 | #define SEAGATE_CACHE_LPAGE 0x37 |
234 | #define SEAGATE_FACTORY_LPAGE 0x3e | |
832b75ed GG |
235 | |
236 | /* Log page response lengths */ | |
237 | #define LOG_RESP_SELF_TEST_LEN 0x194 | |
238 | ||
ff28b140 | 239 | /* See the SSC-2 document at www.t10.org . Earlier note: From IBM |
832b75ed GG |
240 | Documentation, see http://www.storage.ibm.com/techsup/hddtech/prodspecs.htm */ |
241 | #define TAPE_ALERTS_LPAGE 0x2e | |
242 | ||
243 | /* ANSI SCSI-3 Mode Pages */ | |
244 | #define VENDOR_UNIQUE_PAGE 0x00 | |
245 | #define READ_WRITE_ERROR_RECOVERY_PAGE 0x01 | |
246 | #define DISCONNECT_RECONNECT_PAGE 0x02 | |
247 | #define FORMAT_DEVICE_PAGE 0x03 | |
248 | #define RIGID_DISK_DRIVE_GEOMETRY_PAGE 0x04 | |
249 | #define FLEXIBLE_DISK_PAGE 0x05 | |
250 | #define VERIFY_ERROR_RECOVERY_PAGE 0x07 | |
251 | #define CACHING_PAGE 0x08 | |
252 | #define PERIPHERAL_DEVICE_PAGE 0x09 | |
253 | #define XOR_CONTROL_MODE_PAGE 0x10 | |
254 | #define CONTROL_MODE_PAGE 0x0a | |
255 | #define MEDIUM_TYPES_SUPPORTED_PAGE 0x0b | |
256 | #define NOTCH_PAGE 0x0c | |
257 | #define CD_DEVICE_PAGE 0x0d | |
258 | #define CD_AUDIO_CONTROL_PAGE 0x0e | |
259 | #define DATA_COMPRESSION_PAGE 0x0f | |
260 | #define ENCLOSURE_SERVICES_MANAGEMENT_PAGE 0x14 | |
261 | #define PROTOCOL_SPECIFIC_LUN_PAGE 0x18 | |
262 | #define PROTOCOL_SPECIFIC_PORT_PAGE 0x19 | |
263 | #define POWER_CONDITION_PAGE 0x1a | |
264 | #define INFORMATIONAL_EXCEPTIONS_CONTROL_PAGE 0x1c | |
265 | #define FAULT_FAILURE_REPORTING_PAGE 0x1c | |
266 | ||
4d59bff9 GG |
267 | /* Background control mode subpage is [0x1c,0x1] */ |
268 | #define BACKGROUND_CONTROL_M_SUBPAGE 0x1 /* SBC-2 */ | |
269 | ||
832b75ed GG |
270 | #define ALL_MODE_PAGES 0x3f |
271 | ||
272 | /* Mode page control field */ | |
273 | #define MPAGE_CONTROL_CURRENT 0 | |
274 | #define MPAGE_CONTROL_CHANGEABLE 1 | |
275 | #define MPAGE_CONTROL_DEFAULT 2 | |
276 | #define MPAGE_CONTROL_SAVED 3 | |
277 | ||
ee38a438 GI |
278 | /* SCSI Vital Product Data (VPD) pages */ |
279 | #define SCSI_VPD_SUPPORTED_VPD_PAGES 0x0 | |
280 | #define SCSI_VPD_UNIT_SERIAL_NUMBER 0x80 | |
281 | #define SCSI_VPD_DEVICE_IDENTIFICATION 0x83 | |
282 | #define SCSI_VPD_EXTENDED_INQUIRY_DATA 0x86 | |
283 | #define SCSI_VPD_ATA_INFORMATION 0x89 | |
284 | #define SCSI_VPD_POWER_CONDITION 0x8a | |
285 | #define SCSI_VPD_POWER_CONSUMPTION 0x8d | |
286 | #define SCSI_VPD_BLOCK_LIMITS 0xb0 | |
287 | #define SCSI_VPD_BLOCK_DEVICE_CHARACTERISTICS 0xb1 | |
288 | #define SCSI_VPD_LOGICAL_BLOCK_PROVISIONING 0xb2 | |
289 | ||
832b75ed GG |
290 | /* defines for useful SCSI Status codes */ |
291 | #define SCSI_STATUS_CHECK_CONDITION 0x2 | |
292 | ||
293 | /* defines for useful Sense Key codes */ | |
4d59bff9 GG |
294 | #define SCSI_SK_NO_SENSE 0x0 |
295 | #define SCSI_SK_RECOVERED_ERR 0x1 | |
832b75ed GG |
296 | #define SCSI_SK_NOT_READY 0x2 |
297 | #define SCSI_SK_MEDIUM_ERROR 0x3 | |
298 | #define SCSI_SK_HARDWARE_ERROR 0x4 | |
299 | #define SCSI_SK_ILLEGAL_REQUEST 0x5 | |
300 | #define SCSI_SK_UNIT_ATTENTION 0x6 | |
a37e7145 | 301 | #define SCSI_SK_ABORTED_COMMAND 0xb |
832b75ed GG |
302 | |
303 | /* defines for useful Additional Sense Codes (ASCs) */ | |
304 | #define SCSI_ASC_NOT_READY 0x4 /* more info in ASCQ code */ | |
305 | #define SCSI_ASC_NO_MEDIUM 0x3a /* more info in ASCQ code */ | |
306 | #define SCSI_ASC_UNKNOWN_OPCODE 0x20 | |
ee38a438 | 307 | #define SCSI_ASC_INVALID_FIELD 0x24 |
832b75ed GG |
308 | #define SCSI_ASC_UNKNOWN_PARAM 0x26 |
309 | #define SCSI_ASC_WARNING 0xb | |
310 | #define SCSI_ASC_IMPENDING_FAILURE 0x5d | |
311 | ||
4d59bff9 GG |
312 | #define SCSI_ASCQ_ATA_PASS_THROUGH 0x1d |
313 | ||
832b75ed GG |
314 | /* Simplified error code (negative values as per errno) */ |
315 | #define SIMPLE_NO_ERROR 0 | |
316 | #define SIMPLE_ERR_NOT_READY 1 | |
317 | #define SIMPLE_ERR_BAD_OPCODE 2 | |
318 | #define SIMPLE_ERR_BAD_FIELD 3 /* in cbd */ | |
319 | #define SIMPLE_ERR_BAD_PARAM 4 /* in data */ | |
320 | #define SIMPLE_ERR_BAD_RESP 5 /* response fails sanity */ | |
321 | #define SIMPLE_ERR_NO_MEDIUM 6 /* no medium present */ | |
322 | #define SIMPLE_ERR_BECOMING_READY 7 /* device will be ready soon */ | |
323 | #define SIMPLE_ERR_TRY_AGAIN 8 /* some warning, try again */ | |
324 | #define SIMPLE_ERR_MEDIUM_HARDWARE 9 /* medium or hardware error */ | |
a37e7145 | 325 | #define SIMPLE_ERR_UNKNOWN 10 /* unknown sense value */ |
ff28b140 | 326 | #define SIMPLE_ERR_ABORTED_COMMAND 11 /* probably transport error */ |
832b75ed GG |
327 | |
328 | ||
329 | /* defines for functioncode parameter in SENDDIAGNOSTIC function */ | |
330 | #define SCSI_DIAG_NO_SELF_TEST 0x00 | |
331 | #define SCSI_DIAG_DEF_SELF_TEST 0xff | |
332 | #define SCSI_DIAG_BG_SHORT_SELF_TEST 0x01 | |
333 | #define SCSI_DIAG_BG_EXTENDED_SELF_TEST 0x02 | |
334 | #define SCSI_DIAG_FG_SHORT_SELF_TEST 0x05 | |
335 | #define SCSI_DIAG_FG_EXTENDED_SELF_TEST 0x06 | |
336 | #define SCSI_DIAG_ABORT_SELF_TEST 0x04 | |
337 | ||
338 | ||
339 | /* SCSI command timeout values (units are seconds) */ | |
f9e10201 JD |
340 | #define SCSI_TIMEOUT_DEFAULT 60 // should be longer than the spin up time |
341 | // of a disk in JBOD. | |
342 | ||
832b75ed GG |
343 | #define SCSI_TIMEOUT_SELF_TEST (5 * 60 * 60) /* allow max 5 hours for */ |
344 | /* extended foreground self test */ | |
345 | ||
346 | ||
347 | ||
348 | #define LOGPAGEHDRSIZE 4 | |
349 | ||
2127e193 GI |
350 | class scsi_device; |
351 | ||
ee38a438 GI |
352 | // Set of supported SCSI VPD pages. Constructor fetches Supported VPD pages |
353 | // VPD page and remembers the response for later queries. | |
354 | class supported_vpd_pages | |
355 | { | |
356 | public: | |
a86ec89e | 357 | explicit supported_vpd_pages(scsi_device * device); |
ee38a438 GI |
358 | ~supported_vpd_pages() { num_valid = 0; } |
359 | ||
360 | bool is_supported(int vpd_page_num) const; | |
361 | ||
362 | /* Returns 0 or less for VPD pages not supported or error */ | |
363 | int num_pages() const { return num_valid; } | |
364 | ||
365 | private: | |
366 | int num_valid; /* 0 or less for invalid */ | |
367 | unsigned char pages[256]; | |
368 | }; | |
369 | ||
370 | extern supported_vpd_pages * supported_vpd_pages_p; | |
371 | ||
ff28b140 TL |
372 | /* This is a heuristic that takes into account the command bytes and length |
373 | * to decide whether the presented unstructured sequence of bytes could be | |
374 | * a SCSI command. If so it returns true otherwise false. Vendor specific | |
375 | * SCSI commands (i.e. opcodes from 0xc0 to 0xff), if presented, are assumed | |
376 | * to follow SCSI conventions (i.e. length of 6, 10, 12 or 16 bytes). The | |
377 | * only SCSI commands considered above 16 bytes of length are the Variable | |
378 | * Length Commands (opcode 0x7f) and the XCDB wrapped commands (opcode 0x7e). | |
379 | * Both have an inbuilt length field which can be cross checked with clen. | |
380 | * No NVMe commands (64 bytes long plus some extra added by some OSes) have | |
381 | * opcodes 0x7e or 0x7f yet. ATA is register based but SATA has FIS | |
382 | * structures that are sent across the wire. The FIS register structure is | |
383 | * used to move a command from a SATA host to device, but the ATA 'command' | |
384 | * is not the first byte. So it is harder to say what will happen if a | |
385 | * FIS structure is presented as a SCSI command, hopefully there is a low | |
386 | * probability this function will yield true in that case. */ | |
387 | bool is_scsi_cdb(const uint8_t * cdbp, int clen); | |
ee38a438 | 388 | |
cfbba5b9 GI |
389 | // Print SCSI debug messages? |
390 | extern unsigned char scsi_debugmode; | |
391 | ||
832b75ed GG |
392 | void scsi_do_sense_disect(const struct scsi_cmnd_io * in, |
393 | struct scsi_sense_disect * out); | |
394 | ||
4d59bff9 GG |
395 | int scsiSimpleSenseFilter(const struct scsi_sense_disect * sinfo); |
396 | ||
832b75ed GG |
397 | const char * scsiErrString(int scsiErr); |
398 | ||
a7e8ffec GI |
399 | int scsi_vpd_dev_id_iter(const unsigned char * initial_desig_desc, |
400 | int page_len, int * off, int m_assoc, | |
401 | int m_desig_type, int m_code_set); | |
402 | ||
403 | int scsi_decode_lu_dev_id(const unsigned char * b, int blen, char * s, | |
404 | int slen, int * transport); | |
405 | ||
406 | ||
832b75ed | 407 | /* STANDARD SCSI Commands */ |
2127e193 | 408 | int scsiTestUnitReady(scsi_device * device); |
832b75ed | 409 | |
ff28b140 | 410 | int scsiStdInquiry(scsi_device * device, uint8_t *pBuf, int bufLen); |
832b75ed | 411 | |
ff28b140 TL |
412 | int scsiInquiryVpd(scsi_device * device, int vpd_page, uint8_t *pBuf, |
413 | int bufLen); | |
832b75ed | 414 | |
ff28b140 TL |
415 | int scsiLogSense(scsi_device * device, int pagenum, int subpagenum, |
416 | uint8_t *pBuf, int bufLen, int known_resp_len); | |
832b75ed | 417 | |
2127e193 | 418 | int scsiLogSelect(scsi_device * device, int pcr, int sp, int pc, int pagenum, |
ff28b140 | 419 | int subpagenum, uint8_t *pBuf, int bufLen); |
2127e193 GI |
420 | |
421 | int scsiModeSense(scsi_device * device, int pagenum, int subpagenum, int pc, | |
ff28b140 | 422 | uint8_t *pBuf, int bufLen); |
832b75ed | 423 | |
ff28b140 | 424 | int scsiModeSelect(scsi_device * device, int sp, uint8_t *pBuf, int bufLen); |
832b75ed | 425 | |
2127e193 | 426 | int scsiModeSense10(scsi_device * device, int pagenum, int subpagenum, int pc, |
ff28b140 | 427 | uint8_t *pBuf, int bufLen); |
832b75ed | 428 | |
ff28b140 | 429 | int scsiModeSelect10(scsi_device * device, int sp, uint8_t *pBuf, int bufLen); |
832b75ed | 430 | |
ff28b140 | 431 | int scsiModePageOffset(const uint8_t * resp, int len, int modese_len); |
832b75ed | 432 | |
ff28b140 TL |
433 | int scsiRequestSense(scsi_device * device, |
434 | struct scsi_sense_disect * sense_info); | |
832b75ed | 435 | |
ff28b140 TL |
436 | int scsiSendDiagnostic(scsi_device * device, int functioncode, uint8_t *pBuf, |
437 | int bufLen); | |
832b75ed | 438 | |
ff28b140 TL |
439 | int scsiReadDefect10(scsi_device * device, int req_plist, int req_glist, |
440 | int dl_format, uint8_t *pBuf, int bufLen); | |
832b75ed | 441 | |
ee38a438 | 442 | int scsiReadDefect12(scsi_device * device, int req_plist, int req_glist, |
ff28b140 TL |
443 | int dl_format, int addrDescIndex, uint8_t *pBuf, |
444 | int bufLen); | |
ee38a438 | 445 | |
a7e8ffec GI |
446 | int scsiReadCapacity10(scsi_device * device, unsigned int * last_lbp, |
447 | unsigned int * lb_sizep); | |
448 | ||
ff28b140 | 449 | int scsiReadCapacity16(scsi_device * device, uint8_t *pBuf, int bufLen); |
a7e8ffec | 450 | |
832b75ed | 451 | /* SMART specific commands */ |
ff28b140 TL |
452 | int scsiCheckIE(scsi_device * device, int hasIELogPage, int hasTempLogPage, |
453 | uint8_t *asc, uint8_t *ascq, uint8_t *currenttemp, | |
454 | uint8_t *triptemp); | |
832b75ed | 455 | |
2127e193 | 456 | int scsiFetchIECmpage(scsi_device * device, struct scsi_iec_mode_page *iecp, |
832b75ed GG |
457 | int modese_len); |
458 | int scsi_IsExceptionControlEnabled(const struct scsi_iec_mode_page *iecp); | |
459 | int scsi_IsWarningEnabled(const struct scsi_iec_mode_page *iecp); | |
2127e193 | 460 | int scsiSetExceptionControlAndWarning(scsi_device * device, int enabled, |
832b75ed GG |
461 | const struct scsi_iec_mode_page *iecp); |
462 | void scsiDecodeErrCounterPage(unsigned char * resp, | |
463 | struct scsiErrorCounter *ecp); | |
464 | void scsiDecodeNonMediumErrPage(unsigned char * resp, | |
465 | struct scsiNonMediumError *nmep); | |
2127e193 | 466 | int scsiFetchExtendedSelfTestTime(scsi_device * device, int * durationSec, |
832b75ed | 467 | int modese_len); |
2127e193 GI |
468 | int scsiCountFailedSelfTests(scsi_device * device, int noisy); |
469 | int scsiSelfTestInProgress(scsi_device * device, int * inProgress); | |
470 | int scsiFetchControlGLTSD(scsi_device * device, int modese_len, int current); | |
471 | int scsiSetControlGLTSD(scsi_device * device, int enabled, int modese_len); | |
472 | int scsiFetchTransportProtocol(scsi_device * device, int modese_len); | |
d2e702cf GI |
473 | int scsiGetRPM(scsi_device * device, int modese_len, int * form_factorp, |
474 | int * haw_zbcp); | |
ee38a438 GI |
475 | int scsiGetSetCache(scsi_device * device, int modese_len, short int * wce, |
476 | short int * rcd); | |
ff28b140 TL |
477 | uint64_t scsiGetSize(scsi_device * device, bool avoid_rcap16, |
478 | struct scsi_readcap_resp * srrp); | |
832b75ed | 479 | |
a7e8ffec | 480 | /* T10 Standard IE Additional Sense Code strings taken from t10.org */ |
ff28b140 TL |
481 | const char* scsiGetIEString(uint8_t asc, uint8_t ascq); |
482 | int scsiGetTemp(scsi_device * device, uint8_t *currenttemp, uint8_t *triptemp); | |
832b75ed GG |
483 | |
484 | ||
2127e193 GI |
485 | int scsiSmartDefaultSelfTest(scsi_device * device); |
486 | int scsiSmartShortSelfTest(scsi_device * device); | |
487 | int scsiSmartExtendSelfTest(scsi_device * device); | |
488 | int scsiSmartShortCapSelfTest(scsi_device * device); | |
489 | int scsiSmartExtendCapSelfTest(scsi_device * device); | |
490 | int scsiSmartSelfTestAbort(scsi_device * device); | |
832b75ed GG |
491 | |
492 | const char * scsiTapeAlertsTapeDevice(unsigned short code); | |
493 | const char * scsiTapeAlertsChangerDevice(unsigned short code); | |
494 | ||
ff28b140 TL |
495 | const char * scsi_get_opcode_name(uint8_t opcode); |
496 | void scsi_format_id_string(char * out, const uint8_t * in, int n); | |
ee38a438 | 497 | |
ff28b140 | 498 | void dStrHex(const uint8_t * up, int len, int no_ascii); |
4d59bff9 | 499 | |
ee38a438 GI |
500 | /* Attempt to find the first SCSI sense data descriptor that matches the |
501 | given 'desc_type'. If found return pointer to start of sense data | |
502 | descriptor; otherwise (including fixed format sense data) returns NULL. */ | |
503 | const unsigned char * sg_scsi_sense_desc_find(const unsigned char * sensep, | |
ff28b140 | 504 | int sense_len, int desc_type); |
ee38a438 | 505 | |
832b75ed GG |
506 | |
507 | /* SCSI command transmission interface function declaration. Its | |
508 | * definition is target OS specific (see os_<OS>.c file). | |
509 | * Returns 0 if SCSI command successfully launched and response | |
510 | * received. Even when 0 is returned the caller should check | |
511 | * scsi_cmnd_io::scsi_status for SCSI defined errors and warnings | |
512 | * (e.g. CHECK CONDITION). If the SCSI command could not be issued | |
513 | * (e.g. device not present or not a SCSI device) or some other problem | |
514 | * arises (e.g. timeout) then returns a negative errno value. */ | |
2127e193 GI |
515 | // Moved to C++ interface |
516 | //int do_scsi_cmnd_io(int dev_fd, struct scsi_cmnd_io * iop, int report); | |
517 | ||
832b75ed GG |
518 | |
519 | ||
832b75ed | 520 | #endif |