1 /* $NetBSD: rf_compat50.c,v 1.10 2019/03/01 11:06:56 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_debugMem.h" 52 53 typedef struct RF_Config50_s { 54 RF_RowCol_t numRow, numCol, numSpare; 55 int32_t devs[RF_MAXROW][RF_MAXCOL]; 56 char devnames[RF_MAXROW][RF_MAXCOL][50]; 57 int32_t spare_devs[RF_MAXSPARE]; 58 char spare_names[RF_MAXSPARE][50]; 59 RF_SectorNum_t sectPerSU; 60 RF_StripeNum_t SUsPerPU; 61 RF_StripeNum_t SUsPerRU; 62 RF_ParityConfig_t parityConfig; 63 RF_DiskQueueType_t diskQueueType; 64 char maxOutstandingDiskReqs; 65 char debugVars[RF_MAXDBGV][50]; 66 unsigned int layoutSpecificSize; 67 void *layoutSpecific; 68 int force; 69 } RF_Config50_t; 70 71 typedef struct RF_RaidDisk50_s { 72 char devname[56]; 73 RF_DiskStatus_t status; 74 RF_RowCol_t spareRow; 75 RF_RowCol_t spareCol; 76 RF_SectorCount_t numBlocks; 77 int blockSize; 78 RF_SectorCount_t partitionSize; 79 int auto_configured; 80 int32_t dev; 81 } RF_RaidDisk50_t; 82 83 typedef struct RF_DeviceConfig50_s { 84 u_int rows; 85 u_int cols; 86 u_int maxqdepth; 87 int ndevs; 88 RF_RaidDisk50_t devs[RF_MAX_DISKS]; 89 int nspares; 90 RF_RaidDisk50_t spares[RF_MAX_DISKS]; 91 } RF_DeviceConfig50_t; 92 93 static void 94 rf_disk_to_disk50(RF_RaidDisk50_t *d50, const RF_RaidDisk_t *d) 95 { 96 memcpy(d50->devname, d->devname, sizeof(d50->devname)); 97 d50->status = d->status; 98 d50->spareRow = 0; 99 d50->spareCol = d->spareCol; 100 d50->numBlocks = d->numBlocks; 101 d50->blockSize = d->blockSize; 102 d50->partitionSize = d->partitionSize; 103 d50->auto_configured = d->auto_configured; 104 d50->dev = d->dev; 105 } 106 107 static int 108 rf_config50(struct raid_softc *rs, void *data) 109 { 110 RF_Config50_t *u50_cfg, *k50_cfg; 111 RF_Config_t *k_cfg; 112 RF_Raid_t *raidPtr = rf_get_raid(rs); 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", rf_get_unit(rs)); 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 k50_cfg = RF_Malloc(sizeof(*k50_cfg)); 127 if (k50_cfg == NULL) 128 return ENOMEM; 129 130 error = copyin(u50_cfg, k50_cfg, sizeof(*k50_cfg)); 131 if (error) { 132 RF_Free(k50_cfg, sizeof(*k50_cfg)); 133 return error; 134 } 135 k_cfg = RF_Malloc(sizeof(*k_cfg)); 136 if (k_cfg == NULL) { 137 RF_Free(k50_cfg, sizeof(*k50_cfg)); 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(*k50_cfg)); 175 return rf_construct(rs, k_cfg); 176 } 177 178 static int 179 rf_get_info50(RF_Raid_t *raidPtr, void *data) 180 { 181 RF_DeviceConfig50_t **ucfgp = data, *d_cfg; 182 size_t i, j; 183 int error; 184 185 if (!raidPtr->valid) 186 return ENODEV; 187 188 d_cfg = RF_Malloc(sizeof(*d_cfg)); 189 190 if (d_cfg == NULL) 191 return ENOMEM; 192 193 d_cfg->rows = 1; /* there is only 1 row now */ 194 d_cfg->cols = raidPtr->numCol; 195 d_cfg->ndevs = raidPtr->numCol; 196 if (d_cfg->ndevs >= RF_MAX_DISKS) { 197 error = ENOMEM; 198 goto out; 199 } 200 201 d_cfg->nspares = raidPtr->numSpare; 202 if (d_cfg->nspares >= RF_MAX_DISKS) { 203 error = ENOMEM; 204 goto out; 205 } 206 207 d_cfg->maxqdepth = raidPtr->maxQueueDepth; 208 for (j = 0; j < d_cfg->cols; j++) 209 rf_disk_to_disk50(&d_cfg->devs[j], &raidPtr->Disks[j]); 210 211 for (j = d_cfg->cols, i = 0; i < d_cfg->nspares; i++, j++) 212 rf_disk_to_disk50(&d_cfg->spares[i], &raidPtr->Disks[j]); 213 214 error = copyout(d_cfg, *ucfgp, sizeof(**ucfgp)); 215 216 out: 217 RF_Free(d_cfg, sizeof(*d_cfg)); 218 return error; 219 } 220 221 static int 222 raidframe_ioctl_50(struct raid_softc *rs, u_long cmd, void *data) 223 { 224 RF_Raid_t *raidPtr = rf_get_raid(rs); 225 226 switch (cmd) { 227 case RAIDFRAME_GET_INFO50: 228 if (!rf_inited(rs)) 229 return ENXIO; 230 return rf_get_info50(raidPtr, data); 231 232 case RAIDFRAME_CONFIGURE50: 233 return rf_config50(rs, data); 234 default: 235 return EPASSTHROUGH; 236 } 237 } 238 239 static void 240 raidframe_50_init(void) 241 { 242 243 MODULE_HOOK_SET(raidframe_ioctl_50_hook, "raid50", raidframe_ioctl_50); 244 } 245 246 static void 247 raidframe_50_fini(void) 248 { 249 250 MODULE_HOOK_UNSET(raidframe_ioctl_50_hook); 251 } 252 253 MODULE(MODULE_CLASS_EXEC, compat_raid_50, "raid,compat_50,compat_raid_80"); 254 255 static int 256 compat_raid_50_modcmd(modcmd_t cmd, void *arg) 257 { 258 259 switch (cmd) { 260 case MODULE_CMD_INIT: 261 raidframe_50_init(); 262 return 0; 263 case MODULE_CMD_FINI: 264 raidframe_50_fini(); 265 return 0; 266 default: 267 return ENOTTY; 268 } 269 } 270