xref: /freebsd/usr.sbin/mpsutil/mpsutil.h (revision 2830819497fb2deae3dd71574592ace55f2fbdba)
1 /*-
2  * Copyright (c) 2008 Yahoo!, Inc.
3  * All rights reserved.
4  * Written by: John Baldwin <jhb@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the author nor the names of any co-contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #ifndef __MPSUTIL_H__
34 #define	__MPSUTIL_H__
35 
36 #include <sys/cdefs.h>
37 #include <sys/linker_set.h>
38 
39 #include <dev/mps/mpi/mpi2_type.h>
40 #include <dev/mps/mpi/mpi2.h>
41 #include <dev/mps/mpi/mpi2_cnfg.h>
42 #include <dev/mps/mpi/mpi2_raid.h>
43 #include <dev/mps/mpi/mpi2_ioc.h>
44 
45 #define MPSUTIL_VERSION	"1.0.0"
46 
47 #define	IOC_STATUS_SUCCESS(status)					\
48 	(((status) & MPI2_IOCSTATUS_MASK) == MPI2_IOCSTATUS_SUCCESS)
49 
50 struct mpsutil_command {
51 	const char *name;
52 	int (*handler)(int ac, char **av);
53 };
54 struct mpsutil_usage {
55 	const char *set;
56 	const char *name;
57 	void (*handler)(const char **, const char**);
58 };
59 
60 #define	MPS_DATASET(name)	mpsutil_ ## name ## _table
61 
62 #define	MPS_COMMAND(set, name, function, args, desc)			\
63 	static struct mpsutil_command function ## _mpsutil_command =	\
64 	{ #name, function };						\
65 	DATA_SET(MPS_DATASET(set), function ## _mpsutil_command);	\
66 	static void							\
67 	function ## _usage(const char **a3, const char **a4)		\
68 	{								\
69 		*a3 = args;						\
70 		*a4 = desc;						\
71 		return;							\
72 	};								\
73 	static struct mpsutil_usage function ## _mpsutil_usage =	\
74 	{ #set, #name, function ## _usage };				\
75 	DATA_SET(MPS_DATASET(usage), function ## _mpsutil_usage);
76 
77 #define	_MPS_COMMAND(set, name, function)				\
78 	static struct mpsutil_command function ## _mpsutil_command =	\
79 	{ #name, function };						\
80 	DATA_SET(MPS_DATASET(set), function ## _mpsutil_command);
81 
82 #define	MPS_TABLE(set, name)						\
83 	SET_DECLARE(MPS_DATASET(name), struct mpsutil_command);		\
84 									\
85 	static int							\
86 	mpsutil_ ## name ## _table_handler(int ac, char **av)		\
87 	{								\
88 		return (mps_table_handler(SET_BEGIN(MPS_DATASET(name)), \
89 		    SET_LIMIT(MPS_DATASET(name)), ac, av));		\
90 	}								\
91 	_MPS_COMMAND(set, name, mpsutil_ ## name ## _table_handler)
92 
93 extern int mps_unit;
94 extern int is_mps;
95 #define MPS_MAX_UNIT 10
96 
97 void	hexdump(const void *ptr, int length, const char *hdr, int flags);
98 #define	HD_COLUMN_MASK	0xff
99 #define	HD_DELIM_MASK	0xff00
100 #define	HD_OMIT_COUNT	(1 << 16)
101 #define	HD_OMIT_HEX	(1 << 17)
102 #define	HD_OMIT_CHARS	(1 << 18)
103 #define HD_REVERSED	(1 << 19)
104 
105 int	mps_open(int unit);
106 int	mps_table_handler(struct mpsutil_command **start,
107     struct mpsutil_command **end, int ac, char **av);
108 int	mps_user_command(int fd, void *req, uint32_t req_len, void *reply,
109 	uint32_t reply_len, void *buffer, int len, uint32_t flags);
110 int	mps_pass_command(int fd, void *req, uint32_t req_len, void *reply,
111 	uint32_t reply_len, void *data_in, uint32_t datain_len, void *data_out,
112 	uint32_t dataout_len, uint32_t timeout);
113 int	mps_read_config_page_header(int fd, U8 PageType, U8 PageNumber,
114     U32 PageAddress, MPI2_CONFIG_PAGE_HEADER *header, U16 *IOCStatus);
115 int	mps_read_ext_config_page_header(int fd, U8 ExtPageType, U8 PageNumber,
116     U32 PageAddress, MPI2_CONFIG_PAGE_HEADER *header,
117     U16 *ExtPageLen, U16 *IOCStatus);
118 void	*mps_read_config_page(int fd, U8 PageType, U8 PageNumber,
119     U32 PageAddress, U16 *IOCStatus);
120 void	*mps_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion,
121     U8 PageNumber, U32 PageAddress, U16 *IOCStatus);
122 int	mps_map_btdh(int fd, uint16_t *devhandle, uint16_t *bus,
123     uint16_t *target);
124 const char *mps_ioc_status(U16 IOCStatus);
125 
126 static __inline void *
127 mps_read_man_page(int fd, U8 PageNumber, U16 *IOCStatus)
128 {
129 
130 	return (mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_MANUFACTURING,
131 	    PageNumber, 0, IOCStatus));
132 }
133 
134 static __inline void *
135 mps_read_ioc_page(int fd, U8 PageNumber, U16 *IOCStatus)
136 {
137 
138 	return (mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IOC, PageNumber,
139 	    0, IOCStatus));
140 }
141 
142 MPI2_IOC_FACTS_REPLY * mps_get_iocfacts(int fd);
143 
144 #endif /* !__MPSUTIL_H__ */
145