xref: /freebsd/sys/dev/hpt27xx/array.h (revision a0ee8cc636cd5c2374ec44ca71226564ea0bca95)
1 /*-
2  * Copyright (c) 2004-2011 HighPoint Technologies, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #include <dev/hpt27xx/hpt27xx_config.h>
30 
31 #ifndef _HPT_ARRAY_H_
32 #define _HPT_ARRAY_H_
33 
34 #define VERMAGIC_ARRAY 46
35 
36 #if defined(__cplusplus)
37 extern "C" {
38 #endif
39 
40 #define MAX_ARRAY_NAME 16
41 
42 #ifndef MAX_MEMBERS
43 #define MAX_MEMBERS    16
44 #endif
45 
46 #if MAX_MEMBERS<=16
47 typedef HPT_U16 HPT_MMASK;
48 #elif MAX_MEMBERS<=32
49 typedef HPT_U32 HPT_MMASK;
50 #elif MAX_MEMBERS<=64
51 typedef HPT_U64 HPT_MMASK;
52 #else
53 #error "MAX_MEMBERS too large"
54 #endif
55 
56 #define HPT_MMASK_VALUE(x) (HPT_MMASK)((HPT_MMASK)1<<(x))
57 
58 #if MAX_MEMBERS<32
59 #define HPT_MMASK_VALUE_SAFE(x) HPT_MMASK_VALUE(x)
60 #else
61 #define HPT_MMASK_VALUE_SAFE(x) ((x)>=MAX_MEMBERS? (HPT_MMASK)0 : HPT_MMASK_VALUE(x))
62 #endif
63 
64 #define MAX_REBUILD_SECTORS 128
65 
66 typedef struct _RAID_FLAGS {
67 	HPT_UINT rf_need_initialize : 1;
68 	HPT_UINT rf_need_rebuild: 1;
69 	HPT_UINT rf_need_sync: 1;
70 	/* ioctl flags */
71 	HPT_UINT rf_auto_rebuild: 1;
72 	HPT_UINT rf_rebuilding: 1;
73 	HPT_UINT rf_verifying: 1;
74 	HPT_UINT rf_initializing: 1;
75 	HPT_UINT rf_abort_verifying: 1;
76 	HPT_UINT rf_raid15: 1;
77 	HPT_UINT rf_v3_format : 1;
78 	HPT_UINT rf_need_transform : 1;
79 	HPT_UINT rf_transforming : 1;
80 	HPT_UINT rf_abort_transform : 1;
81 	HPT_UINT rf_log_write: 1;
82 } RAID_FLAGS;
83 
84 typedef struct transform_cmd_ext
85 {
86 	HPT_LBA lba;
87 	HPT_U16 total_sectors;
88 	HPT_U16 finished_sectors;
89 } TRANSFORM_CMD_EXT , *PTRANSFORM_CMD_EXT;
90 
91 
92 #define TO_MOVE_DATA        0
93 #define TO_INITIALIZE       1
94 #define TO_INITIALIZE_ONLY  2
95 #define TO_MOVE_DATA_ONLY   3
96 typedef struct hpt_transform
97 {
98 	HPT_U32 stamp;
99 	PVDEV source;
100 	PVDEV target;
101 	struct list_head link;
102 	HPT_U8 transform_from_tail;
103 	struct tq_item task;
104 
105 	struct lock_request lock;
106 	TRANSFORM_CMD_EXT cmdext;
107 
108 	HPT_U64 transform_point;
109 	HPT_U16 transform_sectors_per_step;
110 	HPT_U8  operation;
111 	HPT_U8  disabled;
112 } HPT_TRANSFORM, *PHPT_TRANSFORM;
113 
114 typedef struct hpt_array
115 {
116 	HPT_U32 array_stamp;
117 	HPT_U32 data_stamp;
118 	HPT_U32 array_sn;
119 
120 	HPT_U8  ndisk;
121 	HPT_U8  block_size_shift;
122 	HPT_U16 strip_width;
123 	HPT_U8  sector_size_shift; /*sector size = 512B<<sector_size_shift*/
124 	HPT_U8  jid;
125 	HPT_U8  reserved[2];
126 
127 
128 	HPT_MMASK outdated_members;
129 	HPT_MMASK offline_members;
130 
131 	PVDEV member[MAX_MEMBERS];
132 
133 	RAID_FLAGS flags;
134 
135 	HPT_U64 rebuilt_sectors;
136 
137 
138 	HPT_U8 name[MAX_ARRAY_NAME];
139 	PHPT_TRANSFORM transform;
140 
141 	TIME_RECORD create_time;
142 	HPT_U8  description[64];
143 	HPT_U8  create_manager[16];
144 
145 #ifdef OS_SUPPORT_TASK
146 	int floating_priority;
147 	OSM_TASK ioctl_task;
148 	IOCTL_ARG ioctl_arg;
149 
150 	char ioctl_inbuf[sizeof(PVDEV)+sizeof(HPT_U64)+sizeof(HPT_U16)];
151 	char ioctl_outbuf[sizeof(HPT_UINT)];
152 #endif
153 
154 } HPT_ARRAY, *PHPT_ARRAY;
155 
156 #ifdef OS_SUPPORT_TASK
157 void ldm_start_rebuild(struct _VDEV *pArray);
158 #else
159 #define ldm_start_rebuild(pArray)
160 #endif
161 
162 typedef struct _raw_partition{
163 	struct _raw_partition * next;
164 	__HPT_RAW_LBA start;
165 	__HPT_RAW_LBA capacity;
166 	PVDEV   vd_part;
167 } RAW_PARTITION, *PRAW_PARTITION;
168 
169 typedef struct hpt_partiton
170 {
171 	PVDEV raw_disk;
172 	__HPT_RAW_LBA des_location;
173 	PRAW_PARTITION raw_part;
174 	HPT_U8  del_mbr;
175 	HPT_U8  reserved[3];
176 } HPT_PARTITION, *PHPT_PARTITION;
177 
178 void ldm_check_array_online(PVDEV pArray);
179 void ldm_generic_member_failed(PVDEV member);
180 void ldm_sync_array_info(PVDEV pArray);
181 void ldm_sync_array_stamp(PVDEV pArray);
182 void ldm_add_spare_to_array(PVDEV pArray, PVDEV spare_partition);
183 
184 #if defined(__cplusplus)
185 }
186 #endif
187 #endif
188