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