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