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