rf_compat50.c revision 1.7 1 /* $NetBSD: rf_compat50.c,v 1.7 2019/02/03 08:02:24 pgoyette Exp $ */
2
3 /*-
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/module.h>
43
44 #include <sys/compat_stub.h>
45
46 #include <dev/raidframe/raidframeio.h>
47 #include <dev/raidframe/raidframevar.h>
48
49 #include "rf_raid.h"
50 #include "rf_compat50.h"
51 #include "rf_compat50_mod.h"
52 #include "rf_debugMem.h"
53
54 typedef struct RF_Config50_s {
55 RF_RowCol_t numRow, numCol, numSpare;
56 int32_t devs[RF_MAXROW][RF_MAXCOL];
57 char devnames[RF_MAXROW][RF_MAXCOL][50];
58 int32_t spare_devs[RF_MAXSPARE];
59 char spare_names[RF_MAXSPARE][50];
60 RF_SectorNum_t sectPerSU;
61 RF_StripeNum_t SUsPerPU;
62 RF_StripeNum_t SUsPerRU;
63 RF_ParityConfig_t parityConfig;
64 RF_DiskQueueType_t diskQueueType;
65 char maxOutstandingDiskReqs;
66 char debugVars[RF_MAXDBGV][50];
67 unsigned int layoutSpecificSize;
68 void *layoutSpecific;
69 int force;
70 } RF_Config50_t;
71
72 typedef struct RF_RaidDisk50_s {
73 char devname[56];
74 RF_DiskStatus_t status;
75 RF_RowCol_t spareRow;
76 RF_RowCol_t spareCol;
77 RF_SectorCount_t numBlocks;
78 int blockSize;
79 RF_SectorCount_t partitionSize;
80 int auto_configured;
81 int32_t dev;
82 } RF_RaidDisk50_t;
83
84 typedef struct RF_DeviceConfig50_s {
85 u_int rows;
86 u_int cols;
87 u_int maxqdepth;
88 int ndevs;
89 RF_RaidDisk50_t devs[RF_MAX_DISKS];
90 int nspares;
91 RF_RaidDisk50_t spares[RF_MAX_DISKS];
92 } RF_DeviceConfig50_t;
93
94 static void
95 rf_disk_to_disk50(RF_RaidDisk50_t *d50, const RF_RaidDisk_t *d)
96 {
97 memcpy(d50->devname, d->devname, sizeof(d50->devname));
98 d50->status = d->status;
99 d50->spareRow = 0;
100 d50->spareCol = d->spareCol;
101 d50->numBlocks = d->numBlocks;
102 d50->blockSize = d->blockSize;
103 d50->partitionSize = d->partitionSize;
104 d50->auto_configured = d->auto_configured;
105 d50->dev = d->dev;
106 }
107
108 int
109 rf_config50(RF_Raid_t *raidPtr, int unit, void *data, RF_Config_t **k_cfgp)
110 {
111 RF_Config50_t *u50_cfg, *k50_cfg;
112 RF_Config_t *k_cfg;
113 size_t i, j;
114 int error;
115
116 if (raidPtr->valid) {
117 /* There is a valid RAID set running on this unit! */
118 printf("raid%d: Device already configured!\n", unit);
119 return EINVAL;
120 }
121
122 /* copy-in the configuration information */
123 /* data points to a pointer to the configuration structure */
124
125 u50_cfg = *((RF_Config50_t **) data);
126 RF_Malloc(k50_cfg, sizeof(RF_Config50_t), (RF_Config50_t *));
127 if (k50_cfg == NULL)
128 return ENOMEM;
129
130 error = copyin(u50_cfg, k50_cfg, sizeof(RF_Config50_t));
131 if (error) {
132 RF_Free(k50_cfg, sizeof(RF_Config50_t));
133 return error;
134 }
135 RF_Malloc(k_cfg, sizeof(RF_Config_t), (RF_Config_t *));
136 if (k_cfg == NULL) {
137 RF_Free(k50_cfg, sizeof(RF_Config50_t));
138 return ENOMEM;
139 }
140
141 k_cfg->numCol = k50_cfg->numCol;
142 k_cfg->numSpare = k50_cfg->numSpare;
143
144 for (i = 0; i < RF_MAXROW; i++)
145 for (j = 0; j < RF_MAXCOL; j++)
146 k_cfg->devs[i][j] = k50_cfg->devs[i][j];
147
148 memcpy(k_cfg->devnames, k50_cfg->devnames,
149 sizeof(k_cfg->devnames));
150
151 for (i = 0; i < RF_MAXSPARE; i++)
152 k_cfg->spare_devs[i] = k50_cfg->spare_devs[i];
153
154 memcpy(k_cfg->spare_names, k50_cfg->spare_names,
155 sizeof(k_cfg->spare_names));
156
157 k_cfg->sectPerSU = k50_cfg->sectPerSU;
158 k_cfg->SUsPerPU = k50_cfg->SUsPerPU;
159 k_cfg->SUsPerRU = k50_cfg->SUsPerRU;
160 k_cfg->parityConfig = k50_cfg->parityConfig;
161
162 memcpy(k_cfg->diskQueueType, k50_cfg->diskQueueType,
163 sizeof(k_cfg->diskQueueType));
164
165 k_cfg->maxOutstandingDiskReqs = k50_cfg->maxOutstandingDiskReqs;
166
167 memcpy(k_cfg->debugVars, k50_cfg->debugVars,
168 sizeof(k_cfg->debugVars));
169
170 k_cfg->layoutSpecificSize = k50_cfg->layoutSpecificSize;
171 k_cfg->layoutSpecific = k50_cfg->layoutSpecific;
172 k_cfg->force = k50_cfg->force;
173
174 RF_Free(k50_cfg, sizeof(RF_Config50_t));
175 *k_cfgp = k_cfg;
176 return 0;
177 }
178
179 int
180 rf_get_info50(RF_Raid_t *raidPtr, void *data)
181 {
182 RF_DeviceConfig50_t **ucfgp = data, *d_cfg;
183 size_t i, j;
184 int error;
185
186 if (!raidPtr->valid)
187 return ENODEV;
188
189 RF_Malloc(d_cfg, sizeof(RF_DeviceConfig50_t), (RF_DeviceConfig50_t *));
190
191 if (d_cfg == NULL)
192 return ENOMEM;
193
194 d_cfg->rows = 1; /* there is only 1 row now */
195 d_cfg->cols = raidPtr->numCol;
196 d_cfg->ndevs = raidPtr->numCol;
197 if (d_cfg->ndevs >= RF_MAX_DISKS) {
198 error = ENOMEM;
199 goto out;
200 }
201
202 d_cfg->nspares = raidPtr->numSpare;
203 if (d_cfg->nspares >= RF_MAX_DISKS) {
204 error = ENOMEM;
205 goto out;
206 }
207
208 d_cfg->maxqdepth = raidPtr->maxQueueDepth;
209 for (j = 0; j < d_cfg->cols; j++)
210 rf_disk_to_disk50(&d_cfg->devs[j], &raidPtr->Disks[j]);
211
212 for (j = d_cfg->cols, i = 0; i < d_cfg->nspares; i++, j++)
213 rf_disk_to_disk50(&d_cfg->spares[i], &raidPtr->Disks[j]);
214
215 error = copyout(d_cfg, *ucfgp, sizeof(RF_DeviceConfig50_t));
216
217 out:
218 RF_Free(d_cfg, sizeof(RF_DeviceConfig50_t));
219 return error;
220 }
221
222 int
223 raidframe_ioctl_50(u_long cmd, int initted, RF_Raid_t *raidPtr, int unit,
224 void *data, RF_Config_t **k_cfg)
225 {
226 int error;
227
228 switch (cmd) {
229 case RAIDFRAME_GET_INFO50:
230 if (initted == 0)
231 return ENXIO;
232 return rf_get_info50(raidPtr, data);
233
234 case RAIDFRAME_CONFIGURE50:
235 error = rf_config50(raidPtr, unit, data, k_cfg);
236 if (error != 0)
237 return error;
238 return EAGAIN; /* flag mainline to call generic config */
239 }
240 return EPASSTHROUGH;
241 }
242
243 static void
244 raidframe_50_init(void)
245 {
246
247 MODULE_SET_HOOK(raidframe_ioctl_50_hook, "raid50", raidframe_ioctl_50);
248 }
249
250 static void
251 raidframe_50_fini(void)
252 {
253
254 MODULE_UNSET_HOOK(raidframe_ioctl_50_hook);
255 }
256
257 MODULE(MODULE_CLASS_EXEC, compat_raid_50, "raid,compat_50,compat_raid_80");
258
259 static int
260 compat_raid_50_modcmd(modcmd_t cmd, void *arg)
261 {
262
263 switch (cmd) {
264 case MODULE_CMD_INIT:
265 raidframe_50_init();
266 return 0;
267 case MODULE_CMD_FINI:
268 raidframe_50_fini();
269 return 0;
270 default:
271 return ENOTTY;
272 }
273 }
274