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