Home | History | Annotate | Line # | Download | only in raidframe
rf_compat50.c revision 1.3.2.1
      1 /*	$NetBSD: rf_compat50.c,v 1.3.2.1 2018/03/24 01:59:15 pgoyette Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2009 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Christos Zoulas.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/types.h>
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 
     43 #include <sys/compat_stub.h>
     44 
     45 #include <dev/raidframe/raidframeio.h>
     46 #include <dev/raidframe/raidframevar.h>
     47 
     48 #include "rf_raid.h"
     49 #include "rf_compat50.h"
     50 #include "rf_debugMem.h"
     51 
     52 typedef struct RF_Config50_s {
     53 	RF_RowCol_t		numRow, numCol, numSpare;
     54 	int32_t			devs[RF_MAXROW][RF_MAXCOL];
     55 	char			devnames[RF_MAXROW][RF_MAXCOL][50];
     56 	int32_t			spare_devs[RF_MAXSPARE];
     57 	char			spare_names[RF_MAXSPARE][50];
     58 	RF_SectorNum_t		sectPerSU;
     59 	RF_StripeNum_t		SUsPerPU;
     60 	RF_StripeNum_t		SUsPerRU;
     61 	RF_ParityConfig_t	parityConfig;
     62 	RF_DiskQueueType_t	diskQueueType;
     63 	char			maxOutstandingDiskReqs;
     64 	char			debugVars[RF_MAXDBGV][50];
     65 	unsigned int		layoutSpecificSize;
     66 	void		       *layoutSpecific;
     67 	int			force;
     68 } RF_Config50_t;
     69 
     70 typedef struct RF_RaidDisk50_s {
     71         char		 devname[56];
     72         RF_DiskStatus_t	 status;
     73         RF_RowCol_t	 spareRow;
     74         RF_RowCol_t	 spareCol;
     75         RF_SectorCount_t numBlocks;
     76         int     	 blockSize;
     77         RF_SectorCount_t partitionSize;
     78         int    		 auto_configured;
     79         int32_t		 dev;
     80 } RF_RaidDisk50_t;
     81 
     82 typedef struct RF_DeviceConfig50_s {
     83 	u_int			rows;
     84 	u_int			cols;
     85 	u_int			maxqdepth;
     86 	int			ndevs;
     87 	RF_RaidDisk50_t		devs[RF_MAX_DISKS];
     88 	int			nspares;
     89 	RF_RaidDisk50_t		spares[RF_MAX_DISKS];
     90 } RF_DeviceConfig50_t;
     91 
     92 static void
     93 rf_disk_to_disk50(RF_RaidDisk50_t *d50, const RF_RaidDisk_t *d)
     94 {
     95         memcpy(d50->devname, d->devname, sizeof(d50->devname));
     96         d50->status = d->status;
     97         d50->spareRow = 0;
     98         d50->spareCol = d->spareCol;
     99         d50->numBlocks = d->numBlocks;
    100         d50->blockSize = d->blockSize;
    101         d50->partitionSize = d->partitionSize;
    102         d50->auto_configured = d->auto_configured;
    103         d50->dev = d->dev;
    104 }
    105 
    106 int
    107 rf_config50(RF_Raid_t *raidPtr, int unit, void *data, RF_Config_t **k_cfgp)
    108 {
    109 	RF_Config50_t *u50_cfg, *k50_cfg;
    110 	RF_Config_t *k_cfg;
    111 	size_t i, j;
    112 	int error;
    113 
    114 	if (raidPtr->valid) {
    115 		/* There is a valid RAID set running on this unit! */
    116 		printf("raid%d: Device already configured!\n", unit);
    117 		return EINVAL;
    118 	}
    119 
    120 	/* copy-in the configuration information */
    121 	/* data points to a pointer to the configuration structure */
    122 
    123 	u50_cfg = *((RF_Config50_t **) data);
    124 	RF_Malloc(k50_cfg, sizeof(RF_Config50_t), (RF_Config50_t *));
    125 	if (k50_cfg == NULL)
    126 		return ENOMEM;
    127 
    128 	error = copyin(u50_cfg, k50_cfg, sizeof(RF_Config50_t));
    129 	if (error) {
    130 		RF_Free(k50_cfg, sizeof(RF_Config50_t));
    131 		return error;
    132 	}
    133 	RF_Malloc(k_cfg, sizeof(RF_Config_t), (RF_Config_t *));
    134 	if (k_cfg == NULL) {
    135 		RF_Free(k50_cfg, sizeof(RF_Config50_t));
    136 		return ENOMEM;
    137 	}
    138 
    139 	k_cfg->numCol = k50_cfg->numCol;
    140 	k_cfg->numSpare = k50_cfg->numSpare;
    141 
    142 	for (i = 0; i < RF_MAXROW; i++)
    143 		for (j = 0; j < RF_MAXCOL; j++)
    144 			k_cfg->devs[i][j] = k50_cfg->devs[i][j];
    145 
    146 	memcpy(k_cfg->devnames, k50_cfg->devnames,
    147 	    sizeof(k_cfg->devnames));
    148 
    149 	for (i = 0; i < RF_MAXSPARE; i++)
    150 		k_cfg->spare_devs[i] = k50_cfg->spare_devs[i];
    151 
    152 	memcpy(k_cfg->spare_names, k50_cfg->spare_names,
    153 	    sizeof(k_cfg->spare_names));
    154 
    155 	k_cfg->sectPerSU = k50_cfg->sectPerSU;
    156 	k_cfg->SUsPerPU = k50_cfg->SUsPerPU;
    157 	k_cfg->SUsPerRU = k50_cfg->SUsPerRU;
    158 	k_cfg->parityConfig = k50_cfg->parityConfig;
    159 
    160 	memcpy(k_cfg->diskQueueType, k50_cfg->diskQueueType,
    161 	    sizeof(k_cfg->diskQueueType));
    162 
    163 	k_cfg->maxOutstandingDiskReqs = k50_cfg->maxOutstandingDiskReqs;
    164 
    165 	memcpy(k_cfg->debugVars, k50_cfg->debugVars,
    166 	    sizeof(k_cfg->debugVars));
    167 
    168 	k_cfg->layoutSpecificSize = k50_cfg->layoutSpecificSize;
    169 	k_cfg->layoutSpecific = k50_cfg->layoutSpecific;
    170 	k_cfg->force = k50_cfg->force;
    171 
    172 	RF_Free(k50_cfg, sizeof(RF_Config50_t));
    173 	*k_cfgp = k_cfg;
    174 	return 0;
    175 }
    176 
    177 int
    178 rf_get_info50(RF_Raid_t *raidPtr, void *data)
    179 {
    180 	RF_DeviceConfig50_t **ucfgp = data, *d_cfg;
    181 	size_t i, j;
    182 	int error;
    183 
    184 	if (!raidPtr->valid)
    185 		return ENODEV;
    186 
    187 	RF_Malloc(d_cfg, sizeof(RF_DeviceConfig50_t), (RF_DeviceConfig50_t *));
    188 
    189 	if (d_cfg == NULL)
    190 		return ENOMEM;
    191 
    192 	d_cfg->rows = 1; /* there is only 1 row now */
    193 	d_cfg->cols = raidPtr->numCol;
    194 	d_cfg->ndevs = raidPtr->numCol;
    195 	if (d_cfg->ndevs >= RF_MAX_DISKS) {
    196 		error = ENOMEM;
    197 		goto out;
    198 	}
    199 
    200 	d_cfg->nspares = raidPtr->numSpare;
    201 	if (d_cfg->nspares >= RF_MAX_DISKS) {
    202 		error = ENOMEM;
    203 		goto out;
    204 	}
    205 
    206 	d_cfg->maxqdepth = raidPtr->maxQueueDepth;
    207 	for (j = 0; j < d_cfg->cols; j++)
    208 		rf_disk_to_disk50(&d_cfg->devs[j], &raidPtr->Disks[j]);
    209 
    210 	for (j = d_cfg->cols, i = 0; i < d_cfg->nspares; i++, j++)
    211 		rf_disk_to_disk50(&d_cfg->spares[i], &raidPtr->Disks[j]);
    212 
    213 	error = copyout(d_cfg, *ucfgp, sizeof(RF_DeviceConfig50_t));
    214 
    215 out:
    216 	RF_Free(d_cfg, sizeof(RF_DeviceConfig50_t));
    217 	return error;
    218 }
    219 
    220 int
    221 raidframe_ioctl_50(int cmd, int initted, RF_Raid_t *raidPtr, int unit,
    222     void *data, RF_Config_t **k_cfg)
    223 {
    224 	int error;
    225 
    226 	switch (cmd) {
    227 	case RAIDFRAME_GET_INFO50:
    228 		if (initted == 0)
    229 			return ENXIO;
    230 		return rf_get_info50(raidPtr, data);
    231 
    232 	case RAIDFRAME_CONFIGURE50:
    233 		error = rf_config50(raidPtr, unit, data, k_cfg);
    234 		if (error != 0)
    235 			return error;
    236 		return EAGAIN;	/* flag mainline to call generic config */
    237 	}
    238 	return EPASSTHROUGH;
    239 }
    240 
    241 void
    242 raidframe_50_init(void)
    243 {
    244 
    245 	raidframe50_ioctl = raidframe_ioctl_50;
    246 }
    247 
    248 void
    249 raidframe_50_fini(void)
    250 {
    251 
    252 	raidframe50_ioctl = (void *)enosys;
    253 }
    254