xref: /freebsd/usr.sbin/mlxcontrol/config.c (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1999 Michael Smith
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
15  *
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
26  * SUCH DAMAGE.
27  */
28 
29 #include <fcntl.h>
30 #include <paths.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <err.h>
36 
37 #include <dev/mlx/mlxio.h>
38 #include <dev/mlx/mlxreg.h>
39 
40 #include "mlxcontrol.h"
41 
42 static void	print_span(struct mlx_sys_drv_span *span, int arms);
43 static void	print_sys_drive(struct conf_config *conf, int drvno);
44 static void	print_phys_drive(struct conf_config *conf, int chn, int targ);
45 
46 /********************************************************************************
47  * Get the configuration from the selected controller.
48  *
49  * config <controller>
50  *		Print the configuration for <controller>
51  *
52  * XXX update to support adding/deleting drives.
53  */
54 
55 int
56 cmd_config(int argc, char *argv[])
57 {
58     struct conf_config	conf;
59     int			unit = 0;	/* XXX */
60     int			i, j;
61 
62     bzero(&conf.cc_cfg, sizeof(conf.cc_cfg));
63     if (mlx_read_configuration(unit, &conf.cc_cfg)) {
64 	printf("mlx%d: error submitting READ CONFIGURATION\n", unit);
65     } else {
66 
67 	printf("# Controller <INSERT DETAILS HERE>\n");
68 	printf("#\n# Physical devices connected:\n");
69 	for (i = 0; i < 5; i++)
70 	    for (j = 0; j < 16; j++)
71 	    print_phys_drive(&conf, i, j);
72 	printf("#\n# System Drives defined:\n");
73 
74 	for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
75 	    print_sys_drive(&conf, i);
76     }
77     return(0);
78 }
79 
80 
81 /********************************************************************************
82  * Print details for the system drive (drvno) in a format that we will be
83  * able to parse later.
84  *
85  * drive?? <raidlevel> <writemode>
86  *   span? 0x????????-0x???????? ????MB on <disk> [...]
87  *   ...
88  */
89 static void
90 print_span(struct mlx_sys_drv_span *span, int arms)
91 {
92     int		i;
93 
94     printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048);
95     for (i = 0; i < arms; i++)
96 	printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f);
97     printf("\n");
98 }
99 
100 static void
101 print_sys_drive(struct conf_config *conf, int drvno)
102 {
103     struct mlx_sys_drv	*drv = &conf->cc_cfg.cc_sys_drives[drvno];
104     int			i;
105 
106     printf("drive%02d ", drvno);
107     switch(drv->sd_raidlevel & 0xf) {
108     case MLX_SYS_DRV_RAID0:
109 	printf("RAID0");
110 	break;
111     case MLX_SYS_DRV_RAID1:
112 	printf("RAID1");
113 	break;
114     case MLX_SYS_DRV_RAID3:
115 	printf("RAID3");
116 	break;
117     case MLX_SYS_DRV_RAID5:
118 	printf("RAID5");
119 	break;
120     case MLX_SYS_DRV_RAID6:
121 	printf("RAID6");
122 	break;
123     case MLX_SYS_DRV_JBOD:
124 	printf("JBOD");
125 	break;
126     default:
127 	printf("RAID?");
128     }
129     printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
130 
131     for (i = 0; i < drv->sd_valid_spans; i++) {
132 	printf("  span%d ", i);
133 	print_span(&drv->sd_span[i], drv->sd_valid_arms);
134     }
135 }
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  */
145 static void
146 print_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