1 /* $NetBSD: rf_compat80.c,v 1.2 2018/01/20 01:32:45 mrg 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 35 #include <dev/raidframe/raidframeio.h> 36 #include <dev/raidframe/raidframevar.h> 37 38 #include "rf_raid.h" 39 #include "rf_compat80.h" 40 #include "rf_kintf.h" 41 42 int 43 rf_check_recon_status_ext80(RF_Raid_t *raidPtr, void *data) 44 { 45 RF_ProgressInfo_t info, **infoPtr = data; 46 47 rf_check_recon_status_ext(raidPtr, &info); 48 return copyout(&info, *infoPtr, sizeof info); 49 } 50 51 int 52 rf_check_parityrewrite_status_ext80(RF_Raid_t *raidPtr, void *data) 53 { 54 RF_ProgressInfo_t info, **infoPtr = data; 55 56 rf_check_parityrewrite_status_ext(raidPtr, &info); 57 return copyout(&info, *infoPtr, sizeof info); 58 } 59 60 int 61 rf_check_copyback_status_ext80(RF_Raid_t *raidPtr, void *data) 62 { 63 RF_ProgressInfo_t info, **infoPtr = data; 64 65 rf_check_copyback_status_ext(raidPtr, &info); 66 return copyout(&info, *infoPtr, sizeof info); 67 } 68 69 static void 70 rf_copy_raiddisk80(RF_RaidDisk_t *disk, RF_RaidDisk_t80 *disk80) 71 { 72 73 /* Be sure the padding areas don't have kernel memory. */ 74 memset(disk80, 0, sizeof *disk80); 75 memcpy(disk80->devname, disk->devname, sizeof(disk80->devname)); 76 disk80->status = disk->status; 77 disk80->spareRow = 0; 78 disk80->spareCol = disk->spareCol; 79 disk80->numBlocks = disk->numBlocks; 80 disk80->blockSize = disk->blockSize; 81 disk80->partitionSize = disk->partitionSize; 82 disk80->auto_configured = disk->auto_configured; 83 disk80->dev = disk->dev; 84 } 85 86 int 87 rf_get_info80(RF_Raid_t *raidPtr, void *data) 88 { 89 RF_DeviceConfig_t *config; 90 RF_DeviceConfig_t80 *config80, **configPtr80 = data; 91 int rv; 92 93 RF_Malloc(config, sizeof *config, (RF_DeviceConfig_t *)); 94 if (config == NULL) 95 return (ENOMEM); 96 RF_Malloc(config80, sizeof *config80, (RF_DeviceConfig_t80 *)); 97 if (config80 == NULL) { 98 RF_Free(config, sizeof(RF_DeviceConfig_t)) 99 return (ENOMEM); 100 } 101 rv = rf_get_info(raidPtr, config); 102 if (rv == 0) { 103 /* convert new to old */ 104 config80->rows = 1; 105 config80->cols = config->cols; 106 config80->maxqdepth = config->maxqdepth; 107 config80->ndevs = config->ndevs; 108 config80->nspares = config->nspares; 109 for (size_t i = 0; i < RF_MAX_DISKS; i++) { 110 rf_copy_raiddisk80(&config->devs[i], 111 &config80->devs[i]); 112 rf_copy_raiddisk80(&config->spares[i], 113 &config80->spares[i]); 114 } 115 rv = copyout(config80, *configPtr80, sizeof *config80); 116 } 117 RF_Free(config, sizeof(RF_DeviceConfig_t)); 118 RF_Free(config80, sizeof(RF_DeviceConfig_t80)); 119 120 return rv; 121 } 122 123 int 124 rf_get_component_label80(RF_Raid_t *raidPtr, void *data) 125 { 126 RF_ComponentLabel_t **clabel_ptr = (RF_ComponentLabel_t **)data; 127 RF_ComponentLabel_t *clabel; 128 int retcode; 129 130 /* 131 * Perhaps there should be an option to skip the in-core 132 * copy and hit the disk, as with disklabel(8). 133 */ 134 RF_Malloc(clabel, sizeof(*clabel), (RF_ComponentLabel_t *)); 135 if (clabel == NULL) 136 return ENOMEM; 137 retcode = copyin(*clabel_ptr, clabel, sizeof(*clabel)); 138 if (retcode) { 139 RF_Free(clabel, sizeof(*clabel)); 140 return retcode; 141 } 142 143 rf_get_component_label(raidPtr, clabel); 144 retcode = copyout(clabel, *clabel_ptr, sizeof(**clabel_ptr)); 145 RF_Free(clabel, sizeof(*clabel)); 146 147 return retcode; 148 } 149 150 int 151 rf_config80(RF_Raid_t *raidPtr, int unit, void *data, RF_Config_t **k_cfgp) 152 { 153 RF_Config_t80 *u80_cfg, *k80_cfg; 154 RF_Config_t *k_cfg; 155 size_t i, j; 156 int error; 157 158 if (raidPtr->valid) { 159 /* There is a valid RAID set running on this unit! */ 160 printf("raid%d: Device already configured!\n", unit); 161 return EINVAL; 162 } 163 164 /* copy-in the configuration information */ 165 /* data points to a pointer to the configuration structure */ 166 167 u80_cfg = *((RF_Config_t80 **) data); 168 RF_Malloc(k80_cfg, sizeof(RF_Config_t80), (RF_Config_t80 *)); 169 if (k80_cfg == NULL) 170 return ENOMEM; 171 172 error = copyin(u80_cfg, k80_cfg, sizeof(RF_Config_t80)); 173 if (error) { 174 RF_Free(k80_cfg, sizeof(RF_Config_t80)); 175 return error; 176 } 177 RF_Malloc(k_cfg, sizeof(RF_Config_t), (RF_Config_t *)); 178 if (k_cfg == NULL) { 179 RF_Free(k80_cfg, sizeof(RF_Config_t80)); 180 return ENOMEM; 181 } 182 183 k_cfg->numCol = k80_cfg->numCol; 184 k_cfg->numSpare = k80_cfg->numSpare; 185 186 for (i = 0; i < RF_MAXROW; i++) 187 for (j = 0; j < RF_MAXCOL; j++) 188 k_cfg->devs[i][j] = k80_cfg->devs[i][j]; 189 190 memcpy(k_cfg->devnames, k80_cfg->devnames, 191 sizeof(k_cfg->devnames)); 192 193 for (i = 0; i < RF_MAXSPARE; i++) 194 k_cfg->spare_devs[i] = k80_cfg->spare_devs[i]; 195 196 memcpy(k_cfg->spare_names, k80_cfg->spare_names, 197 sizeof(k_cfg->spare_names)); 198 199 k_cfg->sectPerSU = k80_cfg->sectPerSU; 200 k_cfg->SUsPerPU = k80_cfg->SUsPerPU; 201 k_cfg->SUsPerRU = k80_cfg->SUsPerRU; 202 k_cfg->parityConfig = k80_cfg->parityConfig; 203 204 memcpy(k_cfg->diskQueueType, k80_cfg->diskQueueType, 205 sizeof(k_cfg->diskQueueType)); 206 207 k_cfg->maxOutstandingDiskReqs = k80_cfg->maxOutstandingDiskReqs; 208 209 memcpy(k_cfg->debugVars, k80_cfg->debugVars, 210 sizeof(k_cfg->debugVars)); 211 212 k_cfg->layoutSpecificSize = k80_cfg->layoutSpecificSize; 213 k_cfg->layoutSpecific = k80_cfg->layoutSpecific; 214 k_cfg->force = k80_cfg->force; 215 216 RF_Free(k80_cfg, sizeof(RF_Config_t80)); 217 *k_cfgp = k_cfg; 218 return 0; 219 } 220