11844Swollman/*-
250476Speter * Copyright (c) 1999 Michael Smith
323549Swosch * All rights reserved.
423549Swosch *
5139761Skrion * Redistribution and use in source and binary forms, with or without
623549Swosch * modification, are permitted provided that the following conditions
723549Swosch * are met:
823549Swosch * 1. Redistributions of source code must retain the above copyright
923549Swosch *    notice, this list of conditions and the following disclaimer.
1023549Swosch * 2. Redistributions in binary form must reproduce the above copyright
1123549Swosch *    notice, this list of conditions and the following disclaimer in the
1223549Swosch *    documentation and/or other materials provided with the distribution.
1323549Swosch *
1423549Swosch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1595327Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1623549Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1723549Swosch * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1823549Swosch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1923549Swosch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2023549Swosch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2123549Swosch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2223549Swosch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2323549Swosch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2423549Swosch * SUCH DAMAGE.
2523549Swosch *
2623549Swosch *	$FreeBSD$
27313790Sngie */
28200178Sed
29313790Sngie#include <fcntl.h>
3023549Swosch#include <paths.h>
311638Srgrimes#include <stdio.h>
32242711Ssjg#include <stdlib.h>
33242711Ssjg#include <string.h>
34242711Ssjg#include <unistd.h>
3594940Sru#include <err.h>
3623549Swosch
3799875Sru#include <dev/mlx/mlxio.h>
3899875Sru#include <dev/mlx/mlxreg.h>
39251749Ssjg
4099875Sru#include "mlxcontrol.h"
41133369Sharti
4299875Srustatic void	print_span(struct mlx_sys_drv_span *span, int arms);
4399875Srustatic void	print_sys_drive(struct conf_config *conf, int drvno);
4499875Srustatic void	print_phys_drive(struct conf_config *conf, int chn, int targ);
4599875Sru
46251749Ssjg/********************************************************************************
4799875Sru * Get the configuration from the selected controller.
48313789Sngie *
4995306Sru * config <controller>
50270187Sian *		Print the configuration for <controller>
5190311Sru *
5290311Sru * XXX update to support adding/deleting drives.
5390311Sru */
54270187Sian
5590311Sruint
5690311Srucmd_config(int argc, char *argv[])
5790311Sru{
58270187Sian    struct conf_config	conf;
5995306Sru    int			unit = 0;	/* XXX */
601638Srgrimes    int			i, j;
6195306Sru
621638Srgrimes    bzero(&conf.cc_cfg, sizeof(conf.cc_cfg));
63265934Sian    if (mlx_read_configuration(unit, &conf.cc_cfg)) {
64133369Sharti	printf("mlx%d: error submitting READ CONFIGURATION\n", unit);
6553152Smarcel    } else {
661638Srgrimes
671638Srgrimes	printf("# Controller <INSERT DETAILS HERE>\n");
681638Srgrimes	printf("#\n# Physical devices connected:\n");
69146817Sru	for (i = 0; i < 5; i++)
701638Srgrimes	    for (j = 0; j < 16; j++)
71265934Sian	    print_phys_drive(&conf, i, j);
72265934Sian	printf("#\n# System Drives defined:\n");
73313790Sngie
74200178Sed	for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
75313790Sngie	    print_sys_drive(&conf, i);
76264303Sdim    }
77265934Sian    return(0);
78264303Sdim}
79265934Sian
80265934Sian
81265934Sian/********************************************************************************
82265934Sian * Print details for the system drive (drvno) in a format that we will be
83270187Sian * able to parse later.
84270187Sian *
85270187Sian * drive?? <raidlevel> <writemode>
86270187Sian *   span? 0x????????-0x???????? ????MB on <disk> [...]
87291777Sbdrewery *   ...
88270187Sian */
89313789Sngiestatic void
90264303Sdimprint_span(struct mlx_sys_drv_span *span, int arms)
91264303Sdim{
92264303Sdim    int		i;
93264303Sdim
94264303Sdim    printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048);
95264303Sdim    for (i = 0; i < arms; i++)
96264303Sdim	printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f);
97264303Sdim    printf("\n");
98264303Sdim}
99264303Sdim
100265934Sianstatic void
101270187Sianprint_sys_drive(struct conf_config *conf, int drvno)
102264303Sdim{
103265934Sian    struct mlx_sys_drv	*drv = &conf->cc_cfg.cc_sys_drives[drvno];
104264303Sdim    int			i;
105270187Sian
106270187Sian    printf("drive%02d ", drvno);
107264303Sdim    switch(drv->sd_raidlevel & 0xf) {
10815061Swosch    case MLX_SYS_DRV_RAID0:
1091638Srgrimes	printf("RAID0");
11097769Sru	break;
11196668Sru    case MLX_SYS_DRV_RAID1:
11296668Sru	printf("RAID1");
11396668Sru	break;
114270187Sian    case MLX_SYS_DRV_RAID3:
115270187Sian	printf("RAID3");
11696668Sru	break;
11796668Sru    case MLX_SYS_DRV_RAID5:
118270187Sian	printf("RAID5");
119251749Ssjg	break;
120313789Sngie    case MLX_SYS_DRV_RAID6:
121270187Sian	printf("RAID6");
12296668Sru	break;
12396668Sru    case MLX_SYS_DRV_JBOD:
1241638Srgrimes	printf("JBOD");
1251638Srgrimes	break;
1261638Srgrimes    default:
1271638Srgrimes	printf("RAID?");
1281638Srgrimes    }
1291638Srgrimes    printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
1301638Srgrimes
13199215Sru    for (i = 0; i < drv->sd_valid_spans; i++) {
13299215Sru	printf("  span%d ", i);
1331638Srgrimes	print_span(&drv->sd_span[i], drv->sd_valid_arms);
134242711Ssjg    }
135242711Ssjg}
136
137/********************************************************************************
138 * Print details for the physical drive at chn/targ in a format suitable for
139 * human consumption.
140 *
141 * <type>CCTT (<state>) "<vendor>/<model>"
142 *                       ????MB <features>
143 *
144 */
145static void
146print_phys_drive(struct conf_config *conf, int chn, int targ)
147{
148    struct mlx_phys_drv		*drv = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
149
150    /* if the drive isn't present, don't print it */
151    if (!(drv->pd_flags1 & MLX_PHYS_DRV_PRESENT))
152	return;
153
154    mlx_print_phys_drv(drv, chn, targ, "# ", 1);
155}
156
157
158