config.c revision 59138
159138Smsmith/*-
259138Smsmith * Copyright (c) 1999 Michael Smith
359138Smsmith * All rights reserved.
459138Smsmith *
559138Smsmith * Redistribution and use in source and binary forms, with or without
659138Smsmith * modification, are permitted provided that the following conditions
759138Smsmith * are met:
859138Smsmith * 1. Redistributions of source code must retain the above copyright
959138Smsmith *    notice, this list of conditions and the following disclaimer.
1059138Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1159138Smsmith *    notice, this list of conditions and the following disclaimer in the
1259138Smsmith *    documentation and/or other materials provided with the distribution.
1359138Smsmith *
1459138Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1559138Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1659138Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1759138Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1859138Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1959138Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2059138Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2159138Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2259138Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2359138Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2459138Smsmith * SUCH DAMAGE.
2559138Smsmith *
2659138Smsmith *	$FreeBSD: cvs2svn/branches/MSMITH/usr.sbin/mlxcontrol/config.c 59138 2000-04-11 03:01:45Z msmith $
2759138Smsmith */
2859138Smsmith
2959138Smsmith#include <fcntl.h>
3059138Smsmith#include <paths.h>
3159138Smsmith#include <stdio.h>
3259138Smsmith#include <stdlib.h>
3359138Smsmith#include <string.h>
3459138Smsmith#include <unistd.h>
3559138Smsmith#include <err.h>
3659138Smsmith
3759138Smsmith#if 0
3859138Smsmith#include <sys/mlxio.h>
3959138Smsmith#include <sys/mlxreg.h>
4059138Smsmith#else
4159138Smsmith#include "../sys/dev/mlx/mlxio.h"
4259138Smsmith#include "../sys/dev/mlx/mlxreg.h"
4359138Smsmith#endif
4459138Smsmith
4559138Smsmith#include "mlxcontrol.h"
4659138Smsmith
4759138Smsmithstatic void	print_span(struct mlx_sys_drv_span *span, int arms);
4859138Smsmithstatic void	print_sys_drive(struct conf_config *conf, int drvno);
4959138Smsmithstatic void	print_phys_drive(struct conf_config *conf, int chn, int targ);
5059138Smsmith
5159138Smsmith/********************************************************************************
5259138Smsmith * Get the configuration from the selected controller.
5359138Smsmith *
5459138Smsmith * config <controller>
5559138Smsmith *		Print the configuration for <controller>
5659138Smsmith *
5759138Smsmith * XXX update to support adding/deleting drives.
5859138Smsmith */
5959138Smsmith
6059138Smsmithint
6159138Smsmithcmd_config(int argc, char *argv[])
6259138Smsmith{
6359138Smsmith    struct conf_config	conf;
6459138Smsmith    int			unit = 0;	/* XXX */
6559138Smsmith    int			i, j;
6659138Smsmith
6759138Smsmith    bzero(&conf.cc_cfg, sizeof(conf.cc_cfg));
6859138Smsmith    if (mlx_read_configuration(unit, &conf.cc_cfg)) {
6959138Smsmith	printf("mlx%d: error submitting READ CONFIGURATION\n", unit);
7059138Smsmith    } else {
7159138Smsmith
7259138Smsmith	printf("# Controller <INSERT DETAILS HERE>\n");
7359138Smsmith	printf("#\n# Physical devices connected:\n");
7459138Smsmith	for (i = 0; i < 5; i++)
7559138Smsmith	    for (j = 0; j < 16; j++)
7659138Smsmith	    print_phys_drive(&conf, i, j);
7759138Smsmith	printf("#\n# System Drives defined:\n");
7859138Smsmith
7959138Smsmith	for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
8059138Smsmith	    print_sys_drive(&conf, i);
8159138Smsmith    }
8259138Smsmith    return(0);
8359138Smsmith}
8459138Smsmith
8559138Smsmith
8659138Smsmith/********************************************************************************
8759138Smsmith * Print details for the system drive (drvno) in a format that we will be
8859138Smsmith * able to parse later.
8959138Smsmith *
9059138Smsmith * drive?? <raidlevel> <writemode>
9159138Smsmith *   span? 0x????????-0x???????? ????MB on <disk> [...]
9259138Smsmith *   ...
9359138Smsmith */
9459138Smsmithstatic void
9559138Smsmithprint_span(struct mlx_sys_drv_span *span, int arms)
9659138Smsmith{
9759138Smsmith    int		i;
9859138Smsmith
9959138Smsmith    printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048);
10059138Smsmith    for (i = 0; i < arms; i++)
10159138Smsmith	printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f);
10259138Smsmith    printf("\n");
10359138Smsmith}
10459138Smsmith
10559138Smsmithstatic void
10659138Smsmithprint_sys_drive(struct conf_config *conf, int drvno)
10759138Smsmith{
10859138Smsmith    struct mlx_sys_drv	*drv = &conf->cc_cfg.cc_sys_drives[drvno];
10959138Smsmith    int			i;
11059138Smsmith
11159138Smsmith    printf("drive%02d ", drvno);
11259138Smsmith    switch(drv->sd_raidlevel & 0xf) {
11359138Smsmith    case MLX_SYS_DRV_RAID0:
11459138Smsmith	printf("RAID0");
11559138Smsmith	break;
11659138Smsmith    case MLX_SYS_DRV_RAID1:
11759138Smsmith	printf("RAID1");
11859138Smsmith	break;
11959138Smsmith    case MLX_SYS_DRV_RAID3:
12059138Smsmith	printf("RAID3");
12159138Smsmith	break;
12259138Smsmith    case MLX_SYS_DRV_RAID5:
12359138Smsmith	printf("RAID5");
12459138Smsmith	break;
12559138Smsmith    case MLX_SYS_DRV_RAID6:
12659138Smsmith	printf("RAID6");
12759138Smsmith	break;
12859138Smsmith    case MLX_SYS_DRV_JBOD:
12959138Smsmith	printf("JBOD");
13059138Smsmith	break;
13159138Smsmith    default:
13259138Smsmith	printf("RAID?");
13359138Smsmith    }
13459138Smsmith    printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
13559138Smsmith
13659138Smsmith    for (i = 0; i < drv->sd_valid_spans; i++) {
13759138Smsmith	printf("  span%d ", i);
13859138Smsmith	print_span(&drv->sd_span[i], drv->sd_valid_arms);
13959138Smsmith    }
14059138Smsmith}
14159138Smsmith
14259138Smsmith/********************************************************************************
14359138Smsmith * Print details for the physical drive at chn/targ in a format suitable for
14459138Smsmith * human consumption.
14559138Smsmith *
14659138Smsmith * <type>CCTT (<state>) "<vendor>/<model>"
14759138Smsmith *                       ????MB <features>
14859138Smsmith *
14959138Smsmith */
15059138Smsmithstatic void
15159138Smsmithprint_phys_drive(struct conf_config *conf, int chn, int targ)
15259138Smsmith{
15359138Smsmith    struct mlx_phys_drv		*drv = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
15459138Smsmith
15559138Smsmith    /* if the drive isn't present, don't print it */
15659138Smsmith    if (!(drv->pd_flags1 & MLX_PHYS_DRV_PRESENT))
15759138Smsmith	return;
15859138Smsmith
15959138Smsmith    mlx_print_phys_drv(drv, chn, targ, "# ", 1);
16059138Smsmith}
16159138Smsmith
16259138Smsmith
163