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