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