Home | History | Annotate | Line # | Download | only in mlxctl
config.c revision 1.2
      1 /*	$NetBSD: config.c,v 1.2 2002/08/26 17:04:18 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      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 /*-
     40  * Copyright (c) 1999 Michael Smith
     41  * All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  * SUCH DAMAGE.
     63  *
     64  * from FreeBSD: config.c,v 1.2 2000/04/11 23:04:17 msmith Exp
     65  */
     66 
     67 #ifndef lint
     68 #include <sys/cdefs.h>
     69 __RCSID("$NetBSD: config.c,v 1.2 2002/08/26 17:04:18 ad Exp $");
     70 #endif /* not lint */
     71 
     72 #include <sys/types.h>
     73 #include <sys/param.h>
     74 #include <sys/ioctl.h>
     75 #include <sys/queue.h>
     76 
     77 #include <dev/ic/mlxreg.h>
     78 #include <dev/ic/mlxio.h>
     79 
     80 #include <err.h>
     81 #include <fcntl.h>
     82 #include <stdio.h>
     83 #include <stdlib.h>
     84 #include <string.h>
     85 #include <ctype.h>
     86 #include <unistd.h>
     87 #include <getopt.h>
     88 
     89 #include "extern.h"
     90 
     91 struct conf_phys_drv {
     92 	TAILQ_ENTRY(conf_phys_drv)	pd_link;
     93 	int				pd_bus;
     94 	int				pd_target;
     95 	struct mlx_phys_drv		pd_drv;
     96 };
     97 
     98 struct conf_span {
     99 	TAILQ_ENTRY(conf_span)		s_link;
    100 	struct conf_phys_drv		*s_drvs[8];
    101 	struct mlx_sys_drv_span		s_span;
    102 };
    103 
    104 struct conf_sys_drv {
    105 	TAILQ_ENTRY(conf_sys_drv)	sd_link;
    106 	struct conf_span		*sd_spans[4];
    107 	struct mlx_sys_drv		sd_drv;
    108 };
    109 
    110 struct conf_config {
    111 	TAILQ_HEAD(,conf_phys_drv)	cc_phys_drvs;
    112 	TAILQ_HEAD(,conf_span)		cc_spans;
    113 	TAILQ_HEAD(,conf_sys_drv)	cc_sys_drvs;
    114 	struct conf_sys_drv		*cc_drives[32];
    115 	struct mlx_core_cfg		cc_cfg;
    116 };
    117 
    118 static void	print_span(struct mlx_sys_drv_span *, int);
    119 static void	print_sys_drive(struct conf_config *, int);
    120 static void	print_phys_drive(struct conf_config *, int, int);
    121 
    122 /*
    123  * Get the configuration from the selected controller.
    124  *
    125  * config <controller>
    126  *		Print the configuration for <controller>
    127  *
    128  * XXX update to support adding/deleting drives.
    129  */
    130 int
    131 cmd_config(char **argv)
    132 {
    133 	char hostname[MAXHOSTNAMELEN];
    134 	struct conf_config conf;
    135 	int i, j;
    136 
    137 	if (ci.ci_firmware_id[0] < 3) {
    138 		warnx("action not supported by this firmware version");
    139 		return (1);
    140 	}
    141 
    142 	memset(&conf.cc_cfg, 0, sizeof(conf.cc_cfg));
    143 	mlx_configuration(&conf.cc_cfg, 0);
    144 
    145 	gethostname(hostname, sizeof(hostname));
    146 	printf("# controller %s on %s\n", mlxname, hostname);
    147 
    148 	printf("#\n# physical devices connected:\n");
    149 	for (i = 0; i < 5; i++)
    150 		for (j = 0; j < 16; j++)
    151 			print_phys_drive(&conf, i, j);
    152 
    153 	printf("#\n# system drives defined:\n");
    154 	for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
    155 		print_sys_drive(&conf, i);
    156 
    157 	return(0);
    158 }
    159 
    160 /*
    161  * Print details for the system drive (drvno) in a format that we will be
    162  * able to parse later.
    163  *
    164  * drive?? <raidlevel> <writemode>
    165  *   span? 0x????????-0x???????? ????blks on <disk> [...]
    166  *   ...
    167  */
    168 static void
    169 print_span(struct mlx_sys_drv_span *span, int arms)
    170 {
    171 	int i;
    172 
    173 	printf("0x%08x-0x%08x %u blks on", span->sp_start_lba,
    174 	    span->sp_start_lba + span->sp_nblks, span->sp_nblks);
    175 
    176 	for (i = 0; i < arms; i++)
    177 		printf(" disk%02d%02d", span->sp_arm[i] >> 4,
    178 		    span->sp_arm[i] & 0x0f);
    179 
    180 	printf("\n");
    181 }
    182 
    183 static void
    184 print_sys_drive(struct conf_config *conf, int drvno)
    185 {
    186 	struct mlx_sys_drv *drv;
    187 	int i;
    188 
    189 	drv = &conf->cc_cfg.cc_sys_drives[drvno];
    190 
    191 	printf("drive%02d ", drvno);
    192 
    193 	switch(drv->sd_raidlevel & 0xf) {
    194 	case MLX_SYS_DRV_RAID0:
    195 		printf("RAID0");
    196 		break;
    197 	 case MLX_SYS_DRV_RAID1:
    198 		printf("RAID1");
    199 		break;
    200 	case MLX_SYS_DRV_RAID3:
    201 		printf("RAID3");
    202 		break;
    203 	case MLX_SYS_DRV_RAID5:
    204 		printf("RAID5");
    205 		break;
    206 	case MLX_SYS_DRV_RAID6:
    207 		printf("RAID6");
    208 		break;
    209 	case MLX_SYS_DRV_JBOD:
    210 		printf("JBOD");
    211 		break;
    212 	default:
    213 		printf("RAID?");
    214 		break;
    215 	}
    216 
    217 	printf(" write%s\n",
    218 	    drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
    219 
    220 	for (i = 0; i < drv->sd_valid_spans; i++) {
    221 		printf("  span%d ", i);
    222 		print_span(&drv->sd_span[i], drv->sd_valid_arms);
    223 	}
    224 }
    225 
    226 /*
    227  * Print details for the physical drive at chn/targ in a format suitable for
    228  * human consumption.
    229  */
    230 static void
    231 print_phys_drive(struct conf_config *conf, int chn, int targ)
    232 {
    233 	struct mlx_phys_drv *pd;
    234 
    235 	pd = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
    236 
    237 	/* If the drive isn't present, don't print it. */
    238 	if ((pd->pd_flags1 & MLX_PHYS_DRV_PRESENT) == 0)
    239 		return;
    240 
    241 	mlx_print_phys_drv(pd, chn, targ, "# ");
    242 }
    243