Home | History | Annotate | Line # | Download | only in raidframe
rf_compat32.c revision 1.1
      1 /*	$NetBSD: rf_compat32.c,v 1.1 2018/01/18 00:32:49 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_compat32.h"
     40 
     41 #include <compat/netbsd32/netbsd32.h>
     42 
     43 typedef netbsd32_int64 RF_SectorNum_t32;
     44 typedef netbsd32_int64 RF_StripeNum_t32;
     45 
     46 /* from <dev/raidframe/raidframevar.h> */
     47 typedef struct RF_Config_s32 {
     48 	RF_RowCol_t numCol, numSpare;		/* number of rows, columns,
     49 						 * and spare disks */
     50 	dev_t   devs[RF_MAXROW][RF_MAXCOL];	/* device numbers for disks
     51 						 * comprising array */
     52 	char    devnames[RF_MAXROW][RF_MAXCOL][50];	/* device names */
     53 	dev_t   spare_devs[RF_MAXSPARE];	/* device numbers for spare
     54 						 * disks */
     55 	char    spare_names[RF_MAXSPARE][50];	/* device names */
     56 	RF_SectorNum_t32 sectPerSU;	/* sectors per stripe unit */
     57 	RF_StripeNum_t32 SUsPerPU;/* stripe units per parity unit */
     58 	RF_StripeNum_t32 SUsPerRU;/* stripe units per reconstruction unit */
     59 	RF_ParityConfig_t parityConfig;	/* identifies the RAID architecture to
     60 					 * be used */
     61 	RF_DiskQueueType_t diskQueueType;	/* 'f' = fifo, 'c' = cvscan,
     62 						 * not used in kernel */
     63 	char    maxOutstandingDiskReqs;	/* # concurrent reqs to be sent to a
     64 					 * disk.  not used in kernel. */
     65 	char    debugVars[RF_MAXDBGV][50];	/* space for specifying debug
     66 						 * variables & their values */
     67 	unsigned int layoutSpecificSize;	/* size in bytes of
     68 						 * layout-specific info */
     69 	netbsd32_pointer_t   layoutSpecific;	/* a pointer to a layout-specific structure to
     70 				 * be copied in */
     71 	int     force;                          /* if !0, ignore many fatal
     72 						   configuration conditions */
     73 	/*
     74 	   "force" is used to override cases where the component labels would
     75 	   indicate that configuration should not proceed without user
     76 	   intervention
     77 	 */
     78 } RF_Config_t32 ;
     79 
     80 int
     81 rf_config_netbsd32(void *data, RF_Config_t *k_cfg)
     82 {
     83 	RF_Config_t32 *u_cfg = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
     84 	struct RF_Config_s32 *cfg32;
     85 	int rv;
     86 
     87 	RF_Malloc(cfg32, sizeof(RF_Config_t), (RF_Config_t32 *));
     88 	if (cfg32 == NULL)
     89 		return (ENOMEM);
     90 
     91 	rv = copyin(u_cfg, cfg32, sizeof(RF_Config_t32));
     92 	if (rv)
     93 		goto out;
     94 
     95 	k_cfg->numCol = cfg32->numCol;
     96 	k_cfg->numSpare = cfg32->numSpare;
     97 	memcpy(k_cfg->devs, cfg32->devs, sizeof(k_cfg->devs));
     98 	memcpy(k_cfg->devnames, cfg32->devnames, sizeof(k_cfg->devnames));
     99 	memcpy(k_cfg->spare_devs, cfg32->spare_devs, sizeof(k_cfg->spare_devs));
    100 	memcpy(k_cfg->spare_names, cfg32->spare_names, sizeof(k_cfg->spare_names));
    101 	k_cfg->sectPerSU = cfg32->sectPerSU;
    102 	k_cfg->SUsPerPU = cfg32->SUsPerPU;
    103 	k_cfg->SUsPerRU = cfg32->SUsPerRU;
    104 	k_cfg->parityConfig = cfg32->parityConfig;
    105 	memcpy(k_cfg->diskQueueType, cfg32->diskQueueType, sizeof(k_cfg->diskQueueType));
    106 	k_cfg->maxOutstandingDiskReqs = cfg32->maxOutstandingDiskReqs;
    107 	memcpy(k_cfg->debugVars, cfg32->debugVars, sizeof(k_cfg->debugVars));
    108 	k_cfg->layoutSpecificSize = cfg32->layoutSpecificSize;
    109 	k_cfg->layoutSpecific = NETBSD32PTR64(cfg32->layoutSpecific);
    110 	k_cfg->force = cfg32->force;
    111 
    112  out:
    113 	RF_Free(cfg32, sizeof(RF_Config_t32));
    114 	return rv;
    115 }
    116