Home | History | Annotate | Line # | Download | only in raidframe
rf_compat50.c revision 1.3.2.3
      1 /*	$NetBSD: rf_compat50.c,v 1.3.2.3 2018/09/17 11:04:30 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_compat50_mod.h"
     51 #include "rf_debugMem.h"
     52 
     53 typedef struct RF_Config50_s {
     54 	RF_RowCol_t		numRow, numCol, numSpare;
     55 	int32_t			devs[RF_MAXROW][RF_MAXCOL];
     56 	char			devnames[RF_MAXROW][RF_MAXCOL][50];
     57 	int32_t			spare_devs[RF_MAXSPARE];
     58 	char			spare_names[RF_MAXSPARE][50];
     59 	RF_SectorNum_t		sectPerSU;
     60 	RF_StripeNum_t		SUsPerPU;
     61 	RF_StripeNum_t		SUsPerRU;
     62 	RF_ParityConfig_t	parityConfig;
     63 	RF_DiskQueueType_t	diskQueueType;
     64 	char			maxOutstandingDiskReqs;
     65 	char			debugVars[RF_MAXDBGV][50];
     66 	unsigned int		layoutSpecificSize;
     67 	void		       *layoutSpecific;
     68 	int			force;
     69 } RF_Config50_t;
     70 
     71 typedef struct RF_RaidDisk50_s {
     72         char		 devname[56];
     73         RF_DiskStatus_t	 status;
     74         RF_RowCol_t	 spareRow;
     75         RF_RowCol_t	 spareCol;
     76         RF_SectorCount_t numBlocks;
     77         int     	 blockSize;
     78         RF_SectorCount_t partitionSize;
     79         int    		 auto_configured;
     80         int32_t		 dev;
     81 } RF_RaidDisk50_t;
     82 
     83 typedef struct RF_DeviceConfig50_s {
     84 	u_int			rows;
     85 	u_int			cols;
     86 	u_int			maxqdepth;
     87 	int			ndevs;
     88 	RF_RaidDisk50_t		devs[RF_MAX_DISKS];
     89 	int			nspares;
     90 	RF_RaidDisk50_t		spares[RF_MAX_DISKS];
     91 } RF_DeviceConfig50_t;
     92 
     93 static void
     94 rf_disk_to_disk50(RF_RaidDisk50_t *d50, const RF_RaidDisk_t *d)
     95 {
     96         memcpy(d50->devname, d->devname, sizeof(d50->devname));
     97         d50->status = d->status;
     98         d50->spareRow = 0;
     99         d50->spareCol = d->spareCol;
    100         d50->numBlocks = d->numBlocks;
    101         d50->blockSize = d->blockSize;
    102         d50->partitionSize = d->partitionSize;
    103         d50->auto_configured = d->auto_configured;
    104         d50->dev = d->dev;
    105 }
    106 
    107 int
    108 rf_config50(RF_Raid_t *raidPtr, int unit, void *data, RF_Config_t **k_cfgp)
    109 {
    110 	RF_Config50_t *u50_cfg, *k50_cfg;
    111 	RF_Config_t *k_cfg;
    112 	size_t i, j;
    113 	int error;
    114 
    115 	if (raidPtr->valid) {
    116 		/* There is a valid RAID set running on this unit! */
    117 		printf("raid%d: Device already configured!\n", unit);
    118 		return EINVAL;
    119 	}
    120 
    121 	/* copy-in the configuration information */
    122 	/* data points to a pointer to the configuration structure */
    123 
    124 	u50_cfg = *((RF_Config50_t **) data);
    125 	RF_Malloc(k50_cfg, sizeof(RF_Config50_t), (RF_Config50_t *));
    126 	if (k50_cfg == NULL)
    127 		return ENOMEM;
    128 
    129 	error = copyin(u50_cfg, k50_cfg, sizeof(RF_Config50_t));
    130 	if (error) {
    131 		RF_Free(k50_cfg, sizeof(RF_Config50_t));
    132 		return error;
    133 	}
    134 	RF_Malloc(k_cfg, sizeof(RF_Config_t), (RF_Config_t *));
    135 	if (k_cfg == NULL) {
    136 		RF_Free(k50_cfg, sizeof(RF_Config50_t));
    137 		return ENOMEM;
    138 	}
    139 
    140 	k_cfg->numCol = k50_cfg->numCol;
    141 	k_cfg->numSpare = k50_cfg->numSpare;
    142 
    143 	for (i = 0; i < RF_MAXROW; i++)
    144 		for (j = 0; j < RF_MAXCOL; j++)
    145 			k_cfg->devs[i][j] = k50_cfg->devs[i][j];
    146 
    147 	memcpy(k_cfg->devnames, k50_cfg->devnames,
    148 	    sizeof(k_cfg->devnames));
    149 
    150 	for (i = 0; i < RF_MAXSPARE; i++)
    151 		k_cfg->spare_devs[i] = k50_cfg->spare_devs[i];
    152 
    153 	memcpy(k_cfg->spare_names, k50_cfg->spare_names,
    154 	    sizeof(k_cfg->spare_names));
    155 
    156 	k_cfg->sectPerSU = k50_cfg->sectPerSU;
    157 	k_cfg->SUsPerPU = k50_cfg->SUsPerPU;
    158 	k_cfg->SUsPerRU = k50_cfg->SUsPerRU;
    159 	k_cfg->parityConfig = k50_cfg->parityConfig;
    160 
    161 	memcpy(k_cfg->diskQueueType, k50_cfg->diskQueueType,
    162 	    sizeof(k_cfg->diskQueueType));
    163 
    164 	k_cfg->maxOutstandingDiskReqs = k50_cfg->maxOutstandingDiskReqs;
    165 
    166 	memcpy(k_cfg->debugVars, k50_cfg->debugVars,
    167 	    sizeof(k_cfg->debugVars));
    168 
    169 	k_cfg->layoutSpecificSize = k50_cfg->layoutSpecificSize;
    170 	k_cfg->layoutSpecific = k50_cfg->layoutSpecific;
    171 	k_cfg->force = k50_cfg->force;
    172 
    173 	RF_Free(k50_cfg, sizeof(RF_Config50_t));
    174 	*k_cfgp = k_cfg;
    175 	return 0;
    176 }
    177 
    178 int
    179 rf_get_info50(RF_Raid_t *raidPtr, void *data)
    180 {
    181 	RF_DeviceConfig50_t **ucfgp = data, *d_cfg;
    182 	size_t i, j;
    183 	int error;
    184 
    185 	if (!raidPtr->valid)
    186 		return ENODEV;
    187 
    188 	RF_Malloc(d_cfg, sizeof(RF_DeviceConfig50_t), (RF_DeviceConfig50_t *));
    189 
    190 	if (d_cfg == NULL)
    191 		return ENOMEM;
    192 
    193 	d_cfg->rows = 1; /* there is only 1 row now */
    194 	d_cfg->cols = raidPtr->numCol;
    195 	d_cfg->ndevs = raidPtr->numCol;
    196 	if (d_cfg->ndevs >= RF_MAX_DISKS) {
    197 		error = ENOMEM;
    198 		goto out;
    199 	}
    200 
    201 	d_cfg->nspares = raidPtr->numSpare;
    202 	if (d_cfg->nspares >= RF_MAX_DISKS) {
    203 		error = ENOMEM;
    204 		goto out;
    205 	}
    206 
    207 	d_cfg->maxqdepth = raidPtr->maxQueueDepth;
    208 	for (j = 0; j < d_cfg->cols; j++)
    209 		rf_disk_to_disk50(&d_cfg->devs[j], &raidPtr->Disks[j]);
    210 
    211 	for (j = d_cfg->cols, i = 0; i < d_cfg->nspares; i++, j++)
    212 		rf_disk_to_disk50(&d_cfg->spares[i], &raidPtr->Disks[j]);
    213 
    214 	error = copyout(d_cfg, *ucfgp, sizeof(RF_DeviceConfig50_t));
    215 
    216 out:
    217 	RF_Free(d_cfg, sizeof(RF_DeviceConfig50_t));
    218 	return error;
    219 }
    220 
    221 int
    222 raidframe_ioctl_50(int cmd, int initted, RF_Raid_t *raidPtr, int unit,
    223     void *data, RF_Config_t **k_cfg)
    224 {
    225 	int error;
    226 
    227 	switch (cmd) {
    228 	case RAIDFRAME_GET_INFO50:
    229 		if (initted == 0)
    230 			return ENXIO;
    231 		return rf_get_info50(raidPtr, data);
    232 
    233 	case RAIDFRAME_CONFIGURE50:
    234 		error = rf_config50(raidPtr, unit, data, k_cfg);
    235 		if (error != 0)
    236 			return error;
    237 		return EAGAIN;	/* flag mainline to call generic config */
    238 	}
    239 	return EPASSTHROUGH;
    240 }
    241 
    242 COMPAT_SET_HOOK(raidframe50_ioctl_hook, "raid50", raidframe_ioctl_50);
    243 COMPAT_UNSET_HOOK(raidframe50_ioctl_hook)
    244 
    245 void
    246 raidframe_50_init(void)
    247 {
    248 
    249 	raidframe50_ioctl_hook_set();
    250 }
    251 
    252 void
    253 raidframe_50_fini(void)
    254 {
    255 
    256 	raidframe50_ioctl_hook_unset();
    257 }
    258