2 * Copyright (c) 2008 Yahoo!, Inc.
4 * Written by: John Baldwin <jhb@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
36 #include <sys/cdefs.h>
37 #include <sys/linker_set.h>
40 #include <dev/mps/mpi/mpi2_type.h>
41 #include <dev/mps/mpi/mpi2.h>
42 #include <dev/mps/mpi/mpi2_cnfg.h>
43 #include <dev/mps/mpi/mpi2_raid.h>
44 #include <dev/mps/mpi/mpi2_ioc.h>
46 #define MPSUTIL_VERSION "1.0.0"
48 #define IOC_STATUS_SUCCESS(status) \
49 (((status) & MPI2_IOCSTATUS_MASK) == MPI2_IOCSTATUS_SUCCESS)
51 struct mpsutil_command {
53 int (*handler)(int ac, char **av);
55 struct mpsutil_usage {
58 void (*handler)(const char **, const char**);
61 #define MPS_DATASET(name) mpsutil_ ## name ## _table
63 #define MPS_COMMAND(set, name, function, args, desc) \
64 static struct mpsutil_command function ## _mpsutil_command = \
65 { #name, function }; \
66 DATA_SET(MPS_DATASET(set), function ## _mpsutil_command); \
68 function ## _usage(const char **a3, const char **a4) \
74 static struct mpsutil_usage function ## _mpsutil_usage = \
75 { #set, #name, function ## _usage }; \
76 DATA_SET(MPS_DATASET(usage), function ## _mpsutil_usage);
78 #define _MPS_COMMAND(set, name, function) \
79 static struct mpsutil_command function ## _mpsutil_command = \
80 { #name, function }; \
81 DATA_SET(MPS_DATASET(set), function ## _mpsutil_command);
83 #define MPS_TABLE(set, name) \
84 SET_DECLARE(MPS_DATASET(name), struct mpsutil_command); \
87 mpsutil_ ## name ## _table_handler(int ac, char **av) \
89 return (mps_table_handler(SET_BEGIN(MPS_DATASET(name)), \
90 SET_LIMIT(MPS_DATASET(name)), ac, av)); \
92 _MPS_COMMAND(set, name, mpsutil_ ## name ## _table_handler)
96 #define MPS_MAX_UNIT 10
98 void hexdump(const void *ptr, int length, const char *hdr, int flags);
99 #define HD_COLUMN_MASK 0xff
100 #define HD_DELIM_MASK 0xff00
101 #define HD_OMIT_COUNT (1 << 16)
102 #define HD_OMIT_HEX (1 << 17)
103 #define HD_OMIT_CHARS (1 << 18)
104 #define HD_REVERSED (1 << 19)
106 int mps_open(int unit);
107 int mps_table_handler(struct mpsutil_command **start,
108 struct mpsutil_command **end, int ac, char **av);
109 int mps_user_command(int fd, void *req, uint32_t req_len, void *reply,
110 uint32_t reply_len, void *buffer, int len, uint32_t flags);
111 int mps_pass_command(int fd, void *req, uint32_t req_len, void *reply,
112 uint32_t reply_len, void *data_in, uint32_t datain_len, void *data_out,
113 uint32_t dataout_len, uint32_t timeout);
114 int mps_read_config_page_header(int fd, U8 PageType, U8 PageNumber,
115 U32 PageAddress, MPI2_CONFIG_PAGE_HEADER *header, U16 *IOCStatus);
116 int mps_read_ext_config_page_header(int fd, U8 ExtPageType, U8 PageNumber,
117 U32 PageAddress, MPI2_CONFIG_PAGE_HEADER *header,
118 U16 *ExtPageLen, U16 *IOCStatus);
119 void *mps_read_config_page(int fd, U8 PageType, U8 PageNumber,
120 U32 PageAddress, U16 *IOCStatus);
121 void *mps_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion,
122 U8 PageNumber, U32 PageAddress, U16 *IOCStatus);
123 int mps_map_btdh(int fd, uint16_t *devhandle, uint16_t *bus,
125 const char *mps_ioc_status(U16 IOCStatus);
126 int mps_firmware_send(int fd, unsigned char *buf, uint32_t len, bool bios);
127 int mps_firmware_get(int fd, unsigned char **buf, bool bios);
129 static __inline void *
130 mps_read_man_page(int fd, U8 PageNumber, U16 *IOCStatus)
133 return (mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_MANUFACTURING,
134 PageNumber, 0, IOCStatus));
137 static __inline void *
138 mps_read_ioc_page(int fd, U8 PageNumber, U16 *IOCStatus)
141 return (mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IOC, PageNumber,
145 MPI2_IOC_FACTS_REPLY * mps_get_iocfacts(int fd);
147 #endif /* !__MPSUTIL_H__ */