1 /* $NetBSD: rf_compat32.c,v 1.8 2020/01/07 06:10:18 maxv 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 #include <sys/module.h> 35 #include <sys/compat_stub.h> 36 37 #include <dev/raidframe/raidframeio.h> 38 #include <dev/raidframe/raidframevar.h> 39 40 #include "rf_raid.h" 41 #include "rf_kintf.h" 42 #include "rf_compat32.h" 43 44 #include <compat/netbsd32/netbsd32.h> 45 46 typedef netbsd32_int64 RF_SectorNum_t32; 47 typedef netbsd32_int64 RF_StripeNum_t32; 48 49 /* from <dev/raidframe/raidframevar.h> */ 50 typedef struct RF_Config_s32 { 51 RF_RowCol_t numCol, numSpare; /* number of rows, columns, 52 * and spare disks */ 53 dev_t devs[RF_MAXROW][RF_MAXCOL]; /* device numbers for disks 54 * comprising array */ 55 char devnames[RF_MAXROW][RF_MAXCOL][50]; /* device names */ 56 dev_t spare_devs[RF_MAXSPARE]; /* device numbers for spare 57 * disks */ 58 char spare_names[RF_MAXSPARE][50]; /* device names */ 59 RF_SectorNum_t32 sectPerSU; /* sectors per stripe unit */ 60 RF_StripeNum_t32 SUsPerPU;/* stripe units per parity unit */ 61 RF_StripeNum_t32 SUsPerRU;/* stripe units per reconstruction unit */ 62 RF_ParityConfig_t parityConfig; /* identifies the RAID architecture to 63 * be used */ 64 RF_DiskQueueType_t diskQueueType; /* 'f' = fifo, 'c' = cvscan, 65 * not used in kernel */ 66 char maxOutstandingDiskReqs; /* # concurrent reqs to be sent to a 67 * disk. not used in kernel. */ 68 char debugVars[RF_MAXDBGV][50]; /* space for specifying debug 69 * variables & their values */ 70 unsigned int layoutSpecificSize; /* size in bytes of 71 * layout-specific info */ 72 netbsd32_pointer_t layoutSpecific; /* a pointer to a layout-specific structure to 73 * be copied in */ 74 int force; /* if !0, ignore many fatal 75 configuration conditions */ 76 /* 77 "force" is used to override cases where the component labels would 78 indicate that configuration should not proceed without user 79 intervention 80 */ 81 } RF_Config_t32; 82 83 static int 84 rf_config_netbsd32(struct raid_softc *rs, void *data) 85 { 86 RF_Config_t32 *u_cfg32 = NETBSD32PTR64(*(netbsd32_pointer_t *)data); 87 RF_Config_t *k_cfg; 88 RF_Config_t32 *k_cfg32; 89 int rv; 90 91 k_cfg32 = RF_Malloc(sizeof(*k_cfg32)); 92 if (k_cfg32 == NULL) 93 return ENOMEM; 94 95 rv = copyin(u_cfg32, k_cfg32, sizeof(RF_Config_t32)); 96 if (rv) { 97 RF_Free(k_cfg32, sizeof(RF_Config_t32)); 98 return ENOMEM; 99 } 100 101 k_cfg = RF_Malloc(sizeof(*k_cfg)); 102 if (k_cfg == NULL) { 103 RF_Free(k_cfg32, sizeof(RF_Config_t32)); 104 return ENOMEM; 105 } 106 k_cfg->numCol = k_cfg32->numCol; 107 k_cfg->numSpare = k_cfg32->numSpare; 108 memcpy(k_cfg->devs, k_cfg32->devs, sizeof(k_cfg->devs)); 109 memcpy(k_cfg->devnames, k_cfg32->devnames, sizeof(k_cfg->devnames)); 110 memcpy(k_cfg->spare_devs, k_cfg32->spare_devs, 111 sizeof(k_cfg->spare_devs)); 112 memcpy(k_cfg->spare_names, k_cfg32->spare_names, 113 sizeof(k_cfg->spare_names)); 114 k_cfg->sectPerSU = k_cfg32->sectPerSU; 115 k_cfg->SUsPerPU = k_cfg32->SUsPerPU; 116 k_cfg->SUsPerRU = k_cfg32->SUsPerRU; 117 k_cfg->parityConfig = k_cfg32->parityConfig; 118 memcpy(k_cfg->diskQueueType, k_cfg32->diskQueueType, 119 sizeof(k_cfg->diskQueueType)); 120 k_cfg->maxOutstandingDiskReqs = k_cfg32->maxOutstandingDiskReqs; 121 memcpy(k_cfg->debugVars, k_cfg32->debugVars, sizeof(k_cfg->debugVars)); 122 k_cfg->layoutSpecificSize = k_cfg32->layoutSpecificSize; 123 k_cfg->layoutSpecific = NETBSD32PTR64(k_cfg32->layoutSpecific); 124 k_cfg->force = k_cfg32->force; 125 126 return rf_construct(rs, k_cfg); 127 } 128 129 static int 130 rf_get_info_netbsd32(RF_Raid_t *raidPtr, void *data) 131 { 132 int retcode; 133 void *ucfgp = NETBSD32PTR64(*(netbsd32_pointer_t *)data); 134 135 RF_DeviceConfig_t *d_cfg = RF_Malloc(sizeof(*d_cfg)); 136 if (d_cfg == NULL) 137 return ENOMEM; 138 139 retcode = rf_get_info(raidPtr, d_cfg); 140 if (retcode == 0) { 141 retcode = copyout(d_cfg, ucfgp, sizeof(*d_cfg)); 142 } 143 RF_Free(d_cfg, sizeof(RF_DeviceConfig_t)); 144 return retcode; 145 } 146 147 static int 148 raidframe_netbsd32_ioctl(struct raid_softc *rs, u_long cmd, void *data) 149 { 150 RF_Raid_t *raidPtr = rf_get_raid(rs); 151 152 switch (cmd) { 153 case RAIDFRAME_GET_INFO32: 154 if (!rf_inited(rs)) 155 return ENXIO; 156 return rf_get_info_netbsd32(raidPtr, data); 157 case RAIDFRAME_CONFIGURE32: 158 return rf_config_netbsd32(rs, data); 159 default: 160 return EPASSTHROUGH; 161 } 162 } 163 164 165 static void 166 raidframe_netbsd32_init(void) 167 { 168 169 MODULE_HOOK_SET(raidframe_netbsd32_ioctl_hook, 170 raidframe_netbsd32_ioctl); 171 } 172 173 static void 174 raidframe_netbsd32_fini(void) 175 { 176 177 MODULE_HOOK_UNSET(raidframe_netbsd32_ioctl_hook); 178 } 179 180 MODULE(MODULE_CLASS_EXEC, compat_netbsd32_raid, "raid,compat_netbsd32"); 181 182 static int 183 compat_netbsd32_raid_modcmd(modcmd_t cmd, void *arg) 184 { 185 186 switch (cmd) { 187 case MODULE_CMD_INIT: 188 raidframe_netbsd32_init(); 189 return 0; 190 case MODULE_CMD_FINI: 191 raidframe_netbsd32_fini(); 192 return 0; 193 default: 194 return ENOTTY; 195 } 196 } 197 198