2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1999 Michael Smith
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <dev/mlx/mlxio.h>
40 #include <dev/mlx/mlxreg.h>
42 #include "mlxcontrol.h"
44 static void print_span(struct mlx_sys_drv_span *span, int arms);
45 static void print_sys_drive(struct conf_config *conf, int drvno);
46 static void print_phys_drive(struct conf_config *conf, int chn, int targ);
48 /********************************************************************************
49 * Get the configuration from the selected controller.
52 * Print the configuration for <controller>
54 * XXX update to support adding/deleting drives.
58 cmd_config(int argc, char *argv[])
60 struct conf_config conf;
61 int unit = 0; /* XXX */
64 bzero(&conf.cc_cfg, sizeof(conf.cc_cfg));
65 if (mlx_read_configuration(unit, &conf.cc_cfg)) {
66 printf("mlx%d: error submitting READ CONFIGURATION\n", unit);
69 printf("# Controller <INSERT DETAILS HERE>\n");
70 printf("#\n# Physical devices connected:\n");
71 for (i = 0; i < 5; i++)
72 for (j = 0; j < 16; j++)
73 print_phys_drive(&conf, i, j);
74 printf("#\n# System Drives defined:\n");
76 for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
77 print_sys_drive(&conf, i);
83 /********************************************************************************
84 * Print details for the system drive (drvno) in a format that we will be
85 * able to parse later.
87 * drive?? <raidlevel> <writemode>
88 * span? 0x????????-0x???????? ????MB on <disk> [...]
92 print_span(struct mlx_sys_drv_span *span, int arms)
96 printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048);
97 for (i = 0; i < arms; i++)
98 printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f);
103 print_sys_drive(struct conf_config *conf, int drvno)
105 struct mlx_sys_drv *drv = &conf->cc_cfg.cc_sys_drives[drvno];
108 printf("drive%02d ", drvno);
109 switch(drv->sd_raidlevel & 0xf) {
110 case MLX_SYS_DRV_RAID0:
113 case MLX_SYS_DRV_RAID1:
116 case MLX_SYS_DRV_RAID3:
119 case MLX_SYS_DRV_RAID5:
122 case MLX_SYS_DRV_RAID6:
125 case MLX_SYS_DRV_JBOD:
131 printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
133 for (i = 0; i < drv->sd_valid_spans; i++) {
134 printf(" span%d ", i);
135 print_span(&drv->sd_span[i], drv->sd_valid_arms);
139 /********************************************************************************
140 * Print details for the physical drive at chn/targ in a format suitable for
143 * <type>CCTT (<state>) "<vendor>/<model>"
148 print_phys_drive(struct conf_config *conf, int chn, int targ)
150 struct mlx_phys_drv *drv = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
152 /* if the drive isn't present, don't print it */
153 if (!(drv->pd_flags1 & MLX_PHYS_DRV_PRESENT))
156 mlx_print_phys_drv(drv, chn, targ, "# ", 1);