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