rf_compat80.c revision 1.10 1 /* $NetBSD: rf_compat80.c,v 1.10 2019/02/05 19:42:31 christos Exp $ */
2
3 /*
4 * Copyright (c) 2017 Matthew R. Green
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 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * 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
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/module.h>
35
36 #include <sys/compat_stub.h>
37
38 #include <dev/raidframe/raidframeio.h>
39 #include <dev/raidframe/raidframevar.h>
40
41 #include "rf_raid.h"
42 #include "rf_compat80.h"
43 #include "rf_compat80_mod.h"
44 #include "rf_kintf.h"
45
46 int
47 rf_check_recon_status_ext80(RF_Raid_t *raidPtr, void *data)
48 {
49 RF_ProgressInfo_t info, **infoPtr = data;
50
51 rf_check_recon_status_ext(raidPtr, &info);
52 return copyout(&info, *infoPtr, sizeof info);
53 }
54
55 int
56 rf_check_parityrewrite_status_ext80(RF_Raid_t *raidPtr, void *data)
57 {
58 RF_ProgressInfo_t info, **infoPtr = data;
59
60 rf_check_parityrewrite_status_ext(raidPtr, &info);
61 return copyout(&info, *infoPtr, sizeof info);
62 }
63
64 int
65 rf_check_copyback_status_ext80(RF_Raid_t *raidPtr, void *data)
66 {
67 RF_ProgressInfo_t info, **infoPtr = data;
68
69 rf_check_copyback_status_ext(raidPtr, &info);
70 return copyout(&info, *infoPtr, sizeof info);
71 }
72
73 static void
74 rf_copy_raiddisk80(RF_RaidDisk_t *disk, RF_RaidDisk_t80 *disk80)
75 {
76
77 /* Be sure the padding areas don't have kernel memory. */
78 memset(disk80, 0, sizeof *disk80);
79 memcpy(disk80->devname, disk->devname, sizeof(disk80->devname));
80 disk80->status = disk->status;
81 disk80->spareRow = 0;
82 disk80->spareCol = disk->spareCol;
83 disk80->numBlocks = disk->numBlocks;
84 disk80->blockSize = disk->blockSize;
85 disk80->partitionSize = disk->partitionSize;
86 disk80->auto_configured = disk->auto_configured;
87 disk80->dev = disk->dev;
88 }
89
90 int
91 rf_get_info80(RF_Raid_t *raidPtr, void *data)
92 {
93 RF_DeviceConfig_t *config;
94 RF_DeviceConfig_t80 *config80, **configPtr80 = data;
95 int rv;
96
97 RF_Malloc(config, sizeof *config, (RF_DeviceConfig_t *));
98 if (config == NULL)
99 return (ENOMEM);
100 RF_Malloc(config80, sizeof *config80, (RF_DeviceConfig_t80 *));
101 if (config80 == NULL) {
102 RF_Free(config, sizeof(RF_DeviceConfig_t))
103 return (ENOMEM);
104 }
105 rv = rf_get_info(raidPtr, config);
106 if (rv == 0) {
107 /* convert new to old */
108 config80->rows = 1;
109 config80->cols = config->cols;
110 config80->maxqdepth = config->maxqdepth;
111 config80->ndevs = config->ndevs;
112 config80->nspares = config->nspares;
113 for (size_t i = 0; i < RF_MAX_DISKS; i++) {
114 rf_copy_raiddisk80(&config->devs[i],
115 &config80->devs[i]);
116 rf_copy_raiddisk80(&config->spares[i],
117 &config80->spares[i]);
118 }
119 rv = copyout(config80, *configPtr80, sizeof *config80);
120 }
121 RF_Free(config, sizeof(RF_DeviceConfig_t));
122 RF_Free(config80, sizeof(RF_DeviceConfig_t80));
123
124 return rv;
125 }
126
127 int
128 rf_get_component_label80(RF_Raid_t *raidPtr, void *data)
129 {
130 RF_ComponentLabel_t **clabel_ptr = (RF_ComponentLabel_t **)data;
131 RF_ComponentLabel_t *clabel;
132 int retcode;
133
134 /*
135 * Perhaps there should be an option to skip the in-core
136 * copy and hit the disk, as with disklabel(8).
137 */
138 RF_Malloc(clabel, sizeof(*clabel), (RF_ComponentLabel_t *));
139 if (clabel == NULL)
140 return ENOMEM;
141 retcode = copyin(*clabel_ptr, clabel, sizeof(*clabel));
142 if (retcode) {
143 RF_Free(clabel, sizeof(*clabel));
144 return retcode;
145 }
146
147 rf_get_component_label(raidPtr, clabel);
148 retcode = copyout(clabel, *clabel_ptr, sizeof(**clabel_ptr));
149 RF_Free(clabel, sizeof(*clabel));
150
151 return retcode;
152 }
153
154 int
155 rf_config80(RF_Raid_t *raidPtr, int unit, void *data, RF_Config_t **k_cfgp)
156 {
157 RF_Config_t80 *u80_cfg, *k80_cfg;
158 RF_Config_t *k_cfg;
159 size_t i, j;
160 int error;
161
162 if (raidPtr->valid) {
163 /* There is a valid RAID set running on this unit! */
164 printf("raid%d: Device already configured!\n", unit);
165 return EINVAL;
166 }
167
168 /* copy-in the configuration information */
169 /* data points to a pointer to the configuration structure */
170
171 u80_cfg = *((RF_Config_t80 **) data);
172 RF_Malloc(k80_cfg, sizeof(RF_Config_t80), (RF_Config_t80 *));
173 if (k80_cfg == NULL)
174 return ENOMEM;
175
176 error = copyin(u80_cfg, k80_cfg, sizeof(RF_Config_t80));
177 if (error) {
178 RF_Free(k80_cfg, sizeof(RF_Config_t80));
179 return error;
180 }
181 RF_Malloc(k_cfg, sizeof(RF_Config_t), (RF_Config_t *));
182 if (k_cfg == NULL) {
183 RF_Free(k80_cfg, sizeof(RF_Config_t80));
184 return ENOMEM;
185 }
186
187 k_cfg->numCol = k80_cfg->numCol;
188 k_cfg->numSpare = k80_cfg->numSpare;
189
190 for (i = 0; i < RF_MAXROW; i++)
191 for (j = 0; j < RF_MAXCOL; j++)
192 k_cfg->devs[i][j] = k80_cfg->devs[i][j];
193
194 memcpy(k_cfg->devnames, k80_cfg->devnames,
195 sizeof(k_cfg->devnames));
196
197 for (i = 0; i < RF_MAXSPARE; i++)
198 k_cfg->spare_devs[i] = k80_cfg->spare_devs[i];
199
200 memcpy(k_cfg->spare_names, k80_cfg->spare_names,
201 sizeof(k_cfg->spare_names));
202
203 k_cfg->sectPerSU = k80_cfg->sectPerSU;
204 k_cfg->SUsPerPU = k80_cfg->SUsPerPU;
205 k_cfg->SUsPerRU = k80_cfg->SUsPerRU;
206 k_cfg->parityConfig = k80_cfg->parityConfig;
207
208 memcpy(k_cfg->diskQueueType, k80_cfg->diskQueueType,
209 sizeof(k_cfg->diskQueueType));
210
211 k_cfg->maxOutstandingDiskReqs = k80_cfg->maxOutstandingDiskReqs;
212
213 memcpy(k_cfg->debugVars, k80_cfg->debugVars,
214 sizeof(k_cfg->debugVars));
215
216 k_cfg->layoutSpecificSize = k80_cfg->layoutSpecificSize;
217 k_cfg->layoutSpecific = k80_cfg->layoutSpecific;
218 k_cfg->force = k80_cfg->force;
219
220 RF_Free(k80_cfg, sizeof(RF_Config_t80));
221 *k_cfgp = k_cfg;
222 return 0;
223 }
224
225 static int
226 rf_fail_disk80(RF_Raid_t *raidPtr, struct rf_recon_req80 *req80)
227 {
228 struct rf_recon_req req = {
229 .col = req80->col,
230 .flags = req80->flags,
231 };
232 return rf_fail_disk(raidPtr, &req);
233 }
234
235 int
236 raidframe_ioctl_80(u_long cmd, int initted, RF_Raid_t *raidPtr, int unit,
237 void *data, RF_Config_t **k_cfg)
238 {
239 int error;
240
241 switch (cmd) {
242 case RAIDFRAME_CHECK_RECON_STATUS_EXT80:
243 case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT80:
244 case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT80:
245 case RAIDFRAME_GET_INFO80:
246 case RAIDFRAME_GET_COMPONENT_LABEL80:
247 if (initted == 0)
248 return ENXIO;
249 break;
250 case RAIDFRAME_CONFIGURE80:
251 case RAIDFRAME_FAIL_DISK80:
252 break;
253 default:
254 return EPASSTHROUGH;
255 }
256
257 switch (cmd) {
258 case RAIDFRAME_CHECK_RECON_STATUS_EXT80:
259 return rf_check_recon_status_ext80(raidPtr, data);
260 case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT80:
261 return rf_check_parityrewrite_status_ext80(raidPtr, data);
262 case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT80:
263 return rf_check_copyback_status_ext80(raidPtr, data);
264 case RAIDFRAME_GET_INFO80:
265 return rf_get_info80(raidPtr, data);
266 case RAIDFRAME_GET_COMPONENT_LABEL80:
267 return rf_get_component_label80(raidPtr, data);
268 case RAIDFRAME_CONFIGURE80:
269 error = rf_config80(raidPtr, unit, data, k_cfg);
270 if (error != 0)
271 return error;
272 return EAGAIN; /* flag mainline to call generic config */
273 case RAIDFRAME_FAIL_DISK80:
274 return rf_fail_disk80(raidPtr, data);
275 default:
276 /* abort really */
277 return EPASSTHROUGH;
278 }
279 }
280
281 static void
282 raidframe_80_init(void)
283 {
284
285 MODULE_SET_HOOK(raidframe_ioctl_80_hook, "raid80", raidframe_ioctl_80);
286 }
287
288 static void
289 raidframe_80_fini(void)
290 {
291
292 MODULE_UNSET_HOOK(raidframe_ioctl_80_hook);
293 }
294
295 MODULE(MODULE_CLASS_EXEC, compat_raid_80, "raid,compat_80");
296
297 static int
298 compat_raid_80_modcmd(modcmd_t cmd, void *arg)
299 {
300
301 switch (cmd) {
302 case MODULE_CMD_INIT:
303 raidframe_80_init();
304 return 0;
305 case MODULE_CMD_FINI:
306 raidframe_80_fini();
307 return 0;
308 default:
309 return ENOTTY;
310 }
311 }
312