config.c revision 1.1 1 /* $NetBSD: config.c,v 1.1 2001/02/04 17:30:37 ad Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*-
40 * Copyright (c) 1999 Michael Smith
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * from FreeBSD: config.c,v 1.2 2000/04/11 23:04:17 msmith Exp
65 */
66
67 #ifndef lint
68 #include <sys/cdefs.h>
69 __RCSID("$NetBSD: config.c,v 1.1 2001/02/04 17:30:37 ad Exp $");
70 #endif /* not lint */
71
72 #include <sys/types.h>
73 #include <sys/param.h>
74 #include <sys/ioctl.h>
75 #include <sys/queue.h>
76
77 #include <dev/ic/mlxreg.h>
78 #include <dev/ic/mlxio.h>
79
80 #include <err.h>
81 #include <fcntl.h>
82 #include <stdio.h>
83 #include <stdlib.h>
84 #include <string.h>
85 #include <ctype.h>
86 #include <unistd.h>
87 #include <getopt.h>
88
89 #include "extern.h"
90
91 struct conf_phys_drv {
92 TAILQ_ENTRY(conf_phys_drv) pd_link;
93 int pd_bus;
94 int pd_target;
95 struct mlx_phys_drv pd_drv;
96 };
97
98 struct conf_span {
99 TAILQ_ENTRY(conf_span) s_link;
100 struct conf_phys_drv *s_drvs[8];
101 struct mlx_sys_drv_span s_span;
102 };
103
104 struct conf_sys_drv {
105 TAILQ_ENTRY(conf_sys_drv) sd_link;
106 struct conf_span *sd_spans[4];
107 struct mlx_sys_drv sd_drv;
108 };
109
110 struct conf_config {
111 TAILQ_HEAD(,conf_phys_drv) cc_phys_drvs;
112 TAILQ_HEAD(,conf_span) cc_spans;
113 TAILQ_HEAD(,conf_sys_drv) cc_sys_drvs;
114 struct conf_sys_drv *cc_drives[32];
115 struct mlx_core_cfg cc_cfg;
116 };
117
118 static void print_span(struct mlx_sys_drv_span *, int);
119 static void print_sys_drive(struct conf_config *, int);
120 static void print_phys_drive(struct conf_config *, int, int);
121
122 /*
123 * Get the configuration from the selected controller.
124 *
125 * config <controller>
126 * Print the configuration for <controller>
127 *
128 * XXX update to support adding/deleting drives.
129 */
130 int
131 cmd_config(char **argv)
132 {
133 char hostname[MAXHOSTNAMELEN];
134 struct conf_config conf;
135 int i, j;
136
137 memset(&conf.cc_cfg, 0, sizeof(conf.cc_cfg));
138 mlx_configuration(&conf.cc_cfg, 0);
139
140 gethostname(hostname, sizeof(hostname));
141 printf("# controller %s on %s\n", mlxname, hostname);
142
143 printf("#\n# physical devices connected:\n");
144 for (i = 0; i < 5; i++)
145 for (j = 0; j < 16; j++)
146 print_phys_drive(&conf, i, j);
147
148 printf("#\n# system drives defined:\n");
149 for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++)
150 print_sys_drive(&conf, i);
151
152 return(0);
153 }
154
155 /*
156 * Print details for the system drive (drvno) in a format that we will be
157 * able to parse later.
158 *
159 * drive?? <raidlevel> <writemode>
160 * span? 0x????????-0x???????? ????blks on <disk> [...]
161 * ...
162 */
163 static void
164 print_span(struct mlx_sys_drv_span *span, int arms)
165 {
166 int i;
167
168 printf("0x%08x-0x%08x %u blks on", span->sp_start_lba,
169 span->sp_start_lba + span->sp_nblks, span->sp_nblks);
170
171 for (i = 0; i < arms; i++)
172 printf(" disk%02d%02d", span->sp_arm[i] >> 4,
173 span->sp_arm[i] & 0x0f);
174
175 printf("\n");
176 }
177
178 static void
179 print_sys_drive(struct conf_config *conf, int drvno)
180 {
181 struct mlx_sys_drv *drv;
182 int i;
183
184 drv = &conf->cc_cfg.cc_sys_drives[drvno];
185
186 printf("drive%02d ", drvno);
187
188 switch(drv->sd_raidlevel & 0xf) {
189 case MLX_SYS_DRV_RAID0:
190 printf("RAID0");
191 break;
192 case MLX_SYS_DRV_RAID1:
193 printf("RAID1");
194 break;
195 case MLX_SYS_DRV_RAID3:
196 printf("RAID3");
197 break;
198 case MLX_SYS_DRV_RAID5:
199 printf("RAID5");
200 break;
201 case MLX_SYS_DRV_RAID6:
202 printf("RAID6");
203 break;
204 case MLX_SYS_DRV_JBOD:
205 printf("JBOD");
206 break;
207 default:
208 printf("RAID?");
209 break;
210 }
211
212 printf(" write%s\n",
213 drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through");
214
215 for (i = 0; i < drv->sd_valid_spans; i++) {
216 printf(" span%d ", i);
217 print_span(&drv->sd_span[i], drv->sd_valid_arms);
218 }
219 }
220
221 /*
222 * Print details for the physical drive at chn/targ in a format suitable for
223 * human consumption.
224 */
225 static void
226 print_phys_drive(struct conf_config *conf, int chn, int targ)
227 {
228 struct mlx_phys_drv *pd;
229
230 pd = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ];
231
232 /* If the drive isn't present, don't print it. */
233 if ((pd->pd_flags1 & MLX_PHYS_DRV_PRESENT) == 0)
234 return;
235
236 mlx_print_phys_drv(pd, chn, targ, "# ");
237 }
238