xref: /freebsd/contrib/smart/libsmart_priv.h (revision 7419d6e463fee40f0f52cd5bc46a93cbb7ac6114)
1 /*
2  * Copyright (c) 2016-2021 Chuck Tuffli <chuck@tuffli.net>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #ifndef _LIBSMART_PRIV_H
17 #define _LIBSMART_PRIV_H
18 
19 /* OS-independent structures and definitions internal to libsmart */
20 
21 #define PAGE_ID_ATA_SMART_READ_DATA	0xd0		/* SMART Read Data */
22 #define PAGE_ID_ATA_SMART_RET_STATUS	0xda		/* SMART Return Status */
23 
24 #define PAGE_ID_SCSI_SUPPORTED_PAGES	0x00
25 #define PAGE_ID_SCSI_WRITE_ERR		0x02		/* Write Error counter */
26 #define PAGE_ID_SCSI_READ_ERR		0x03		/* Read Error counter */
27 #define PAGE_ID_SCSI_VERIFY_ERR		0x05		/* Verify Error counter */
28 #define PAGE_ID_SCSI_NON_MEDIUM_ERR	0x06		/* Non-Medium Error */
29 #define PAGE_ID_SCSI_LAST_N_ERR		0x07		/* Last n Error events */
30 #define PAGE_ID_SCSI_TEMPERATURE	0x0d		/* Temperature */
31 #define PAGE_ID_SCSI_START_STOP_CYCLE	0x0e		/* Start-Stop Cycle counter */
32 #define PAGE_ID_SCSI_INFO_EXCEPTION	0x2f		/* Informational Exceptions */
33 
34 extern bool do_debug;
35 
36 #define dprintf(f, ...)	if (do_debug) fprintf(stderr, "dbg: " f, ## __VA_ARGS__)
37 
38 /* General information about the device */
39 typedef struct smart_info_s {
40 		 /* device supports SMART */
41 	uint32_t supported:1,
42 		 /* storage protocol is tunneled (e.g. ATA inside SCSI) */
43 		 tunneled:1,
44 		 :30;
45 	/*
46 	 * Device-provided information, including
47 	 *  - vendor name
48 	 *  - device / model
49 	 *  - firmware revision
50 	 *  - serial number
51 	 * Protocols may provide a subset of this information
52 	 */
53 	char vendor[16], device[48], rev[16], serial[32];
54 } smart_info_t;
55 
56 /* List of pages providing SMART/health data */
57 typedef struct smart_page_list_s {
58 	uint32_t	pg_count;
59 	struct {
60 		uint32_t id;
61 		size_t	bytes;
62 	} pages[];
63 } smart_page_list_t;
64 
65 /*
66  * The device handle (i.e. smart_h) is an opaque pointer to memory containing
67  * device/OS independent and dependent data. The library uses type punning to
68  * isolate the OS-independent portion (struct smart_s) from the OS-dependent
69  * details. Because of this, the device layer allocates and frees this memory.
70  */
71 typedef struct smart_s {
72 	smart_protocol_e protocol;
73 	smart_info_t info;
74 	smart_page_list_t *pg_list;
75 	/* Device / OS specific follows this structure */
76 } smart_t;
77 
78 /* Return a textual description of the ATA attribute */
79 const char * __smart_ata_desc(uint32_t page, uint32_t id);
80 /* Return a textual description of the SCSI error attribute */
81 const char * __smart_scsi_err_desc(uint32_t id);
82 
83 #endif
84