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$
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
3759159Smsmith#include <dev/mlx/mlxio.h>
3859159Smsmith#include <dev/mlx/mlxreg.h>
3959138Smsmith
4059138Smsmith#include "mlxcontrol.h"
4159138Smsmith
4259138Smsmithstatic void	print_span(struct mlx_sys_drv_span *span, int arms);
4359138Smsmithstatic void	print_sys_drive(struct conf_config *conf, int drvno);
4459138Smsmithstatic void	print_phys_drive(struct conf_config *conf, int chn, int targ);
4559138Smsmith
4659138Smsmith/********************************************************************************
4759138Smsmith * Get the configuration from the selected controller.
4859138Smsmith *
4959138Smsmith * config <controller>
5059138Smsmith *		Print the configuration for <controller>
5159138Smsmith *
5259138Smsmith * XXX update to support adding/deleting drives.
5359138Smsmith */
5459138Smsmith
5559138Smsmithint
5659138Smsmithcmd_config(int argc, char *argv[])
5759138Smsmith{
5859138Smsmith    struct conf_config	conf;
5959138Smsmith    int			unit = 0;	/* XXX */
6059138Smsmith    int			i, j;
6159138Smsmith
6259138Smsmith    bzero(&conf.cc_cfg, sizeof(conf.cc_cfg));
6359138Smsmith    if (mlx_read_configuration(unit, &conf.cc_cfg)) {
6459138Smsmith	printf("mlx%d: error submitting READ CONFIGURATION\n", unit);
6559138Smsmith    } else {
6659138Smsmith
6759138Smsmith	printf("# Controller <INSERT DETAILS HERE>\n");
6859138Smsmith	printf("#\n# Physical devices connected:\n");
6959138Smsmith	for (i = 0; i < 5; i++)
7059138Smsmith	    for (j = 0; j < 16; j++)
7159138Smsmith	    print_phys_drive(&conf, i, j);
7259138Smsmith	printf("#\n# System Drives defined:\n");
7359138Smsmith
7459138Smsmith	for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
7559138Smsmith	    print_sys_drive(&conf, i);
7659138Smsmith    }
7759138Smsmith    return(0);
7859138Smsmith}
7959138Smsmith
8059138Smsmith
8159138Smsmith/********************************************************************************
8259138Smsmith * Print details for the system drive (drvno) in a format that we will be
8359138Smsmith * able to parse later.
8459138Smsmith *
8559138Smsmith * drive?? <raidlevel> <writemode>
8659138Smsmith *   span? 0x????????-0x???????? ????MB on <disk> [...]
8759138Smsmith *   ...
8859138Smsmith */
8959138Smsmithstatic void
9059138Smsmithprint_span(struct mlx_sys_drv_span *span, int arms)
9159138Smsmith{
9259138Smsmith    int		i;
9359138Smsmith
9459138Smsmith    printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048);
9559138Smsmith    for (i = 0; i < arms; i++)
9659138Smsmith	printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f);
9759138Smsmith    printf("\n");
9859138Smsmith}
9959138Smsmith
10059138Smsmithstatic void
10159138Smsmithprint_sys_drive(struct conf_config *conf, int drvno)
10259138Smsmith{
10359138Smsmith    struct mlx_sys_drv	*drv = &conf->cc_cfg.cc_sys_drives[drvno];
10459138Smsmith    int			i;
10559138Smsmith
10659138Smsmith    printf("drive%02d ", drvno);
10759138Smsmith    switch(drv->sd_raidlevel & 0xf) {
10859138Smsmith    case MLX_SYS_DRV_RAID0:
10959138Smsmith	printf("RAID0");
11059138Smsmith	break;
11159138Smsmith    case MLX_SYS_DRV_RAID1:
11259138Smsmith	printf("RAID1");
11359138Smsmith	break;
11459138Smsmith    case MLX_SYS_DRV_RAID3:
11559138Smsmith	printf("RAID3");
11659138Smsmith	break;
11759138Smsmith    case MLX_SYS_DRV_RAID5:
11859138Smsmith	printf("RAID5");
11959138Smsmith	break;
12059138Smsmith    case MLX_SYS_DRV_RAID6:
12159138Smsmith	printf("RAID6");
12259138Smsmith	break;
12359138Smsmith    case MLX_SYS_DRV_JBOD:
12459138Smsmith	printf("JBOD");
12559138Smsmith	break;
12659138Smsmith    default:
12759138Smsmith	printf("RAID?");
12859138Smsmith    }
12959138Smsmith    printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
13059138Smsmith
13159138Smsmith    for (i = 0; i < drv->sd_valid_spans; i++) {
13259138Smsmith	printf("  span%d ", i);
13359138Smsmith	print_span(&drv->sd_span[i], drv->sd_valid_arms);
13459138Smsmith    }
13559138Smsmith}
13659138Smsmith
13759138Smsmith/********************************************************************************
13859138Smsmith * Print details for the physical drive at chn/targ in a format suitable for
13959138Smsmith * human consumption.
14059138Smsmith *
14159138Smsmith * <type>CCTT (<state>) "<vendor>/<model>"
14259138Smsmith *                       ????MB <features>
14359138Smsmith *
14459138Smsmith */
14559138Smsmithstatic void
14659138Smsmithprint_phys_drive(struct conf_config *conf, int chn, int targ)
14759138Smsmith{
14859138Smsmith    struct mlx_phys_drv		*drv = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
14959138Smsmith
15059138Smsmith    /* if the drive isn't present, don't print it */
15159138Smsmith    if (!(drv->pd_flags1 & MLX_PHYS_DRV_PRESENT))
15259138Smsmith	return;
15359138Smsmith
15459138Smsmith    mlx_print_phys_drv(drv, chn, targ, "# ", 1);
15559138Smsmith}
15659138Smsmith
15759138Smsmith
158