1/* $NetBSD: rf_compat32.c,v 1.9 2021/12/11 19:24:21 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/types.h> 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/module.h> 33#include <sys/compat_stub.h> 34 35#include <dev/raidframe/raidframeio.h> 36#include <dev/raidframe/raidframevar.h> 37 38#include "rf_raid.h" 39#include "rf_kintf.h" 40#include "rf_compat32.h" 41 42#include <compat/netbsd32/netbsd32.h> 43 44typedef netbsd32_int64 RF_SectorNum_t32; 45typedef netbsd32_int64 RF_StripeNum_t32; 46 47/* from <dev/raidframe/raidframevar.h> */ 48typedef struct RF_Config_s32 { 49 RF_RowCol_t numCol, numSpare; /* number of rows, columns, 50 * and spare disks */ 51 dev_t devs[RF_MAXROW][RF_MAXCOL]; /* device numbers for disks 52 * comprising array */ 53 char devnames[RF_MAXROW][RF_MAXCOL][50]; /* device names */ 54 dev_t spare_devs[RF_MAXSPARE]; /* device numbers for spare 55 * disks */ 56 char spare_names[RF_MAXSPARE][50]; /* device names */ 57 RF_SectorNum_t32 sectPerSU; /* sectors per stripe unit */ 58 RF_StripeNum_t32 SUsPerPU;/* stripe units per parity unit */ 59 RF_StripeNum_t32 SUsPerRU;/* stripe units per reconstruction unit */ 60 RF_ParityConfig_t parityConfig; /* identifies the RAID architecture to 61 * be used */ 62 RF_DiskQueueType_t diskQueueType; /* 'f' = fifo, 'c' = cvscan, 63 * not used in kernel */ 64 char maxOutstandingDiskReqs; /* # concurrent reqs to be sent to a 65 * disk. not used in kernel. */ 66 char debugVars[RF_MAXDBGV][50]; /* space for specifying debug 67 * variables & their values */ 68 unsigned int layoutSpecificSize; /* size in bytes of 69 * layout-specific info */ 70 netbsd32_pointer_t layoutSpecific; /* a pointer to a layout-specific structure to 71 * be copied in */ 72 int force; /* if !0, ignore many fatal 73 configuration conditions */ 74 /* 75 "force" is used to override cases where the component labels would 76 indicate that configuration should not proceed without user 77 intervention 78 */ 79} RF_Config_t32; 80 81static int 82rf_config_netbsd32(struct raid_softc *rs, void *data) 83{ 84 RF_Config_t32 *u_cfg32 = NETBSD32PTR64(*(netbsd32_pointer_t *)data); 85 RF_Config_t *k_cfg; 86 RF_Config_t32 *k_cfg32; 87 int rv; 88 89 k_cfg32 = RF_Malloc(sizeof(*k_cfg32)); 90 if (k_cfg32 == NULL) 91 return ENOMEM; 92 93 rv = copyin(u_cfg32, k_cfg32, sizeof(RF_Config_t32)); 94 if (rv) { 95 RF_Free(k_cfg32, sizeof(RF_Config_t32)); 96 return ENOMEM; 97 } 98 99 k_cfg = RF_Malloc(sizeof(*k_cfg)); 100 if (k_cfg == NULL) { 101 RF_Free(k_cfg32, sizeof(RF_Config_t32)); 102 return ENOMEM; 103 } 104 k_cfg->numCol = k_cfg32->numCol; 105 k_cfg->numSpare = k_cfg32->numSpare; 106 memcpy(k_cfg->devs, k_cfg32->devs, sizeof(k_cfg->devs)); 107 memcpy(k_cfg->devnames, k_cfg32->devnames, sizeof(k_cfg->devnames)); 108 memcpy(k_cfg->spare_devs, k_cfg32->spare_devs, 109 sizeof(k_cfg->spare_devs)); 110 memcpy(k_cfg->spare_names, k_cfg32->spare_names, 111 sizeof(k_cfg->spare_names)); 112 k_cfg->sectPerSU = k_cfg32->sectPerSU; 113 k_cfg->SUsPerPU = k_cfg32->SUsPerPU; 114 k_cfg->SUsPerRU = k_cfg32->SUsPerRU; 115 k_cfg->parityConfig = k_cfg32->parityConfig; 116 memcpy(k_cfg->diskQueueType, k_cfg32->diskQueueType, 117 sizeof(k_cfg->diskQueueType)); 118 k_cfg->maxOutstandingDiskReqs = k_cfg32->maxOutstandingDiskReqs; 119 memcpy(k_cfg->debugVars, k_cfg32->debugVars, sizeof(k_cfg->debugVars)); 120 k_cfg->layoutSpecificSize = k_cfg32->layoutSpecificSize; 121 k_cfg->layoutSpecific = NETBSD32PTR64(k_cfg32->layoutSpecific); 122 k_cfg->force = k_cfg32->force; 123 124 return rf_construct(rs, k_cfg); 125} 126 127static int 128rf_get_info_netbsd32(RF_Raid_t *raidPtr, void *data) 129{ 130 int retcode; 131 void *ucfgp = NETBSD32PTR64(*(netbsd32_pointer_t *)data); 132 133 RF_DeviceConfig_t *d_cfg = RF_Malloc(sizeof(*d_cfg)); 134 if (d_cfg == NULL) 135 return ENOMEM; 136 137 retcode = rf_get_info(raidPtr, d_cfg); 138 if (retcode == 0) { 139 retcode = copyout(d_cfg, ucfgp, sizeof(*d_cfg)); 140 } 141 RF_Free(d_cfg, sizeof(RF_DeviceConfig_t)); 142 return retcode; 143} 144 145static int 146raidframe_netbsd32_ioctl(struct raid_softc *rs, u_long cmd, void *data) 147{ 148 RF_Raid_t *raidPtr = rf_get_raid(rs); 149 150 switch (cmd) { 151 case RAIDFRAME_GET_INFO32: 152 if (!rf_inited(rs)) 153 return ENXIO; 154 return rf_get_info_netbsd32(raidPtr, data); 155 case RAIDFRAME_CONFIGURE32: 156 return rf_config_netbsd32(rs, data); 157 default: 158 return EPASSTHROUGH; 159 } 160} 161 162 163static void 164raidframe_netbsd32_init(void) 165{ 166 167 MODULE_HOOK_SET(raidframe_netbsd32_ioctl_hook, 168 raidframe_netbsd32_ioctl); 169} 170 171static void 172raidframe_netbsd32_fini(void) 173{ 174 175 MODULE_HOOK_UNSET(raidframe_netbsd32_ioctl_hook); 176} 177 178MODULE(MODULE_CLASS_EXEC, compat_netbsd32_raid, "raid,compat_netbsd32"); 179 180static int 181compat_netbsd32_raid_modcmd(modcmd_t cmd, void *arg) 182{ 183 184 switch (cmd) { 185 case MODULE_CMD_INIT: 186 raidframe_netbsd32_init(); 187 return 0; 188 case MODULE_CMD_FINI: 189 raidframe_netbsd32_fini(); 190 return 0; 191 default: 192 return ENOTTY; 193 } 194} 195 196