xref: /freebsd/usr.sbin/mlxcontrol/config.c (revision 1de7b4b805ddbf2429da511c053686ac4591ed89)
1b6a7bef2SMike Smith /*-
2*1de7b4b8SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*1de7b4b8SPedro 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  *	$FreeBSD$
29b6a7bef2SMike Smith  */
30b6a7bef2SMike Smith 
31b6a7bef2SMike Smith #include <fcntl.h>
32b6a7bef2SMike Smith #include <paths.h>
33b6a7bef2SMike Smith #include <stdio.h>
34b6a7bef2SMike Smith #include <stdlib.h>
35b6a7bef2SMike Smith #include <string.h>
36b6a7bef2SMike Smith #include <unistd.h>
37b6a7bef2SMike Smith #include <err.h>
38b6a7bef2SMike Smith 
39bb441a15SMike Smith #include <dev/mlx/mlxio.h>
40bb441a15SMike Smith #include <dev/mlx/mlxreg.h>
41b6a7bef2SMike Smith 
42b6a7bef2SMike Smith #include "mlxcontrol.h"
43b6a7bef2SMike Smith 
44b6a7bef2SMike Smith static void	print_span(struct mlx_sys_drv_span *span, int arms);
45b6a7bef2SMike Smith static void	print_sys_drive(struct conf_config *conf, int drvno);
46b6a7bef2SMike Smith static void	print_phys_drive(struct conf_config *conf, int chn, int targ);
47b6a7bef2SMike Smith 
48b6a7bef2SMike Smith /********************************************************************************
49b6a7bef2SMike Smith  * Get the configuration from the selected controller.
50b6a7bef2SMike Smith  *
51b6a7bef2SMike Smith  * config <controller>
52b6a7bef2SMike Smith  *		Print the configuration for <controller>
53b6a7bef2SMike Smith  *
54b6a7bef2SMike Smith  * XXX update to support adding/deleting drives.
55b6a7bef2SMike Smith  */
56b6a7bef2SMike Smith 
57b6a7bef2SMike Smith int
58b6a7bef2SMike Smith cmd_config(int argc, char *argv[])
59b6a7bef2SMike Smith {
60b6a7bef2SMike Smith     struct conf_config	conf;
61b6a7bef2SMike Smith     int			unit = 0;	/* XXX */
62b6a7bef2SMike Smith     int			i, j;
63b6a7bef2SMike Smith 
64b6a7bef2SMike Smith     bzero(&conf.cc_cfg, sizeof(conf.cc_cfg));
65b6a7bef2SMike Smith     if (mlx_read_configuration(unit, &conf.cc_cfg)) {
66b6a7bef2SMike Smith 	printf("mlx%d: error submitting READ CONFIGURATION\n", unit);
67b6a7bef2SMike Smith     } else {
68b6a7bef2SMike Smith 
69b6a7bef2SMike Smith 	printf("# Controller <INSERT DETAILS HERE>\n");
70b6a7bef2SMike Smith 	printf("#\n# Physical devices connected:\n");
71b6a7bef2SMike Smith 	for (i = 0; i < 5; i++)
72b6a7bef2SMike Smith 	    for (j = 0; j < 16; j++)
73b6a7bef2SMike Smith 	    print_phys_drive(&conf, i, j);
74b6a7bef2SMike Smith 	printf("#\n# System Drives defined:\n");
75b6a7bef2SMike Smith 
76b6a7bef2SMike Smith 	for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
77b6a7bef2SMike Smith 	    print_sys_drive(&conf, i);
78b6a7bef2SMike Smith     }
79b6a7bef2SMike Smith     return(0);
80b6a7bef2SMike Smith }
81b6a7bef2SMike Smith 
82b6a7bef2SMike Smith 
83b6a7bef2SMike Smith /********************************************************************************
84b6a7bef2SMike Smith  * Print details for the system drive (drvno) in a format that we will be
85b6a7bef2SMike Smith  * able to parse later.
86b6a7bef2SMike Smith  *
87b6a7bef2SMike Smith  * drive?? <raidlevel> <writemode>
88b6a7bef2SMike Smith  *   span? 0x????????-0x???????? ????MB on <disk> [...]
89b6a7bef2SMike Smith  *   ...
90b6a7bef2SMike Smith  */
91b6a7bef2SMike Smith static void
92b6a7bef2SMike Smith print_span(struct mlx_sys_drv_span *span, int arms)
93b6a7bef2SMike Smith {
94b6a7bef2SMike Smith     int		i;
95b6a7bef2SMike Smith 
96b6a7bef2SMike Smith     printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048);
97b6a7bef2SMike Smith     for (i = 0; i < arms; i++)
98b6a7bef2SMike Smith 	printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f);
99b6a7bef2SMike Smith     printf("\n");
100b6a7bef2SMike Smith }
101b6a7bef2SMike Smith 
102b6a7bef2SMike Smith static void
103b6a7bef2SMike Smith print_sys_drive(struct conf_config *conf, int drvno)
104b6a7bef2SMike Smith {
105b6a7bef2SMike Smith     struct mlx_sys_drv	*drv = &conf->cc_cfg.cc_sys_drives[drvno];
106b6a7bef2SMike Smith     int			i;
107b6a7bef2SMike Smith 
108b6a7bef2SMike Smith     printf("drive%02d ", drvno);
109b6a7bef2SMike Smith     switch(drv->sd_raidlevel & 0xf) {
110b6a7bef2SMike Smith     case MLX_SYS_DRV_RAID0:
111b6a7bef2SMike Smith 	printf("RAID0");
112b6a7bef2SMike Smith 	break;
113b6a7bef2SMike Smith     case MLX_SYS_DRV_RAID1:
114b6a7bef2SMike Smith 	printf("RAID1");
115b6a7bef2SMike Smith 	break;
116b6a7bef2SMike Smith     case MLX_SYS_DRV_RAID3:
117b6a7bef2SMike Smith 	printf("RAID3");
118b6a7bef2SMike Smith 	break;
119b6a7bef2SMike Smith     case MLX_SYS_DRV_RAID5:
120b6a7bef2SMike Smith 	printf("RAID5");
121b6a7bef2SMike Smith 	break;
122b6a7bef2SMike Smith     case MLX_SYS_DRV_RAID6:
123b6a7bef2SMike Smith 	printf("RAID6");
124b6a7bef2SMike Smith 	break;
125b6a7bef2SMike Smith     case MLX_SYS_DRV_JBOD:
126b6a7bef2SMike Smith 	printf("JBOD");
127b6a7bef2SMike Smith 	break;
128b6a7bef2SMike Smith     default:
129b6a7bef2SMike Smith 	printf("RAID?");
130b6a7bef2SMike Smith     }
131b6a7bef2SMike Smith     printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
132b6a7bef2SMike Smith 
133b6a7bef2SMike Smith     for (i = 0; i < drv->sd_valid_spans; i++) {
134b6a7bef2SMike Smith 	printf("  span%d ", i);
135b6a7bef2SMike Smith 	print_span(&drv->sd_span[i], drv->sd_valid_arms);
136b6a7bef2SMike Smith     }
137b6a7bef2SMike Smith }
138b6a7bef2SMike Smith 
139b6a7bef2SMike Smith /********************************************************************************
140b6a7bef2SMike Smith  * Print details for the physical drive at chn/targ in a format suitable for
141b6a7bef2SMike Smith  * human consumption.
142b6a7bef2SMike Smith  *
143b6a7bef2SMike Smith  * <type>CCTT (<state>) "<vendor>/<model>"
144b6a7bef2SMike Smith  *                       ????MB <features>
145b6a7bef2SMike Smith  *
146b6a7bef2SMike Smith  */
147b6a7bef2SMike Smith static void
148b6a7bef2SMike Smith print_phys_drive(struct conf_config *conf, int chn, int targ)
149b6a7bef2SMike Smith {
150b6a7bef2SMike Smith     struct mlx_phys_drv		*drv = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
151b6a7bef2SMike Smith 
152b6a7bef2SMike Smith     /* if the drive isn't present, don't print it */
153b6a7bef2SMike Smith     if (!(drv->pd_flags1 & MLX_PHYS_DRV_PRESENT))
154b6a7bef2SMike Smith 	return;
155b6a7bef2SMike Smith 
156b6a7bef2SMike Smith     mlx_print_phys_drv(drv, chn, targ, "# ", 1);
157b6a7bef2SMike Smith }
158b6a7bef2SMike Smith 
159b6a7bef2SMike Smith 
160