Home | History | Annotate | Line # | Download | only in mlxctl
config.c revision 1.3
      1  1.3  hubertf /*	$NetBSD: config.c,v 1.3 2007/02/21 20:53:59 hubertf 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.3  hubertf __RCSID("$NetBSD: config.c,v 1.3 2007/02/21 20:53:59 hubertf 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 <unistd.h>
     86  1.1       ad #include <getopt.h>
     87  1.1       ad 
     88  1.1       ad #include "extern.h"
     89  1.1       ad 
     90  1.1       ad struct conf_phys_drv {
     91  1.1       ad 	TAILQ_ENTRY(conf_phys_drv)	pd_link;
     92  1.1       ad 	int				pd_bus;
     93  1.1       ad 	int				pd_target;
     94  1.1       ad 	struct mlx_phys_drv		pd_drv;
     95  1.1       ad };
     96  1.1       ad 
     97  1.1       ad struct conf_span {
     98  1.1       ad 	TAILQ_ENTRY(conf_span)		s_link;
     99  1.1       ad 	struct conf_phys_drv		*s_drvs[8];
    100  1.1       ad 	struct mlx_sys_drv_span		s_span;
    101  1.1       ad };
    102  1.1       ad 
    103  1.1       ad struct conf_sys_drv {
    104  1.1       ad 	TAILQ_ENTRY(conf_sys_drv)	sd_link;
    105  1.1       ad 	struct conf_span		*sd_spans[4];
    106  1.1       ad 	struct mlx_sys_drv		sd_drv;
    107  1.1       ad };
    108  1.1       ad 
    109  1.1       ad struct conf_config {
    110  1.1       ad 	TAILQ_HEAD(,conf_phys_drv)	cc_phys_drvs;
    111  1.1       ad 	TAILQ_HEAD(,conf_span)		cc_spans;
    112  1.1       ad 	TAILQ_HEAD(,conf_sys_drv)	cc_sys_drvs;
    113  1.1       ad 	struct conf_sys_drv		*cc_drives[32];
    114  1.1       ad 	struct mlx_core_cfg		cc_cfg;
    115  1.1       ad };
    116  1.1       ad 
    117  1.1       ad static void	print_span(struct mlx_sys_drv_span *, int);
    118  1.1       ad static void	print_sys_drive(struct conf_config *, int);
    119  1.1       ad static void	print_phys_drive(struct conf_config *, int, int);
    120  1.1       ad 
    121  1.1       ad /*
    122  1.1       ad  * Get the configuration from the selected controller.
    123  1.1       ad  *
    124  1.1       ad  * config <controller>
    125  1.1       ad  *		Print the configuration for <controller>
    126  1.1       ad  *
    127  1.1       ad  * XXX update to support adding/deleting drives.
    128  1.1       ad  */
    129  1.1       ad int
    130  1.1       ad cmd_config(char **argv)
    131  1.1       ad {
    132  1.1       ad 	char hostname[MAXHOSTNAMELEN];
    133  1.1       ad 	struct conf_config conf;
    134  1.1       ad 	int i, j;
    135  1.2       ad 
    136  1.2       ad 	if (ci.ci_firmware_id[0] < 3) {
    137  1.2       ad 		warnx("action not supported by this firmware version");
    138  1.2       ad 		return (1);
    139  1.2       ad 	}
    140  1.1       ad 
    141  1.1       ad 	memset(&conf.cc_cfg, 0, sizeof(conf.cc_cfg));
    142  1.1       ad 	mlx_configuration(&conf.cc_cfg, 0);
    143  1.1       ad 
    144  1.1       ad 	gethostname(hostname, sizeof(hostname));
    145  1.1       ad 	printf("# controller %s on %s\n", mlxname, hostname);
    146  1.1       ad 
    147  1.1       ad 	printf("#\n# physical devices connected:\n");
    148  1.1       ad 	for (i = 0; i < 5; i++)
    149  1.1       ad 		for (j = 0; j < 16; j++)
    150  1.1       ad 			print_phys_drive(&conf, i, j);
    151  1.1       ad 
    152  1.1       ad 	printf("#\n# system drives defined:\n");
    153  1.1       ad 	for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
    154  1.1       ad 		print_sys_drive(&conf, i);
    155  1.1       ad 
    156  1.1       ad 	return(0);
    157  1.1       ad }
    158  1.1       ad 
    159  1.1       ad /*
    160  1.1       ad  * Print details for the system drive (drvno) in a format that we will be
    161  1.1       ad  * able to parse later.
    162  1.1       ad  *
    163  1.1       ad  * drive?? <raidlevel> <writemode>
    164  1.1       ad  *   span? 0x????????-0x???????? ????blks on <disk> [...]
    165  1.1       ad  *   ...
    166  1.1       ad  */
    167  1.1       ad static void
    168  1.1       ad print_span(struct mlx_sys_drv_span *span, int arms)
    169  1.1       ad {
    170  1.1       ad 	int i;
    171  1.1       ad 
    172  1.1       ad 	printf("0x%08x-0x%08x %u blks on", span->sp_start_lba,
    173  1.1       ad 	    span->sp_start_lba + span->sp_nblks, span->sp_nblks);
    174  1.1       ad 
    175  1.1       ad 	for (i = 0; i < arms; i++)
    176  1.1       ad 		printf(" disk%02d%02d", span->sp_arm[i] >> 4,
    177  1.1       ad 		    span->sp_arm[i] & 0x0f);
    178  1.1       ad 
    179  1.1       ad 	printf("\n");
    180  1.1       ad }
    181  1.1       ad 
    182  1.1       ad static void
    183  1.1       ad print_sys_drive(struct conf_config *conf, int drvno)
    184  1.1       ad {
    185  1.1       ad 	struct mlx_sys_drv *drv;
    186  1.1       ad 	int i;
    187  1.1       ad 
    188  1.1       ad 	drv = &conf->cc_cfg.cc_sys_drives[drvno];
    189  1.1       ad 
    190  1.1       ad 	printf("drive%02d ", drvno);
    191  1.1       ad 
    192  1.1       ad 	switch(drv->sd_raidlevel & 0xf) {
    193  1.1       ad 	case MLX_SYS_DRV_RAID0:
    194  1.1       ad 		printf("RAID0");
    195  1.1       ad 		break;
    196  1.1       ad 	 case MLX_SYS_DRV_RAID1:
    197  1.1       ad 		printf("RAID1");
    198  1.1       ad 		break;
    199  1.1       ad 	case MLX_SYS_DRV_RAID3:
    200  1.1       ad 		printf("RAID3");
    201  1.1       ad 		break;
    202  1.1       ad 	case MLX_SYS_DRV_RAID5:
    203  1.1       ad 		printf("RAID5");
    204  1.1       ad 		break;
    205  1.1       ad 	case MLX_SYS_DRV_RAID6:
    206  1.1       ad 		printf("RAID6");
    207  1.1       ad 		break;
    208  1.1       ad 	case MLX_SYS_DRV_JBOD:
    209  1.1       ad 		printf("JBOD");
    210  1.1       ad 		break;
    211  1.1       ad 	default:
    212  1.1       ad 		printf("RAID?");
    213  1.1       ad 		break;
    214  1.1       ad 	}
    215  1.1       ad 
    216  1.1       ad 	printf(" write%s\n",
    217  1.1       ad 	    drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
    218  1.1       ad 
    219  1.1       ad 	for (i = 0; i < drv->sd_valid_spans; i++) {
    220  1.1       ad 		printf("  span%d ", i);
    221  1.1       ad 		print_span(&drv->sd_span[i], drv->sd_valid_arms);
    222  1.1       ad 	}
    223  1.1       ad }
    224  1.1       ad 
    225  1.1       ad /*
    226  1.1       ad  * Print details for the physical drive at chn/targ in a format suitable for
    227  1.1       ad  * human consumption.
    228  1.1       ad  */
    229  1.1       ad static void
    230  1.1       ad print_phys_drive(struct conf_config *conf, int chn, int targ)
    231  1.1       ad {
    232  1.1       ad 	struct mlx_phys_drv *pd;
    233  1.1       ad 
    234  1.1       ad 	pd = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
    235  1.1       ad 
    236  1.1       ad 	/* If the drive isn't present, don't print it. */
    237  1.1       ad 	if ((pd->pd_flags1 & MLX_PHYS_DRV_PRESENT) == 0)
    238  1.1       ad 		return;
    239  1.1       ad 
    240  1.1       ad 	mlx_print_phys_drv(pd, chn, targ, "# ");
    241  1.1       ad }
    242