]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - usr.sbin/mpsutil/mpsutil.h
MFC r322124:
[FreeBSD/stable/10.git] / usr.sbin / mpsutil / mpsutil.h
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 #include <stdbool.h>
39
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>
45
46 #define MPSUTIL_VERSION "1.0.0"
47
48 #define IOC_STATUS_SUCCESS(status)                                      \
49         (((status) & MPI2_IOCSTATUS_MASK) == MPI2_IOCSTATUS_SUCCESS)
50
51 struct mpsutil_command {
52         const char *name;
53         int (*handler)(int ac, char **av);
54 };
55 struct mpsutil_usage {
56         const char *set;
57         const char *name;
58         void (*handler)(const char **, const char**);
59 };
60
61 #define MPS_DATASET(name)       mpsutil_ ## name ## _table
62
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);       \
67         static void                                                     \
68         function ## _usage(const char **a3, const char **a4)            \
69         {                                                               \
70                 *a3 = args;                                             \
71                 *a4 = desc;                                             \
72                 return;                                                 \
73         };                                                              \
74         static struct mpsutil_usage function ## _mpsutil_usage =        \
75         { #set, #name, function ## _usage };                            \
76         DATA_SET(MPS_DATASET(usage), function ## _mpsutil_usage);
77
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);
82
83 #define MPS_TABLE(set, name)                                            \
84         SET_DECLARE(MPS_DATASET(name), struct mpsutil_command);         \
85                                                                         \
86         static int                                                      \
87         mpsutil_ ## name ## _table_handler(int ac, char **av)           \
88         {                                                               \
89                 return (mps_table_handler(SET_BEGIN(MPS_DATASET(name)), \
90                     SET_LIMIT(MPS_DATASET(name)), ac, av));             \
91         }                                                               \
92         _MPS_COMMAND(set, name, mpsutil_ ## name ## _table_handler)
93
94 extern int mps_unit;
95 extern int is_mps;
96 #define MPS_MAX_UNIT 10
97
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)
105
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,
124     uint16_t *target);
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);
128
129 static __inline void *
130 mps_read_man_page(int fd, U8 PageNumber, U16 *IOCStatus)
131 {
132
133         return (mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_MANUFACTURING,
134             PageNumber, 0, IOCStatus));
135 }
136
137 static __inline void *
138 mps_read_ioc_page(int fd, U8 PageNumber, U16 *IOCStatus)
139 {
140
141         return (mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IOC, PageNumber,
142             0, IOCStatus));
143 }
144
145 MPI2_IOC_FACTS_REPLY * mps_get_iocfacts(int fd);
146
147 #endif /* !__MPSUTIL_H__ */