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