]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - usr.sbin/mptutil/mptutil.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / usr.sbin / mptutil / mptutil.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 __MPTUTIL_H__
34 #define __MPTUTIL_H__
35
36 #include <sys/cdefs.h>
37 #include <sys/linker_set.h>
38
39 #include <dev/mpt/mpilib/mpi_type.h>
40 #include <dev/mpt/mpilib/mpi.h>
41 #include <dev/mpt/mpilib/mpi_cnfg.h>
42 #include <dev/mpt/mpilib/mpi_raid.h>
43
44 #define IOC_STATUS_SUCCESS(status)                                      \
45         (((status) & MPI_IOCSTATUS_MASK) == MPI_IOCSTATUS_SUCCESS)
46
47 struct mpt_query_disk {
48         char    devname[SPECNAMELEN + 1];
49 };
50
51 struct mpt_standalone_disk {
52         uint64_t maxlba;
53         char    inqstring[64];
54         char    devname[SPECNAMELEN + 1];
55         u_int   bus;
56         u_int   target;
57 };
58
59 struct mpt_drive_list {
60         int     ndrives;
61         CONFIG_PAGE_RAID_PHYS_DISK_0 *drives[0];
62 };
63
64 struct mptutil_command {
65         const char *name;
66         int (*handler)(int ac, char **av);
67 };
68
69 #define MPT_DATASET(name)       mptutil_ ## name ## _table
70
71 #define MPT_COMMAND(set, name, function)                                \
72         static struct mptutil_command function ## _mptutil_command =    \
73         { #name, function };                                            \
74         DATA_SET(MPT_DATASET(set), function ## _mptutil_command)
75
76 #define MPT_TABLE(set, name)                                            \
77         SET_DECLARE(MPT_DATASET(name), struct mptutil_command);         \
78                                                                         \
79         static int                                                      \
80         mptutil_ ## name ## _table_handler(int ac, char **av)           \
81         {                                                               \
82                 return (mpt_table_handler(SET_BEGIN(MPT_DATASET(name)), \
83                     SET_LIMIT(MPT_DATASET(name)), ac, av));             \
84         }                                                               \
85         MPT_COMMAND(set, name, mptutil_ ## name ## _table_handler)
86
87 extern int mpt_unit;
88
89 #ifdef DEBUG
90 void    hexdump(const void *ptr, int length, const char *hdr, int flags);
91 #define HD_COLUMN_MASK  0xff
92 #define HD_DELIM_MASK   0xff00
93 #define HD_OMIT_COUNT   (1 << 16)
94 #define HD_OMIT_HEX     (1 << 17)
95 #define HD_OMIT_CHARS   (1 << 18)
96 #endif
97
98 int     mpt_table_handler(struct mptutil_command **start,
99     struct mptutil_command **end, int ac, char **av);
100 int     mpt_read_config_page_header(int fd, U8 PageType, U8 PageNumber,
101     U32 PageAddress, CONFIG_PAGE_HEADER *header, U16 *IOCStatus);
102 void    *mpt_read_config_page(int fd, U8 PageType, U8 PageNumber,
103     U32 PageAddress, U16 *IOCStatus);
104 void    *mpt_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion,
105     U8 PageNumber, U32 PageAddress, U16 *IOCStatus);
106 int     mpt_write_config_page(int fd, void *buf, U16 *IOCStatus);
107 const char *mpt_ioc_status(U16 IOCStatus);
108 int     mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID,
109     U8 PhysDiskNum, U32 ActionDataWord, void *buf, int len,
110     RAID_VOL0_STATUS *VolumeStatus, U32 *ActionData, int datalen,
111     U16 *IOCStatus, U16 *ActionStatus, int write);
112 const char *mpt_raid_status(U16 ActionStatus);
113 int     mpt_open(int unit);
114 const char *mpt_raid_level(U8 VolumeType);
115 const char *mpt_volstate(U8 State);
116 const char *mpt_pdstate(CONFIG_PAGE_RAID_PHYS_DISK_0 *info);
117 const char *mpt_pd_inq_string(CONFIG_PAGE_RAID_PHYS_DISK_0 *pd_info);
118 struct mpt_drive_list *mpt_pd_list(int fd);
119 void    mpt_free_pd_list(struct mpt_drive_list *list);
120 int     mpt_query_disk(U8 VolumeBus, U8 VolumeID, struct mpt_query_disk *qd);
121 const char *mpt_volume_name(U8 VolumeBus, U8 VolumeID);
122 int     mpt_fetch_disks(int fd, int *ndisks,
123     struct mpt_standalone_disk **disksp);
124 int     mpt_lock_volume(U8 VolumeBus, U8 VolumeID);
125 int     mpt_lookup_drive(struct mpt_drive_list *list, const char *drive,
126     U8 *PhysDiskNum);
127 int     mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus,
128     U8 *VolumeID);
129 int     mpt_rescan_bus(int bus, int id);
130
131 static __inline void *
132 mpt_read_man_page(int fd, U8 PageNumber, U16 *IOCStatus)
133 {
134
135         return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_MANUFACTURING,
136             PageNumber, 0, IOCStatus));
137 }
138
139 static __inline void *
140 mpt_read_ioc_page(int fd, U8 PageNumber, U16 *IOCStatus)
141 {
142
143         return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_IOC, PageNumber,
144             0, IOCStatus));
145 }
146
147 static __inline U32
148 mpt_vol_pageaddr(U8 VolumeBus, U8 VolumeID)
149 {
150
151         return (VolumeBus << 8 | VolumeID);
152 }
153
154 static __inline CONFIG_PAGE_RAID_VOL_0 *
155 mpt_vol_info(int fd, U8 VolumeBus, U8 VolumeID, U16 *IOCStatus)
156 {
157
158         return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME, 0,
159             mpt_vol_pageaddr(VolumeBus, VolumeID), IOCStatus));
160 }
161
162 static __inline CONFIG_PAGE_RAID_VOL_1 *
163 mpt_vol_names(int fd, U8 VolumeBus, U8 VolumeID, U16 *IOCStatus)
164 {
165
166         return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME, 1,
167             mpt_vol_pageaddr(VolumeBus, VolumeID), IOCStatus));
168 }
169
170 static __inline CONFIG_PAGE_RAID_PHYS_DISK_0 *
171 mpt_pd_info(int fd, U8 PhysDiskNum, U16 *IOCStatus)
172 {
173
174         return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK, 0,
175             PhysDiskNum, IOCStatus));
176 }
177
178 #endif /* !__MPTUTIL_H__ */