Home | History | Annotate | Line # | Download | only in raidframe
      1 /*	$NetBSD: rf_compat50.c,v 1.13 2019/12/15 16:48:27 tsutsui 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/types.h>
     33 #include <sys/param.h>
     34 #include <sys/systm.h>
     35 #include <sys/module.h>
     36 
     37 #include <sys/compat_stub.h>
     38 
     39 #include <dev/raidframe/raidframeio.h>
     40 #include <dev/raidframe/raidframevar.h>
     41 
     42 #include "rf_raid.h"
     43 #include "rf_compat50.h"
     44 #include "rf_debugMem.h"
     45 
     46 typedef struct RF_Config50_s {
     47 	RF_RowCol_t		numRow, numCol, numSpare;
     48 	int32_t			devs[RF_MAXROW][RF_MAXCOL];
     49 	char			devnames[RF_MAXROW][RF_MAXCOL][50];
     50 	int32_t			spare_devs[RF_MAXSPARE];
     51 	char			spare_names[RF_MAXSPARE][50];
     52 	RF_SectorNum_t		sectPerSU;
     53 	RF_StripeNum_t		SUsPerPU;
     54 	RF_StripeNum_t		SUsPerRU;
     55 	RF_ParityConfig_t	parityConfig;
     56 	RF_DiskQueueType_t	diskQueueType;
     57 	char			maxOutstandingDiskReqs;
     58 	char			debugVars[RF_MAXDBGV][50];
     59 	unsigned int		layoutSpecificSize;
     60 	void		       *layoutSpecific;
     61 	int			force;
     62 } RF_Config50_t;
     63 
     64 typedef struct RF_RaidDisk50_s {
     65         char		 devname[56];
     66         RF_DiskStatus_t	 status;
     67         RF_RowCol_t	 spareRow;
     68         RF_RowCol_t	 spareCol;
     69         RF_SectorCount_t numBlocks;
     70         int     	 blockSize;
     71         RF_SectorCount_t partitionSize;
     72         int    		 auto_configured;
     73         int32_t		 dev;
     74 } RF_RaidDisk50_t;
     75 
     76 typedef struct RF_DeviceConfig50_s {
     77 	u_int			rows;
     78 	u_int			cols;
     79 	u_int			maxqdepth;
     80 	int			ndevs;
     81 	RF_RaidDisk50_t		devs[RF_MAX_DISKS];
     82 	u_int			nspares;
     83 	RF_RaidDisk50_t		spares[RF_MAX_DISKS];
     84 } RF_DeviceConfig50_t;
     85 
     86 static void
     87 rf_disk_to_disk50(RF_RaidDisk50_t *d50, const RF_RaidDisk_t *d)
     88 {
     89         memcpy(d50->devname, d->devname, sizeof(d50->devname));
     90         d50->status = d->status;
     91         d50->spareRow = 0;
     92         d50->spareCol = d->spareCol;
     93         d50->numBlocks = d->numBlocks;
     94         d50->blockSize = d->blockSize;
     95         d50->partitionSize = d->partitionSize;
     96         d50->auto_configured = d->auto_configured;
     97         d50->dev = d->dev;
     98 }
     99 
    100 static int
    101 rf_config50(struct raid_softc *rs, void *data)
    102 {
    103 	RF_Config50_t *u50_cfg, *k50_cfg;
    104 	RF_Config_t *k_cfg;
    105 	RF_Raid_t *raidPtr = rf_get_raid(rs);
    106 	size_t i, j;
    107 	int error;
    108 
    109 	if (raidPtr->valid) {
    110 		/* There is a valid RAID set running on this unit! */
    111 		printf("raid%d: Device already configured!\n", rf_get_unit(rs));
    112 		return EINVAL;
    113 	}
    114 
    115 	/* copy-in the configuration information */
    116 	/* data points to a pointer to the configuration structure */
    117 
    118 	u50_cfg = *((RF_Config50_t **) data);
    119 	k50_cfg = RF_Malloc(sizeof(*k50_cfg));
    120 	if (k50_cfg == NULL)
    121 		return ENOMEM;
    122 
    123 	error = copyin(u50_cfg, k50_cfg, sizeof(*k50_cfg));
    124 	if (error) {
    125 		RF_Free(k50_cfg, sizeof(*k50_cfg));
    126 		return error;
    127 	}
    128 	k_cfg = RF_Malloc(sizeof(*k_cfg));
    129 	if (k_cfg == NULL) {
    130 		RF_Free(k50_cfg, sizeof(*k50_cfg));
    131 		return ENOMEM;
    132 	}
    133 
    134 	k_cfg->numCol = k50_cfg->numCol;
    135 	k_cfg->numSpare = k50_cfg->numSpare;
    136 
    137 	for (i = 0; i < RF_MAXROW; i++)
    138 		for (j = 0; j < RF_MAXCOL; j++)
    139 			k_cfg->devs[i][j] = k50_cfg->devs[i][j];
    140 
    141 	memcpy(k_cfg->devnames, k50_cfg->devnames,
    142 	    sizeof(k_cfg->devnames));
    143 
    144 	for (i = 0; i < RF_MAXSPARE; i++)
    145 		k_cfg->spare_devs[i] = k50_cfg->spare_devs[i];
    146 
    147 	memcpy(k_cfg->spare_names, k50_cfg->spare_names,
    148 	    sizeof(k_cfg->spare_names));
    149 
    150 	k_cfg->sectPerSU = k50_cfg->sectPerSU;
    151 	k_cfg->SUsPerPU = k50_cfg->SUsPerPU;
    152 	k_cfg->SUsPerRU = k50_cfg->SUsPerRU;
    153 	k_cfg->parityConfig = k50_cfg->parityConfig;
    154 
    155 	memcpy(k_cfg->diskQueueType, k50_cfg->diskQueueType,
    156 	    sizeof(k_cfg->diskQueueType));
    157 
    158 	k_cfg->maxOutstandingDiskReqs = k50_cfg->maxOutstandingDiskReqs;
    159 
    160 	memcpy(k_cfg->debugVars, k50_cfg->debugVars,
    161 	    sizeof(k_cfg->debugVars));
    162 
    163 	k_cfg->layoutSpecificSize = k50_cfg->layoutSpecificSize;
    164 	k_cfg->layoutSpecific = k50_cfg->layoutSpecific;
    165 	k_cfg->force = k50_cfg->force;
    166 
    167 	RF_Free(k50_cfg, sizeof(*k50_cfg));
    168 	return rf_construct(rs, k_cfg);
    169 }
    170 
    171 static int
    172 rf_get_info50(RF_Raid_t *raidPtr, void *data)
    173 {
    174 	RF_DeviceConfig50_t **ucfgp = data, *d_cfg;
    175 	size_t i, j;
    176 	int error;
    177 
    178 	if (!raidPtr->valid)
    179 		return ENODEV;
    180 
    181 	d_cfg = RF_Malloc(sizeof(*d_cfg));
    182 
    183 	if (d_cfg == NULL)
    184 		return ENOMEM;
    185 
    186 	d_cfg->rows = 1; /* there is only 1 row now */
    187 	d_cfg->cols = raidPtr->numCol;
    188 	d_cfg->ndevs = raidPtr->numCol;
    189 	if (d_cfg->ndevs >= RF_MAX_DISKS) {
    190 		error = ENOMEM;
    191 		goto out;
    192 	}
    193 
    194 	d_cfg->nspares = raidPtr->numSpare;
    195 	if (d_cfg->nspares >= RF_MAX_DISKS) {
    196 		error = ENOMEM;
    197 		goto out;
    198 	}
    199 
    200 	d_cfg->maxqdepth = raidPtr->maxQueueDepth;
    201 	for (j = 0; j < d_cfg->cols; j++)
    202 		rf_disk_to_disk50(&d_cfg->devs[j], &raidPtr->Disks[j]);
    203 
    204 	for (j = d_cfg->cols, i = 0; i < d_cfg->nspares; i++, j++)
    205 		rf_disk_to_disk50(&d_cfg->spares[i], &raidPtr->Disks[j]);
    206 
    207 	error = copyout(d_cfg, *ucfgp, sizeof(**ucfgp));
    208 
    209 out:
    210 	RF_Free(d_cfg, sizeof(*d_cfg));
    211 	return error;
    212 }
    213 
    214 static int
    215 raidframe_ioctl_50(struct raid_softc *rs, u_long cmd, void *data)
    216 {
    217 	RF_Raid_t *raidPtr = rf_get_raid(rs);
    218 
    219 	switch (cmd) {
    220 	case RAIDFRAME_GET_INFO50:
    221 		if (!rf_inited(rs))
    222 			return ENXIO;
    223 		return rf_get_info50(raidPtr, data);
    224 
    225 	case RAIDFRAME_CONFIGURE50:
    226 		return rf_config50(rs, data);
    227 	default:
    228 		return EPASSTHROUGH;
    229 	}
    230 }
    231 
    232 static void
    233 raidframe_50_init(void)
    234 {
    235 
    236 	MODULE_HOOK_SET(raidframe_ioctl_50_hook, raidframe_ioctl_50);
    237 }
    238 
    239 static void
    240 raidframe_50_fini(void)
    241 {
    242 
    243 	MODULE_HOOK_UNSET(raidframe_ioctl_50_hook);
    244 }
    245 
    246 MODULE(MODULE_CLASS_EXEC, compat_raid_50, "raid,compat_50,compat_raid_80");
    247 
    248 static int
    249 compat_raid_50_modcmd(modcmd_t cmd, void *arg)
    250 {
    251 
    252 	switch (cmd) {
    253 	case MODULE_CMD_INIT:
    254 		raidframe_50_init();
    255 		return 0;
    256 	case MODULE_CMD_FINI:
    257 		raidframe_50_fini();
    258 		return 0;
    259 	default:
    260 		return ENOTTY;
    261 	}
    262 }
    263