1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

root/trunk/smartmontools/scsicmds.h @ 3258

Revision 3258, 14.8 KB (checked in by manfred99, 3 years ago)

tweak some includes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * scsicmds.h
3 *
4 * Home page of code is: http://smartmontools.sourceforge.net
5 *
6 * Copyright (C) 2002-8 Bruce Allen <smartmontools-support@lists.sourceforge.net>
7 * Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
8 *
9 * Additional SCSI work:
10 * Copyright (C) 2003-10 Douglas Gilbert <dgilbert@interlog.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * You should have received a copy of the GNU General Public License
18 * (for example COPYING); if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * This code was originally developed as a Senior Thesis by Michael Cornwell
22 * at the Concurrent Systems Laboratory (now part of the Storage Systems
23 * Research Center), Jack Baskin School of Engineering, University of
24 * California, Santa Cruz. http://ssrc.soe.ucsc.edu/
25 *
26 * N.B. What was formerly known as "SMART" are now called "informational
27 * exceptions" in recent t10.org drafts (i.e. recent SCSI).
28 *
29 */
30
31
32#ifndef SCSICMDS_H_
33#define SCSICMDS_H_
34
35#define SCSICMDS_H_CVSID "$Id$\n"
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40
41/* #define SCSI_DEBUG 1 */ /* Comment out to disable command debugging */
42
43/* Following conditional defines just in case OS already has them defined.
44 * If they are defined we hope they are defined correctly (for SCSI). */
45#ifndef TEST_UNIT_READY
46#define TEST_UNIT_READY 0x0
47#endif
48#ifndef LOG_SELECT
49#define LOG_SELECT 0x4c
50#endif
51#ifndef LOG_SENSE
52#define LOG_SENSE 0x4d
53#endif
54#ifndef MODE_SENSE
55#define MODE_SENSE 0x1a
56#endif
57#ifndef MODE_SENSE_10
58#define MODE_SENSE_10 0x5a
59#endif
60#ifndef MODE_SELECT
61#define MODE_SELECT 0x15
62#endif
63#ifndef MODE_SELECT_10
64#define MODE_SELECT_10 0x55
65#endif
66#ifndef INQUIRY
67#define INQUIRY 0x12
68#endif
69#ifndef REQUEST_SENSE
70#define REQUEST_SENSE  0x03
71#endif
72#ifndef RECEIVE_DIAGNOSTIC
73#define RECEIVE_DIAGNOSTIC  0x1c
74#endif
75#ifndef SEND_DIAGNOSTIC
76#define SEND_DIAGNOSTIC  0x1d
77#endif
78#ifndef READ_DEFECT_10
79#define READ_DEFECT_10  0x37
80#endif
81#ifndef START_STOP_UNIT
82#define START_STOP_UNIT  0x1b
83#endif
84#ifndef REPORT_LUNS
85#define REPORT_LUNS  0xa0
86#endif
87#ifndef READ_CAPACITY_10
88#define READ_CAPACITY_10  0x25
89#endif
90#ifndef READ_CAPACITY_16
91#define READ_CAPACITY_16  0x9e  /* service action 0x10 */
92#endif
93
94#ifndef SAT_ATA_PASSTHROUGH_12
95#define SAT_ATA_PASSTHROUGH_12 0xa1
96#endif
97#ifndef SAT_ATA_PASSTHROUGH_16
98#define SAT_ATA_PASSTHROUGH_16 0x85
99#endif
100
101typedef unsigned char UINT8;
102typedef signed char INT8;
103typedef unsigned int UINT32;
104typedef int INT32;
105
106#define DXFER_NONE        0
107#define DXFER_FROM_DEVICE 1
108#define DXFER_TO_DEVICE   2
109
110struct scsi_cmnd_io
111{
112    UINT8 * cmnd;       /* [in]: ptr to SCSI command block (cdb) */
113    size_t  cmnd_len;   /* [in]: number of bytes in SCSI command */
114    int dxfer_dir;      /* [in]: DXFER_NONE, DXFER_FROM_DEVICE, or
115                                 DXFER_TO_DEVICE */
116    UINT8 * dxferp;     /* [in]: ptr to outgoing or incoming data buffer */
117    size_t dxfer_len;   /* [in]: bytes to be transferred to/from dxferp */
118    UINT8 * sensep;     /* [in]: ptr to sense buffer, filled when
119                                 CHECK CONDITION status occurs */
120    size_t max_sense_len; /* [in]: max number of bytes to write to sensep */
121    unsigned timeout;   /* [in]: seconds, 0-> default timeout (60 seconds?) */
122    size_t resp_sense_len;  /* [out]: sense buffer length written */
123    UINT8 scsi_status;  /* [out]: 0->ok, 2->CHECK CONDITION, etc ... */
124    int resid;          /* [out]: Number of bytes requested to be transferred
125                                  less actual number transferred (0 if not
126                                   supported) */
127};
128
129struct scsi_sense_disect {
130    UINT8 error_code;
131    UINT8 sense_key;
132    UINT8 asc; 
133    UINT8 ascq;
134};
135
136/* Useful data from Informational Exception Control mode page (0x1c) */
137#define SCSI_IECMP_RAW_LEN 64
138struct scsi_iec_mode_page {
139    UINT8 requestedCurrent;
140    UINT8 gotCurrent;
141    UINT8 requestedChangeable;
142    UINT8 gotChangeable;
143    UINT8 modese_len;   /* 0 (don't know), 6 or 10 */
144    UINT8 raw_curr[SCSI_IECMP_RAW_LEN];
145    UINT8 raw_chg[SCSI_IECMP_RAW_LEN];
146};
147
148/* Carrier for Error counter log pages (e.g. read, write, verify ...) */
149struct scsiErrorCounter {
150    UINT8 gotPC[7];
151    UINT8 gotExtraPC;
152    uint64_t counter[8];
153};
154
155/* Carrier for Non-medium error log page */
156struct scsiNonMediumError {
157    UINT8 gotPC0;
158    UINT8 gotExtraPC;
159    uint64_t counterPC0;
160    UINT8 gotTFE_H;
161    uint64_t counterTFE_H; /* Track following errors [Hitachi] */
162    UINT8 gotPE_H;
163    uint64_t counterPE_H;  /* Positioning errors [Hitachi] */
164};
165
166/* SCSI Peripheral types (of interest) */
167#define SCSI_PT_DIRECT_ACCESS           0x0
168#define SCSI_PT_SEQUENTIAL_ACCESS       0x1
169#define SCSI_PT_CDROM                   0x5
170#define SCSI_PT_MEDIUM_CHANGER          0x8
171#define SCSI_PT_ENCLOSURE               0xd
172
173/* ANSI SCSI-3 Log Pages retrieved by LOG SENSE. */
174#define SUPPORTED_LPAGES                        0x00
175#define BUFFER_OVERRUN_LPAGE                    0x01
176#define WRITE_ERROR_COUNTER_LPAGE               0x02
177#define READ_ERROR_COUNTER_LPAGE                0x03
178#define READ_REVERSE_ERROR_COUNTER_LPAGE        0x04
179#define VERIFY_ERROR_COUNTER_LPAGE              0x05
180#define NON_MEDIUM_ERROR_LPAGE                  0x06
181#define LAST_N_ERROR_LPAGE                      0x07
182#define FORMAT_STATUS_LPAGE                     0x08
183#define TEMPERATURE_LPAGE                       0x0d
184#define STARTSTOP_CYCLE_COUNTER_LPAGE           0x0e
185#define APPLICATION_CLIENT_LPAGE                0x0f
186#define SELFTEST_RESULTS_LPAGE                  0x10
187#define BACKGROUND_RESULTS_LPAGE                0x15   /* SBC-3 */
188#define PROTOCOL_SPECIFIC_LPAGE                 0x18
189#define IE_LPAGE                                0x2f
190
191/* Seagate vendor specific log pages. */
192#define SEAGATE_CACHE_LPAGE                     0x37
193#define SEAGATE_FACTORY_LPAGE                   0x3e
194
195/* Log page response lengths */
196#define LOG_RESP_SELF_TEST_LEN 0x194
197
198/* See the SSC-2 document at www.t10.org . Earler note: From IBM
199Documentation, see http://www.storage.ibm.com/techsup/hddtech/prodspecs.htm */
200#define TAPE_ALERTS_LPAGE                        0x2e
201
202/* ANSI SCSI-3 Mode Pages */
203#define VENDOR_UNIQUE_PAGE                       0x00
204#define READ_WRITE_ERROR_RECOVERY_PAGE           0x01
205#define DISCONNECT_RECONNECT_PAGE                0x02
206#define FORMAT_DEVICE_PAGE                       0x03
207#define RIGID_DISK_DRIVE_GEOMETRY_PAGE           0x04
208#define FLEXIBLE_DISK_PAGE                       0x05
209#define VERIFY_ERROR_RECOVERY_PAGE               0x07
210#define CACHING_PAGE                             0x08
211#define PERIPHERAL_DEVICE_PAGE                   0x09
212#define XOR_CONTROL_MODE_PAGE                    0x10
213#define CONTROL_MODE_PAGE                        0x0a
214#define MEDIUM_TYPES_SUPPORTED_PAGE              0x0b
215#define NOTCH_PAGE                               0x0c
216#define CD_DEVICE_PAGE                           0x0d
217#define CD_AUDIO_CONTROL_PAGE                    0x0e
218#define DATA_COMPRESSION_PAGE                    0x0f
219#define ENCLOSURE_SERVICES_MANAGEMENT_PAGE       0x14
220#define PROTOCOL_SPECIFIC_LUN_PAGE               0x18
221#define PROTOCOL_SPECIFIC_PORT_PAGE              0x19
222#define POWER_CONDITION_PAGE                     0x1a
223#define INFORMATIONAL_EXCEPTIONS_CONTROL_PAGE    0x1c
224#define FAULT_FAILURE_REPORTING_PAGE             0x1c
225
226/* Background control mode subpage is [0x1c,0x1] */
227#define BACKGROUND_CONTROL_M_SUBPAGE             0x1   /* SBC-2 */
228
229#define ALL_MODE_PAGES                           0x3f
230
231/* Mode page control field */
232#define MPAGE_CONTROL_CURRENT               0
233#define MPAGE_CONTROL_CHANGEABLE            1
234#define MPAGE_CONTROL_DEFAULT               2
235#define MPAGE_CONTROL_SAVED                 3
236
237/* defines for useful SCSI Status codes */
238#define SCSI_STATUS_CHECK_CONDITION     0x2
239
240/* defines for useful Sense Key codes */
241#define SCSI_SK_NO_SENSE                0x0
242#define SCSI_SK_RECOVERED_ERR           0x1
243#define SCSI_SK_NOT_READY               0x2
244#define SCSI_SK_MEDIUM_ERROR            0x3
245#define SCSI_SK_HARDWARE_ERROR          0x4
246#define SCSI_SK_ILLEGAL_REQUEST         0x5
247#define SCSI_SK_UNIT_ATTENTION          0x6
248#define SCSI_SK_ABORTED_COMMAND         0xb
249
250/* defines for useful Additional Sense Codes (ASCs) */
251#define SCSI_ASC_NOT_READY              0x4     /* more info in ASCQ code */
252#define SCSI_ASC_NO_MEDIUM              0x3a    /* more info in ASCQ code */
253#define SCSI_ASC_UNKNOWN_OPCODE         0x20
254#define SCSI_ASC_UNKNOWN_FIELD          0x24
255#define SCSI_ASC_UNKNOWN_PARAM          0x26
256#define SCSI_ASC_WARNING                0xb
257#define SCSI_ASC_IMPENDING_FAILURE      0x5d
258
259#define SCSI_ASCQ_ATA_PASS_THROUGH      0x1d
260
261/* Simplified error code (negative values as per errno) */
262#define SIMPLE_NO_ERROR                 0
263#define SIMPLE_ERR_NOT_READY            1
264#define SIMPLE_ERR_BAD_OPCODE           2
265#define SIMPLE_ERR_BAD_FIELD            3       /* in cbd */
266#define SIMPLE_ERR_BAD_PARAM            4       /* in data */
267#define SIMPLE_ERR_BAD_RESP             5       /* response fails sanity */
268#define SIMPLE_ERR_NO_MEDIUM            6       /* no medium present */
269#define SIMPLE_ERR_BECOMING_READY       7       /* device will be ready soon */
270#define SIMPLE_ERR_TRY_AGAIN            8       /* some warning, try again */
271#define SIMPLE_ERR_MEDIUM_HARDWARE      9       /* medium or hardware error */
272#define SIMPLE_ERR_UNKNOWN              10      /* unknown sense value */
273#define SIMPLE_ERR_ABORTED_COMMAND      11      /* most likely transport error */
274
275
276/* defines for functioncode parameter in SENDDIAGNOSTIC function */
277#define SCSI_DIAG_NO_SELF_TEST          0x00
278#define SCSI_DIAG_DEF_SELF_TEST         0xff
279#define SCSI_DIAG_BG_SHORT_SELF_TEST    0x01
280#define SCSI_DIAG_BG_EXTENDED_SELF_TEST 0x02
281#define SCSI_DIAG_FG_SHORT_SELF_TEST    0x05
282#define SCSI_DIAG_FG_EXTENDED_SELF_TEST 0x06
283#define SCSI_DIAG_ABORT_SELF_TEST       0x04
284
285
286/* SCSI command timeout values (units are seconds) */
287#define SCSI_TIMEOUT_DEFAULT    20  // should be longer than the spin up time
288                                    // of a disk in standby mode.
289#define SCSI_TIMEOUT_SELF_TEST  (5 * 60 * 60)   /* allow max 5 hours for */
290                                            /* extended foreground self test */
291
292
293
294#define LOGPAGEHDRSIZE  4
295
296class scsi_device;
297
298// Print SCSI debug messages?
299extern unsigned char scsi_debugmode;
300
301void scsi_do_sense_disect(const struct scsi_cmnd_io * in,
302                          struct scsi_sense_disect * out);
303
304int scsiSimpleSenseFilter(const struct scsi_sense_disect * sinfo);
305
306const char * scsiErrString(int scsiErr);
307
308/* STANDARD SCSI Commands  */
309int scsiTestUnitReady(scsi_device * device);
310
311int scsiStdInquiry(scsi_device * device, UINT8 *pBuf, int bufLen);
312
313int scsiInquiryVpd(scsi_device * device, int vpd_page, UINT8 *pBuf, int bufLen);
314
315int scsiLogSense(scsi_device * device, int pagenum, int subpagenum, UINT8 *pBuf,
316                 int bufLen, int known_resp_len);
317
318int scsiLogSelect(scsi_device * device, int pcr, int sp, int pc, int pagenum,
319                  int subpagenum, UINT8 *pBuf, int bufLen);
320
321int scsiModeSense(scsi_device * device, int pagenum, int subpagenum, int pc,
322                  UINT8 *pBuf, int bufLen);
323
324int scsiModeSelect(scsi_device * device, int sp, UINT8 *pBuf, int bufLen);
325
326int scsiModeSense10(scsi_device * device, int pagenum, int subpagenum, int pc,
327                    UINT8 *pBuf, int bufLen);
328
329int scsiModeSelect10(scsi_device * device, int sp, UINT8 *pBuf, int bufLen);
330
331int scsiModePageOffset(const UINT8 * resp, int len, int modese_len);
332
333int scsiRequestSense(scsi_device * device, struct scsi_sense_disect * sense_info);
334
335int scsiSendDiagnostic(scsi_device * device, int functioncode, UINT8 *pBuf, int bufLen);
336
337int scsiReceiveDiagnostic(scsi_device * device, int pcv, int pagenum, UINT8 *pBuf,
338                      int bufLen);
339
340int scsiReadDefect10(scsi_device * device, int req_plist, int req_glist, int dl_format,
341                     UINT8 *pBuf, int bufLen);
342
343/* SMART specific commands */
344int scsiCheckIE(scsi_device * device, int hasIELogPage, int hasTempLogPage, UINT8 *asc,
345                UINT8 *ascq, UINT8 *currenttemp, UINT8 *triptemp);
346
347int scsiFetchIECmpage(scsi_device * device, struct scsi_iec_mode_page *iecp,
348                      int modese_len);
349int scsi_IsExceptionControlEnabled(const struct scsi_iec_mode_page *iecp);
350int scsi_IsWarningEnabled(const struct scsi_iec_mode_page *iecp);
351int scsiSetExceptionControlAndWarning(scsi_device * device, int enabled,
352                            const struct scsi_iec_mode_page *iecp);
353void scsiDecodeErrCounterPage(unsigned char * resp,
354                              struct scsiErrorCounter *ecp);
355void scsiDecodeNonMediumErrPage(unsigned char * resp,
356                                struct scsiNonMediumError *nmep);
357int scsiFetchExtendedSelfTestTime(scsi_device * device, int * durationSec,
358                                  int modese_len);
359int scsiCountFailedSelfTests(scsi_device * device, int noisy);
360int scsiSelfTestInProgress(scsi_device * device, int * inProgress);
361int scsiFetchControlGLTSD(scsi_device * device, int modese_len, int current);
362int scsiSetControlGLTSD(scsi_device * device, int enabled, int modese_len);
363int scsiFetchTransportProtocol(scsi_device * device, int modese_len);
364
365/* T10 Standard IE Additional Sense Code strings taken from t10.org */
366
367const char* scsiGetIEString(UINT8 asc, UINT8 ascq);
368int scsiGetTemp(scsi_device * device, UINT8 *currenttemp, UINT8 *triptemp);
369
370
371int scsiSmartIBMOfflineTest(scsi_device * device);
372
373int scsiSmartDefaultSelfTest(scsi_device * device);
374int scsiSmartShortSelfTest(scsi_device * device);
375int scsiSmartExtendSelfTest(scsi_device * device);
376int scsiSmartShortCapSelfTest(scsi_device * device);
377int scsiSmartExtendCapSelfTest(scsi_device * device);
378int scsiSmartSelfTestAbort(scsi_device * device);
379
380const char * scsiTapeAlertsTapeDevice(unsigned short code);
381const char * scsiTapeAlertsChangerDevice(unsigned short code);
382
383const char * scsi_get_opcode_name(UINT8 opcode);
384void dStrHex(const char* str, int len, int no_ascii);
385inline void dStrHex(const unsigned char* str, int len, int no_ascii)
386  { dStrHex((const char *)str, len, no_ascii); }
387
388
389/* SCSI command transmission interface function declaration. Its
390 * definition is target OS specific (see os_<OS>.c file).
391 * Returns 0 if SCSI command successfully launched and response
392 * received. Even when 0 is returned the caller should check
393 * scsi_cmnd_io::scsi_status for SCSI defined errors and warnings
394 * (e.g. CHECK CONDITION). If the SCSI command could not be issued
395 * (e.g. device not present or not a SCSI device) or some other problem
396 * arises (e.g. timeout) then returns a negative errno value. */
397// Moved to C++ interface
398//int do_scsi_cmnd_io(int dev_fd, struct scsi_cmnd_io * iop, int report);
399
400
401
402#endif
403
Note: See TracBrowser for help on using the browser.