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