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