mfiutil.h revision 223345
1241600Sgonzo/*-
2241600Sgonzo * Copyright (c) 2008, 2009 Yahoo!, Inc.
3241600Sgonzo * All rights reserved.
4241600Sgonzo *
5241600Sgonzo * Redistribution and use in source and binary forms, with or without
6241600Sgonzo * modification, are permitted provided that the following conditions
7241600Sgonzo * are met:
8241600Sgonzo * 1. Redistributions of source code must retain the above copyright
9241600Sgonzo *    notice, this list of conditions and the following disclaimer.
10241600Sgonzo * 2. Redistributions in binary form must reproduce the above copyright
11241600Sgonzo *    notice, this list of conditions and the following disclaimer in the
12241600Sgonzo *    documentation and/or other materials provided with the distribution.
13241600Sgonzo * 3. The names of the authors may not be used to endorse or promote
14241600Sgonzo *    products derived from this software without specific prior written
15241600Sgonzo *    permission.
16241600Sgonzo *
17241600Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18241600Sgonzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19241600Sgonzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20241600Sgonzo * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21241600Sgonzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22241600Sgonzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23241600Sgonzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24241600Sgonzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25241600Sgonzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26241600Sgonzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27241600Sgonzo * SUCH DAMAGE.
28241600Sgonzo *
29241600Sgonzo * $FreeBSD: head/usr.sbin/mfiutil/mfiutil.h 223345 2011-06-20 21:28:50Z bz $
30241600Sgonzo */
31241600Sgonzo
32241600Sgonzo#ifndef __MFIUTIL_H__
33241600Sgonzo#define	__MFIUTIL_H__
34241600Sgonzo
35241600Sgonzo#include <sys/cdefs.h>
36241600Sgonzo#include <sys/linker_set.h>
37241600Sgonzo
38241600Sgonzo#include <dev/mfi/mfireg.h>
39241600Sgonzo
40241600Sgonzo/* 4.x compat */
41241600Sgonzo#ifndef SET_DECLARE
42241600Sgonzo
43241600Sgonzo/* <sys/cdefs.h> */
44241600Sgonzo#define	__used
45241600Sgonzo#define	__section(x)	__attribute__((__section__(x)))
46241600Sgonzo
47241600Sgonzo/* <sys/linker_set.h> */
48241600Sgonzo#undef __MAKE_SET
49318197Smarius#undef DATA_SET
50318197Smarius
51241600Sgonzo#define __MAKE_SET(set, sym)						\
52241600Sgonzo	static void const * const __set_##set##_sym_##sym 		\
53241600Sgonzo	__section("set_" #set) __used = &sym
54241600Sgonzo
55241600Sgonzo#define DATA_SET(set, sym)	__MAKE_SET(set, sym)
56241600Sgonzo
57318197Smarius#define SET_DECLARE(set, ptype)						\
58318197Smarius	extern ptype *__CONCAT(__start_set_,set);			\
59318197Smarius	extern ptype *__CONCAT(__stop_set_,set)
60241600Sgonzo
61318197Smarius#define SET_BEGIN(set)							\
62318197Smarius	(&__CONCAT(__start_set_,set))
63318197Smarius#define SET_LIMIT(set)							\
64241600Sgonzo	(&__CONCAT(__stop_set_,set))
65241600Sgonzo
66241600Sgonzo#define	SET_FOREACH(pvar, set)						\
67241600Sgonzo	for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++)
68241600Sgonzo
69241600Sgonzoint	humanize_number(char *_buf, size_t _len, int64_t _number,
70312399Smarius	    const char *_suffix, int _scale, int _flags);
71241600Sgonzo
72241600Sgonzo/* humanize_number(3) */
73241600Sgonzo#define HN_DECIMAL		0x01
74241600Sgonzo#define HN_NOSPACE		0x02
75241600Sgonzo#define HN_B			0x04
76241600Sgonzo#define HN_DIVISOR_1000		0x08
77270885Smarius
78241600Sgonzo#define HN_GETSCALE		0x10
79241600Sgonzo#define HN_AUTOSCALE		0x20
80318197Smarius
81241600Sgonzo#endif
82318197Smarius
83276469Smarius/* Constants for DDF RAID levels. */
84276469Smarius#define	DDF_RAID0		0x00
85318197Smarius#define	DDF_RAID1		0x01
86241600Sgonzo#define	DDF_RAID3		0x03
87318197Smarius#define	DDF_RAID5		0x05
88241600Sgonzo#define	DDF_RAID6		0x06
89318197Smarius#define	DDF_RAID1E		0x11
90241600Sgonzo#define	DDF_JBOD		0x0f
91318197Smarius#define	DDF_CONCAT		0x1f
92241600Sgonzo#define	DDF_RAID5E		0x15
93318197Smarius#define	DDF_RAID5EE		0x25
94241600Sgonzo
95241600Sgonzostruct mfiutil_command {
96318197Smarius	const char *name;
97241600Sgonzo	int (*handler)(int ac, char **av);
98241600Sgonzo};
99318197Smarius
100241600Sgonzo#define	MFI_DATASET(name)	mfiutil_ ## name ## _table
101318197Smarius
102241600Sgonzo#define	MFI_COMMAND(set, name, function)				\
103241600Sgonzo	static struct mfiutil_command function ## _mfiutil_command =	\
104289359Sadrian	{ #name, function };						\
105289359Sadrian	DATA_SET(MFI_DATASET(set), function ## _mfiutil_command)
106312399Smarius
107312399Smarius#define	MFI_TABLE(set, name)						\
108318197Smarius	SET_DECLARE(MFI_DATASET(name), struct mfiutil_command);		\
109318494Smarius									\
110318494Smarius	static int							\
111318494Smarius	mfiutil_ ## name ## _table_handler(int ac, char **av)		\
112318494Smarius	{								\
113318197Smarius		return (mfi_table_handler(SET_BEGIN(MFI_DATASET(name)), \
114318494Smarius		    SET_LIMIT(MFI_DATASET(name)), ac, av));		\
115318494Smarius	}								\
116312399Smarius	MFI_COMMAND(set, name, mfiutil_ ## name ## _table_handler)
117312399Smarius
118318197Smarius/* Drive name printing options */
119318494Smarius#define	MFI_DNAME_ES		0x0001	/* E%u:S%u */
120318494Smarius#define	MFI_DNAME_DEVICE_ID	0x0002	/* %u */
121318494Smarius#define	MFI_DNAME_HONOR_OPTS	0x8000	/* Allow cmd line to override default */
122318494Smarius
123312399Smariusextern int mfi_unit;
124312399Smariusextern u_int mfi_opts;
125312399Smarius
126318197Smariusvoid	mbox_store_ldref(uint8_t *mbox, union mfi_ld_ref *ref);
127318494Smariusvoid	mbox_store_pdref(uint8_t *mbox, union mfi_pd_ref *ref);
128318494Smariusvoid	mfi_display_progress(const char *label, struct mfi_progress *prog);
129318494Smariusint	mfi_table_handler(struct mfiutil_command **start,
130318494Smarius    struct mfiutil_command **end, int ac, char **av);
131318197Smariusconst char *mfi_raid_level(uint8_t primary_level, uint8_t secondary_level);
132318494Smariusconst char *mfi_ldstate(enum mfi_ld_state state);
133318494Smariusconst char *mfi_pdstate(enum mfi_pd_state state);
134318197Smariusconst char *mfi_pd_inq_string(struct mfi_pd_info *info);
135318496Smariusconst char *mfi_volume_name(int fd, uint8_t target_id);
136318494Smariusint	mfi_volume_busy(int fd, uint8_t target_id);
137318494Smariusint	mfi_config_read(int fd, struct mfi_config_data **configp);
138312399Smariusint	mfi_lookup_drive(int fd, char *drive, uint16_t *device_id);
139318496Smariusint	mfi_lookup_volume(int fd, const char *name, uint8_t *target_id);
140312399Smariusint	mfi_dcmd_command(int fd, uint32_t opcode, void *buf, size_t bufsize,
141318197Smarius    uint8_t *mbox, size_t mboxlen, uint8_t *statusp);
142318494Smariusint	mfi_open(int unit);
143318494Smariusint	mfi_ctrl_get_info(int fd, struct mfi_ctrl_info *info, uint8_t *statusp);
144318494Smariusint	mfi_ld_get_info(int fd, uint8_t target_id, struct mfi_ld_info *info,
145318494Smarius    uint8_t *statusp);
146241600Sgonzoint	mfi_ld_get_list(int fd, struct mfi_ld_list *list, uint8_t *statusp);
147241600Sgonzoint	mfi_pd_get_info(int fd, uint16_t device_id, struct mfi_pd_info *info,
148241600Sgonzo    uint8_t *statusp);
149241600Sgonzoint	mfi_pd_get_list(int fd, struct mfi_pd_list **listp, uint8_t *statusp);
150241600Sgonzoint	mfi_reconfig_supported(void);
151241600Sgonzoconst char *mfi_status(u_int status_code);
152241600Sgonzoconst char *mfi_drive_name(struct mfi_pd_info *pinfo, uint16_t device_id,
153318197Smarius    uint32_t def);
154241600Sgonzo
155241600Sgonzo#endif /* !__MFIUTIL_H__ */
156241600Sgonzo