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