dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / scsi / libses / common / libses_plugin.h
blob0bae67bb29b9451e1f45b70ea2aab01e92909b9c
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
26 #ifndef _LIBSES_PLUGIN_H
27 #define _LIBSES_PLUGIN_H
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #define LIBSES_PLUGIN_VERSION 1
36 * These are the primary APIs for plugins to interact with libses.
39 struct ses_plugin;
40 typedef struct ses_plugin ses_plugin_t;
42 typedef enum {
43 SES_PAGE_DIAG,
44 SES_PAGE_CTL
45 } ses_pagetype_t;
47 typedef enum ses_page_req {
48 SES_REQ_OPTIONAL,
49 SES_REQ_MANDATORY_ALL,
50 SES_REQ_MANDATORY_STANDARD,
51 SES_REQ_OPTIONAL_STANDARD
52 } ses_page_req_t;
54 typedef struct ses_pagedesc {
55 int spd_pagenum;
56 size_t (*spd_ctl_len)(uint_t, int, size_t);
57 void *(*spd_ctl_fill)(ses_plugin_t *, void *, size_t,
58 ses_node_t *);
59 void *(*spd_index)(ses_plugin_t *, ses_node_t *,
60 void *, size_t, size_t *);
61 int spd_gcoff;
62 ses_page_req_t spd_req;
63 } ses_pagedesc_t;
65 typedef struct ses_plugin_config {
66 ses_pagedesc_t *spc_pages;
67 int (*spc_node_parse)(ses_plugin_t *, ses_node_t *);
68 int (*spc_node_ctl)(ses_plugin_t *, ses_node_t *,
69 const char *, nvlist_t *);
70 } ses_plugin_config_t;
72 extern int ses_plugin_register(ses_plugin_t *, int, ses_plugin_config_t *);
74 extern void *ses_plugin_page_lookup(ses_plugin_t *, ses_snap_t *, int,
75 ses_node_t *, size_t *);
77 extern void *ses_plugin_ctlpage_lookup(ses_plugin_t *, ses_snap_t *, int,
78 size_t, ses_node_t *, boolean_t);
80 extern void ses_plugin_setspecific(ses_plugin_t *, void *);
81 extern void *ses_plugin_getspecific(ses_plugin_t *);
84 * The following are support functions provided by libses.
87 extern int ses_assert(const char *, const char *, int);
89 #define VERIFY(x) ((void)((x) || ses_assert(#x, __FILE__, __LINE__)))
91 #ifdef DEBUG
92 #define ASSERT(x) VERIFY(x)
93 #else
94 #define ASSERT(x)
95 #endif
97 #define SES_NV_ADD(_t, _e, _l, _n, ...) \
98 if (((_e) = nvlist_add_##_t((_l), (_n), __VA_ARGS__)) != 0) \
99 return (ses_set_nverrno((_e), (_n)))
101 #define SES_NV_ADD_OR_FREE(_t, _e, _l, _n, ...) \
102 if (((_e) = nvlist_add_##_t((_l), (_n), __VA_ARGS__)) != 0) { \
103 nvlist_free(_l); return (ses_set_nverrno((_e), (_n))); }
105 #define SES_NV_ADD_FS(_e, _l, _name, _buf) \
106 SES_NV_ADD(fixed_string, (_e), (_l), (_name), (_buf), sizeof (_buf))
108 #define SES_NV_ADD_FS_TRUNC(_e, _l, _name, _buf) \
109 SES_NV_ADD(fixed_string_trunc, (_e), (_l), (_name), (_buf), \
110 sizeof (_buf))
112 #define SES_NV_CTLBOOL(_l, _n, _b) \
114 boolean_t v = B_FALSE; \
115 (void) nvlist_lookup_boolean_value((_l), (_n), &v); \
116 (_b) = v; \
119 #define SES_NV_CTLBOOL_INVERT(_l, _n, _b) \
121 boolean_t v = B_FALSE; \
122 (void) nvlist_lookup_boolean_value((_l), (_n), &v); \
123 (_b) = !v; \
126 #define SES_NV_CTL64(_l, _n, _v) \
128 uint64_t v = 0; \
129 (void) nvlist_lookup_uint64((_l), (_n), &v); \
130 (_v) = v; \
133 #define SES_NV_CTL16(_l, _n, _v) \
135 uint16_t v = 0; \
136 (void) nvlist_lookup_uint16((_l), (_n), &v); \
137 SCSI_WRITE16(&(_v), v); \
140 extern void *ses_alloc(size_t);
141 extern void *ses_zalloc(size_t);
142 extern char *ses_strdup(const char *);
143 extern void *ses_realloc(void *, size_t);
144 extern void ses_free(void *);
146 extern int ses_set_errno(ses_errno_t);
147 extern int ses_set_nverrno(int, const char *);
148 extern int ses_error(ses_errno_t, const char *, ...);
149 extern int ses_nverror(int, const char *, const char *, ...);
150 extern void ses_panic(const char *, ...) __NORETURN;
152 extern int nvlist_add_fixed_string(nvlist_t *, const char *,
153 const char *, size_t);
154 extern int nvlist_add_fixed_string_trunc(nvlist_t *, const char *,
155 const char *, size_t);
157 #define SES_WITHIN_PAGE(sp, size, data, len) \
158 ((char *)(sp) <= (char *)(data) + (len) - (size))
159 #define SES_WITHIN_PAGE_STRUCT(sp, data, len) \
160 SES_WITHIN_PAGE((sp), sizeof (*(sp)), (data), (len))
162 #ifdef __cplusplus
164 #endif
166 #endif /* _LIBSES_PLUGIN_H */