1b6a7bef2SMike Smith /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni *
4b6a7bef2SMike Smith * Copyright (c) 1999 Michael Smith
5b6a7bef2SMike Smith * All rights reserved.
6b6a7bef2SMike Smith *
7b6a7bef2SMike Smith * Redistribution and use in source and binary forms, with or without
8b6a7bef2SMike Smith * modification, are permitted provided that the following conditions
9b6a7bef2SMike Smith * are met:
10b6a7bef2SMike Smith * 1. Redistributions of source code must retain the above copyright
11b6a7bef2SMike Smith * notice, this list of conditions and the following disclaimer.
12b6a7bef2SMike Smith * 2. Redistributions in binary form must reproduce the above copyright
13b6a7bef2SMike Smith * notice, this list of conditions and the following disclaimer in the
14b6a7bef2SMike Smith * documentation and/or other materials provided with the distribution.
15b6a7bef2SMike Smith *
16b6a7bef2SMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17b6a7bef2SMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b6a7bef2SMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b6a7bef2SMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20b6a7bef2SMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b6a7bef2SMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22b6a7bef2SMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23b6a7bef2SMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24b6a7bef2SMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b6a7bef2SMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b6a7bef2SMike Smith * SUCH DAMAGE.
27b6a7bef2SMike Smith */
28b6a7bef2SMike Smith
29b6a7bef2SMike Smith #include <fcntl.h>
30b6a7bef2SMike Smith #include <paths.h>
31b6a7bef2SMike Smith #include <stdio.h>
32b6a7bef2SMike Smith #include <stdlib.h>
33b6a7bef2SMike Smith #include <string.h>
34b6a7bef2SMike Smith #include <unistd.h>
35b6a7bef2SMike Smith #include <err.h>
36b6a7bef2SMike Smith
37bb441a15SMike Smith #include <dev/mlx/mlxio.h>
38bb441a15SMike Smith #include <dev/mlx/mlxreg.h>
39b6a7bef2SMike Smith
40b6a7bef2SMike Smith #include "mlxcontrol.h"
41b6a7bef2SMike Smith
42b6a7bef2SMike Smith static void print_span(struct mlx_sys_drv_span *span, int arms);
43b6a7bef2SMike Smith static void print_sys_drive(struct conf_config *conf, int drvno);
44b6a7bef2SMike Smith static void print_phys_drive(struct conf_config *conf, int chn, int targ);
45b6a7bef2SMike Smith
46b6a7bef2SMike Smith /********************************************************************************
47b6a7bef2SMike Smith * Get the configuration from the selected controller.
48b6a7bef2SMike Smith *
49b6a7bef2SMike Smith * config <controller>
50b6a7bef2SMike Smith * Print the configuration for <controller>
51b6a7bef2SMike Smith *
52b6a7bef2SMike Smith * XXX update to support adding/deleting drives.
53b6a7bef2SMike Smith */
54b6a7bef2SMike Smith
55b6a7bef2SMike Smith int
cmd_config(int argc,char * argv[])56b6a7bef2SMike Smith cmd_config(int argc, char *argv[])
57b6a7bef2SMike Smith {
58b6a7bef2SMike Smith struct conf_config conf;
59b6a7bef2SMike Smith int unit = 0; /* XXX */
60b6a7bef2SMike Smith int i, j;
61b6a7bef2SMike Smith
62b6a7bef2SMike Smith bzero(&conf.cc_cfg, sizeof(conf.cc_cfg));
63b6a7bef2SMike Smith if (mlx_read_configuration(unit, &conf.cc_cfg)) {
64b6a7bef2SMike Smith printf("mlx%d: error submitting READ CONFIGURATION\n", unit);
65b6a7bef2SMike Smith } else {
66b6a7bef2SMike Smith
67b6a7bef2SMike Smith printf("# Controller <INSERT DETAILS HERE>\n");
68b6a7bef2SMike Smith printf("#\n# Physical devices connected:\n");
69b6a7bef2SMike Smith for (i = 0; i < 5; i++)
70b6a7bef2SMike Smith for (j = 0; j < 16; j++)
71b6a7bef2SMike Smith print_phys_drive(&conf, i, j);
72b6a7bef2SMike Smith printf("#\n# System Drives defined:\n");
73b6a7bef2SMike Smith
74b6a7bef2SMike Smith for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
75b6a7bef2SMike Smith print_sys_drive(&conf, i);
76b6a7bef2SMike Smith }
77b6a7bef2SMike Smith return(0);
78b6a7bef2SMike Smith }
79b6a7bef2SMike Smith
80b6a7bef2SMike Smith
81b6a7bef2SMike Smith /********************************************************************************
82b6a7bef2SMike Smith * Print details for the system drive (drvno) in a format that we will be
83b6a7bef2SMike Smith * able to parse later.
84b6a7bef2SMike Smith *
85b6a7bef2SMike Smith * drive?? <raidlevel> <writemode>
86b6a7bef2SMike Smith * span? 0x????????-0x???????? ????MB on <disk> [...]
87b6a7bef2SMike Smith * ...
88b6a7bef2SMike Smith */
89b6a7bef2SMike Smith static void
print_span(struct mlx_sys_drv_span * span,int arms)90b6a7bef2SMike Smith print_span(struct mlx_sys_drv_span *span, int arms)
91b6a7bef2SMike Smith {
92b6a7bef2SMike Smith int i;
93b6a7bef2SMike Smith
94b6a7bef2SMike Smith printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048);
95b6a7bef2SMike Smith for (i = 0; i < arms; i++)
96b6a7bef2SMike Smith printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f);
97b6a7bef2SMike Smith printf("\n");
98b6a7bef2SMike Smith }
99b6a7bef2SMike Smith
100b6a7bef2SMike Smith static void
print_sys_drive(struct conf_config * conf,int drvno)101b6a7bef2SMike Smith print_sys_drive(struct conf_config *conf, int drvno)
102b6a7bef2SMike Smith {
103b6a7bef2SMike Smith struct mlx_sys_drv *drv = &conf->cc_cfg.cc_sys_drives[drvno];
104b6a7bef2SMike Smith int i;
105b6a7bef2SMike Smith
106b6a7bef2SMike Smith printf("drive%02d ", drvno);
107b6a7bef2SMike Smith switch(drv->sd_raidlevel & 0xf) {
108b6a7bef2SMike Smith case MLX_SYS_DRV_RAID0:
109b6a7bef2SMike Smith printf("RAID0");
110b6a7bef2SMike Smith break;
111b6a7bef2SMike Smith case MLX_SYS_DRV_RAID1:
112b6a7bef2SMike Smith printf("RAID1");
113b6a7bef2SMike Smith break;
114b6a7bef2SMike Smith case MLX_SYS_DRV_RAID3:
115b6a7bef2SMike Smith printf("RAID3");
116b6a7bef2SMike Smith break;
117b6a7bef2SMike Smith case MLX_SYS_DRV_RAID5:
118b6a7bef2SMike Smith printf("RAID5");
119b6a7bef2SMike Smith break;
120b6a7bef2SMike Smith case MLX_SYS_DRV_RAID6:
121b6a7bef2SMike Smith printf("RAID6");
122b6a7bef2SMike Smith break;
123b6a7bef2SMike Smith case MLX_SYS_DRV_JBOD:
124b6a7bef2SMike Smith printf("JBOD");
125b6a7bef2SMike Smith break;
126b6a7bef2SMike Smith default:
127b6a7bef2SMike Smith printf("RAID?");
128b6a7bef2SMike Smith }
129b6a7bef2SMike Smith printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
130b6a7bef2SMike Smith
131b6a7bef2SMike Smith for (i = 0; i < drv->sd_valid_spans; i++) {
132b6a7bef2SMike Smith printf(" span%d ", i);
133b6a7bef2SMike Smith print_span(&drv->sd_span[i], drv->sd_valid_arms);
134b6a7bef2SMike Smith }
135b6a7bef2SMike Smith }
136b6a7bef2SMike Smith
137b6a7bef2SMike Smith /********************************************************************************
138b6a7bef2SMike Smith * Print details for the physical drive at chn/targ in a format suitable for
139b6a7bef2SMike Smith * human consumption.
140b6a7bef2SMike Smith *
141b6a7bef2SMike Smith * <type>CCTT (<state>) "<vendor>/<model>"
142b6a7bef2SMike Smith * ????MB <features>
143b6a7bef2SMike Smith *
144b6a7bef2SMike Smith */
145b6a7bef2SMike Smith static void
print_phys_drive(struct conf_config * conf,int chn,int targ)146b6a7bef2SMike Smith print_phys_drive(struct conf_config *conf, int chn, int targ)
147b6a7bef2SMike Smith {
148b6a7bef2SMike Smith struct mlx_phys_drv *drv = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
149b6a7bef2SMike Smith
150b6a7bef2SMike Smith /* if the drive isn't present, don't print it */
151b6a7bef2SMike Smith if (!(drv->pd_flags1 & MLX_PHYS_DRV_PRESENT))
152b6a7bef2SMike Smith return;
153b6a7bef2SMike Smith
154b6a7bef2SMike Smith mlx_print_phys_drv(drv, chn, targ, "# ", 1);
155b6a7bef2SMike Smith }
156b6a7bef2SMike Smith
157b6a7bef2SMike Smith
158