xref: /titanic_50/usr/src/lib/scsi/libsmp/common/libsmp.h (revision 23a1ccea6aac035f084a7a4cdc968687d1b02daf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	_LIBSMP_H
27 #define	_LIBSMP_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/types.h>
34 #include <sys/sysmacros.h>
35 #include <sys/scsi/impl/usmp.h>
36 #include <sys/scsi/generic/smp_frames.h>
37 #include <libnvpair.h>
38 #include <stdarg.h>
39 
40 #define	LIBSMP_VERSION		1
41 
42 #define	SMP_TARGET_C_LONG_RESP	0x01	/* Long response (SAS-2 10.4.3.4) */
43 #define	SMP_TARGET_C_ZONING	0x02	/* Zoning supported */
44 #define	SMP_TARGET_C_ZG_256	0x04	/* 256 zone groups supported */
45 
46 typedef enum smp_errno {
47 	ESMP_NONE,		/* no error */
48 	ESMP_NOMEM,		/* no memory */
49 	ESMP_ZERO_LENGTH,	/* zero-length allocation requested */
50 	ESMP_VERSION,		/* library version mismatch */
51 	ESMP_BADTARGET,		/* invalid target specification */
52 	ESMP_BADFUNC,		/* invalid SMP function */
53 	ESMP_BADENGINE,		/* engine library corrupt */
54 	ESMP_NOENGINE,		/* engine library not found */
55 	ESMP_ENGINE_INIT,	/* engine initialization failed */
56 	ESMP_ENGINE_VER,	/* engine version mismatch */
57 	ESMP_ENGINE_BADPATH,	/* engine path contains no usable components */
58 	ESMP_BADLENGTH,		/* buffer length overflow or size error */
59 	ESMP_NEEDBUF,		/* missing required buffer */
60 	ESMP_PLUGIN,		/* no plugins found */
61 	ESMP_IO,		/* I/O operation failed */
62 	ESMP_SYS,		/* system call failed */
63 	ESMP_PERM,		/* insufficient permissions */
64 	ESMP_RANGE,		/* parameter outside valid range */
65 	ESMP_NOTSUP,		/* operation not supported */
66 	ESMP_UNKNOWN,		/* error of unknown type */
67 	ESMP_REPGEN_FAILED,	/* initial report general command failed */
68 	ESMP_MAX		/* maximum libsmp errno value */
69 } smp_errno_t;
70 
71 typedef struct smp_target_def {
72 	const char *std_engine;
73 	const void *std_def;
74 } smp_target_def_t;
75 
76 struct smp_target;
77 typedef struct smp_target smp_target_t;
78 
79 struct smp_action;
80 typedef struct smp_action smp_action_t;
81 
82 extern int smp_init(int);
83 extern void smp_fini(void);
84 
85 extern smp_target_t *smp_open(const smp_target_def_t *);
86 extern uint_t smp_target_getcap(const smp_target_t *);
87 extern uint16_t smp_target_get_change_count(const smp_target_t *);
88 extern void smp_target_set_change_count(smp_target_t *, uint16_t);
89 extern const char *smp_target_vendor(const smp_target_t *);
90 extern const char *smp_target_product(const smp_target_t *);
91 extern const char *smp_target_revision(const smp_target_t *);
92 extern const char *smp_target_component_vendor(const smp_target_t *);
93 extern uint16_t smp_target_component_id(const smp_target_t *);
94 extern uint8_t smp_target_component_revision(const smp_target_t *);
95 extern void smp_target_name(const smp_target_t *, char *, size_t);
96 extern uint64_t smp_target_addr(const smp_target_t *);
97 extern void smp_close(smp_target_t *);
98 
99 extern smp_errno_t smp_errno(void);
100 extern smp_errno_t smp_errcode(const char *);
101 extern const char *smp_errmsg(void);
102 extern const char *smp_strerror(smp_errno_t);
103 extern const char *smp_errname(smp_errno_t);
104 
105 extern char *smp_trim_strdup(const char *, size_t);
106 
107 extern smp_action_t *smp_action_alloc(smp_function_t, smp_target_t *, size_t);
108 extern smp_action_t *smp_action_xalloc(smp_function_t, smp_target_t *,
109     void *, size_t, void *, size_t);
110 extern uint32_t smp_action_get_timeout(const smp_action_t *);
111 extern void smp_action_set_timeout(smp_action_t *, uint32_t);
112 extern void smp_action_get_request(const smp_action_t *, void **, size_t *);
113 extern void smp_action_get_response(const smp_action_t *,
114     smp_result_t *, void **, size_t *);
115 extern int smp_exec(smp_action_t *, smp_target_t *);
116 extern void smp_action_free(smp_action_t *);
117 
118 extern nvlist_t *smp_discover(const smp_target_def_t **, size_t);
119 extern nvlist_t *smp_discover_targets(smp_target_t **, size_t);
120 
121 #ifdef	__cplusplus
122 }
123 #endif
124 
125 #endif	/* _LIBSMP_H */
126