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