cmds.c revision 1.3 1 1.3 simonb /* $NetBSD: cmds.c,v 1.3 2001/02/15 02:32:26 simonb Exp $ */
2 1.1 ad
3 1.1 ad /*-
4 1.1 ad * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.1 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.1 ad * by Andrew Doran.
9 1.1 ad *
10 1.1 ad * Redistribution and use in source and binary forms, with or without
11 1.1 ad * modification, are permitted provided that the following conditions
12 1.1 ad * are met:
13 1.1 ad * 1. Redistributions of source code must retain the above copyright
14 1.1 ad * notice, this list of conditions and the following disclaimer.
15 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ad * notice, this list of conditions and the following disclaimer in the
17 1.1 ad * documentation and/or other materials provided with the distribution.
18 1.1 ad * 3. All advertising materials mentioning features or use of this software
19 1.1 ad * must display the following acknowledgement:
20 1.1 ad * This product includes software developed by the NetBSD
21 1.1 ad * Foundation, Inc. and its contributors.
22 1.1 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 ad * contributors may be used to endorse or promote products derived
24 1.1 ad * from this software without specific prior written permission.
25 1.1 ad *
26 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.1 ad */
38 1.1 ad
39 1.1 ad /*-
40 1.1 ad * Copyright (c) 1999 Michael Smith
41 1.1 ad * All rights reserved.
42 1.1 ad *
43 1.1 ad * Redistribution and use in source and binary forms, with or without
44 1.1 ad * modification, are permitted provided that the following conditions
45 1.1 ad * are met:
46 1.1 ad * 1. Redistributions of source code must retain the above copyright
47 1.1 ad * notice, this list of conditions and the following disclaimer.
48 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 ad * notice, this list of conditions and the following disclaimer in the
50 1.1 ad * documentation and/or other materials provided with the distribution.
51 1.1 ad *
52 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53 1.1 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.1 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.1 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56 1.1 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.1 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.1 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.1 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.1 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.1 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.1 ad * SUCH DAMAGE.
63 1.1 ad *
64 1.1 ad * from FreeBSD: command.c,v 1.2 2000/04/11 23:04:17 msmith Exp
65 1.1 ad */
66 1.1 ad
67 1.1 ad #ifndef lint
68 1.1 ad #include <sys/cdefs.h>
69 1.3 simonb __RCSID("$NetBSD: cmds.c,v 1.3 2001/02/15 02:32:26 simonb Exp $");
70 1.1 ad #endif /* not lint */
71 1.1 ad
72 1.1 ad #include <sys/types.h>
73 1.1 ad #include <sys/ioctl.h>
74 1.1 ad #include <sys/queue.h>
75 1.1 ad #include <sys/endian.h>
76 1.1 ad
77 1.1 ad #include <dev/ic/mlxreg.h>
78 1.1 ad #include <dev/ic/mlxio.h>
79 1.1 ad
80 1.1 ad #include <err.h>
81 1.1 ad #include <fcntl.h>
82 1.1 ad #include <stdio.h>
83 1.1 ad #include <stdlib.h>
84 1.1 ad #include <string.h>
85 1.1 ad #include <ctype.h>
86 1.1 ad #include <unistd.h>
87 1.1 ad #include <getopt.h>
88 1.1 ad
89 1.1 ad #include "extern.h"
90 1.1 ad
91 1.1 ad static void cmd_status0(struct mlx_disk *);
92 1.1 ad static void cmd_check0(struct mlx_disk *);
93 1.1 ad static void cmd_detach0(struct mlx_disk *);
94 1.1 ad
95 1.1 ad static struct mlx_rebuild_status rs;
96 1.1 ad static int rstatus;
97 1.1 ad
98 1.1 ad struct {
99 1.1 ad int hwid;
100 1.1 ad const char *name;
101 1.1 ad } static const mlx_ctlr_names[] = {
102 1.1 ad { 0x01, "960P/PD" },
103 1.1 ad { 0x02, "960PL" },
104 1.1 ad { 0x10, "960PG" },
105 1.1 ad { 0x11, "960PJ" },
106 1.1 ad { 0x12, "960PR" },
107 1.1 ad { 0x13, "960PT" },
108 1.1 ad { 0x14, "960PTL0" },
109 1.1 ad { 0x15, "960PRL" } ,
110 1.1 ad { 0x16, "960PTL1" },
111 1.1 ad { 0x20, "1100PVX" },
112 1.1 ad { -1, NULL },
113 1.1 ad };
114 1.1 ad
115 1.1 ad /*
116 1.1 ad * Status output
117 1.1 ad */
118 1.1 ad static void
119 1.1 ad cmd_status0(struct mlx_disk *md)
120 1.1 ad {
121 1.1 ad int result;
122 1.1 ad
123 1.1 ad result = md->hwunit;
124 1.1 ad if (ioctl(mlxfd, MLXD_STATUS, &result) < 0)
125 1.1 ad err(EXIT_FAILURE, "ioctl(MLXD_STATUS)");
126 1.1 ad
127 1.1 ad switch(result) {
128 1.1 ad case MLX_SYSD_ONLINE:
129 1.3 simonb printf("%s: online\n", md->name);
130 1.1 ad break;
131 1.1 ad
132 1.1 ad case MLX_SYSD_CRITICAL:
133 1.3 simonb printf("%s: critical\n", md->name);
134 1.1 ad if (!rstatus)
135 1.1 ad rstatus = 1;
136 1.1 ad break;
137 1.1 ad
138 1.1 ad case MLX_SYSD_OFFLINE:
139 1.3 simonb printf("%s: offline\n", md->name);
140 1.1 ad rstatus = 2;
141 1.1 ad break;
142 1.1 ad
143 1.1 ad default:
144 1.3 simonb printf("%s: unknown status 0x%02x\n", md->name, result);
145 1.1 ad break;
146 1.1 ad }
147 1.1 ad
148 1.1 ad /* Rebuild/check in progress on this drive? */
149 1.1 ad if (rs.rs_drive == md->hwunit &&
150 1.1 ad rs.rs_code != MLX_REBUILDSTAT_IDLE) {
151 1.1 ad switch(rs.rs_code) {
152 1.1 ad case MLX_REBUILDSTAT_REBUILDCHECK:
153 1.1 ad printf(" [consistency check");
154 1.1 ad break;
155 1.1 ad
156 1.1 ad case MLX_REBUILDSTAT_ADDCAPACITY:
157 1.1 ad printf(" [add capacity");
158 1.1 ad break;
159 1.1 ad
160 1.1 ad case MLX_REBUILDSTAT_ADDCAPACITYINIT:
161 1.1 ad printf(" [add capacity init");
162 1.1 ad break;
163 1.1 ad
164 1.1 ad default:
165 1.1 ad printf(" [unknown operation");
166 1.1 ad break;
167 1.1 ad }
168 1.1 ad
169 1.1 ad printf(": %d/%d, %d%% complete]\n", rs.rs_remaining, rs.rs_size,
170 1.1 ad ((rs.rs_size - rs.rs_remaining) / (rs.rs_size / 100)));
171 1.1 ad }
172 1.1 ad }
173 1.1 ad
174 1.1 ad int
175 1.1 ad cmd_status(char **argv)
176 1.1 ad {
177 1.1 ad
178 1.1 ad if (ioctl(mlxfd, MLX_REBUILDSTAT, &rs) < 0)
179 1.1 ad err(EXIT_FAILURE, "ioctl(MLX_REBUILDSTAT)");
180 1.1 ad
181 1.1 ad mlx_disk_iterate(cmd_status0);
182 1.1 ad return (rstatus);
183 1.1 ad }
184 1.1 ad
185 1.1 ad /*
186 1.1 ad * Display controller status.
187 1.1 ad */
188 1.1 ad int
189 1.1 ad cmd_cstatus(char **argv)
190 1.1 ad {
191 1.1 ad struct mlx_enquiry2 enq;
192 1.1 ad struct mlx_phys_drv pd;
193 1.1 ad static char buf[80];
194 1.1 ad const char *model;
195 1.1 ad int i, channel, target;
196 1.1 ad
197 1.1 ad mlx_enquiry(&enq);
198 1.1 ad
199 1.1 ad for (i = 0; i < sizeof(mlx_ctlr_names) / sizeof(mlx_ctlr_names[0]); i++)
200 1.1 ad if (enq.me_hardware_id[0] == mlx_ctlr_names[i].hwid) {
201 1.1 ad model = mlx_ctlr_names[i].name;
202 1.1 ad break;
203 1.1 ad }
204 1.1 ad
205 1.1 ad if (i == sizeof(mlx_ctlr_names) / sizeof(mlx_ctlr_names[0])) {
206 1.1 ad sprintf(buf, " model 0x%x", enq.me_hardware_id[0]);
207 1.1 ad model = buf;
208 1.1 ad }
209 1.1 ad
210 1.1 ad printf("DAC%s, %d channel%s, firmware %d.%02d-%c-%02d, %dMB RAM\n",
211 1.1 ad model, enq.me_actual_channels,
212 1.1 ad enq.me_actual_channels > 1 ? "s" : "",
213 1.1 ad enq.me_firmware_id[0], enq.me_firmware_id[1],
214 1.1 ad enq.me_firmware_id[2], enq.me_firmware_id[3],
215 1.1 ad le32toh(enq.me_mem_size) / (1024 * 1024));
216 1.1 ad
217 1.1 ad if (verbosity > 0) {
218 1.1 ad printf(" Hardware ID\t\t\t0x%08x\n",
219 1.1 ad le32toh(*(u_int32_t *)enq.me_hardware_id));
220 1.1 ad printf(" Firmware ID\t\t\t0x%08x\n",
221 1.1 ad le32toh(*(u_int32_t *)enq.me_firmware_id));
222 1.1 ad printf(" Configured/Actual channels\t%d/%d\n",
223 1.1 ad enq.me_configured_channels, enq.me_actual_channels);
224 1.1 ad printf(" Max Targets\t\t\t%d\n", enq.me_max_targets);
225 1.1 ad printf(" Max Tags\t\t\t%d\n", enq.me_max_tags);
226 1.1 ad printf(" Max System Drives\t\t%d\n", enq.me_max_sys_drives);
227 1.1 ad printf(" Max Arms\t\t\t%d\n", enq.me_max_arms);
228 1.1 ad printf(" Max Spans\t\t\t%d\n", enq.me_max_spans);
229 1.1 ad printf(" DRAM/cache/flash/NVRAM size\t%d/%d/%d/%d\n",
230 1.1 ad le32toh(enq.me_mem_size), le32toh(enq.me_cache_size),
231 1.1 ad le32toh(enq.me_flash_size), le32toh(enq.me_nvram_size));
232 1.1 ad printf(" DRAM type\t\t\t%d\n", le16toh(enq.me_mem_type));
233 1.1 ad printf(" Clock Speed\t\t\t%dns\n",
234 1.1 ad le16toh(enq.me_clock_speed));
235 1.1 ad printf(" Hardware Speed\t\t%dns\n",
236 1.1 ad le16toh(enq.me_hardware_speed));
237 1.1 ad printf(" Max Commands\t\t\t%d\n",
238 1.1 ad le16toh(enq.me_max_commands));
239 1.1 ad printf(" Max SG Entries\t\t%d\n", le16toh(enq.me_max_sg));
240 1.1 ad printf(" Max DP\t\t\t%d\n", le16toh(enq.me_max_dp));
241 1.1 ad printf(" Max IOD\t\t\t%d\n", le16toh(enq.me_max_iod));
242 1.1 ad printf(" Max Comb\t\t\t%d\n", le16toh(enq.me_max_comb));
243 1.1 ad printf(" Latency\t\t\t%ds\n", enq.me_latency);
244 1.1 ad printf(" SCSI Timeout\t\t\t%ds\n", enq.me_scsi_timeout);
245 1.1 ad printf(" Min Free Lines\t\t%d\n",
246 1.1 ad le16toh(enq.me_min_freelines));
247 1.1 ad printf(" Rate Constant\t\t\t%d\n", enq.me_rate_const);
248 1.1 ad printf(" MAXBLK\t\t\t%d\n", le16toh(enq.me_maxblk));
249 1.1 ad printf(" Blocking Factor\t\t%d sectors\n",
250 1.1 ad le16toh(enq.me_blocking_factor));
251 1.1 ad printf(" Cache Line Size\t\t%d blocks\n",
252 1.1 ad le16toh(enq.me_cacheline));
253 1.1 ad printf(" SCSI Capability\t\t%s%dMHz, %d bit\n",
254 1.1 ad enq.me_scsi_cap & (1<<4) ? "differential " : "",
255 1.1 ad (1 << ((enq.me_scsi_cap >> 2) & 3)) * 10,
256 1.1 ad 8 << (enq.me_scsi_cap & 0x3));
257 1.1 ad printf(" Firmware Build Number\t\t%d\n",
258 1.1 ad le16toh(enq.me_firmware_build));
259 1.1 ad printf(" Fault Management Type\t\t%d\n",
260 1.1 ad enq.me_fault_mgmt_type);
261 1.1 ad #if 0
262 1.1 ad printf(" Features\t\t\t%b\n", enq.me_firmware_features,
263 1.1 ad "\20\4Background Init\3Read Ahead\2MORE\1Cluster\n");
264 1.1 ad #endif
265 1.1 ad }
266 1.1 ad
267 1.1 ad fflush(stdout);
268 1.1 ad
269 1.1 ad /*
270 1.1 ad * Fetch and print physical drive data.
271 1.1 ad */
272 1.1 ad for (channel = 0; channel < enq.me_configured_channels; channel++) {
273 1.1 ad for (target = 0; target < enq.me_max_targets; target++)
274 1.1 ad if (mlx_get_device_state(channel, target, &pd) == 0 &&
275 1.1 ad (pd.pd_flags1 & MLX_PHYS_DRV_PRESENT) != 0)
276 1.1 ad mlx_print_phys_drv(&pd, channel, target, " ");
277 1.1 ad }
278 1.1 ad
279 1.1 ad return (0);
280 1.1 ad }
281 1.1 ad
282 1.1 ad /*
283 1.1 ad * Recscan for new or changed system drives.
284 1.1 ad */
285 1.1 ad int
286 1.1 ad cmd_rescan(char **argv)
287 1.1 ad {
288 1.1 ad
289 1.1 ad if (ioctl(mlxfd, MLX_RESCAN_DRIVES) < 0)
290 1.1 ad err(EXIT_FAILURE, "rescan failed");
291 1.1 ad return (0);
292 1.1 ad }
293 1.1 ad
294 1.1 ad /*
295 1.1 ad * Detach one or more system drives from a controller.
296 1.1 ad */
297 1.1 ad static void
298 1.1 ad cmd_detach0(struct mlx_disk *md)
299 1.1 ad {
300 1.1 ad
301 1.1 ad if (ioctl(mlxfd, MLXD_DETACH, &md->hwunit) < 0)
302 1.1 ad warn("can't detach %s", md->name);
303 1.1 ad }
304 1.1 ad
305 1.1 ad int
306 1.1 ad cmd_detach(char **argv)
307 1.1 ad {
308 1.1 ad
309 1.1 ad mlx_disk_iterate(cmd_detach0);
310 1.1 ad return (0);
311 1.1 ad }
312 1.1 ad
313 1.1 ad /*
314 1.1 ad * Initiate a consistency check on a system drive.
315 1.1 ad */
316 1.1 ad static void
317 1.1 ad cmd_check0(struct mlx_disk *md)
318 1.1 ad {
319 1.1 ad int result;
320 1.1 ad
321 1.1 ad if (ioctl(mlxfd, MLXD_CHECKASYNC, &result) == 0)
322 1.1 ad return;
323 1.1 ad
324 1.1 ad switch (result) {
325 1.1 ad case 0x0002:
326 1.1 ad warnx("one or more of the SCSI disks on which %s", md->name);
327 1.2 simonb warnx("depends is DEAD.");
328 1.1 ad break;
329 1.1 ad
330 1.1 ad case 0x0105:
331 1.1 ad warnx("drive %s is invalid, or not a drive which ", md->name);
332 1.1 ad warnx("can be checked.");
333 1.1 ad break;
334 1.1 ad
335 1.1 ad case 0x0106:
336 1.1 ad warnx("drive rebuild or consistency check is already ");
337 1.1 ad warnx("in progress on this controller.");
338 1.1 ad break;
339 1.1 ad
340 1.1 ad default:
341 1.1 ad err(EXIT_FAILURE, "ioctl(MLXD_CHECKASYNC)");
342 1.1 ad /* NOTREACHED */
343 1.1 ad }
344 1.1 ad }
345 1.1 ad
346 1.1 ad int
347 1.1 ad cmd_check(char **argv)
348 1.1 ad {
349 1.1 ad
350 1.1 ad mlx_disk_iterate(cmd_check0);
351 1.1 ad return (0);
352 1.1 ad }
353 1.1 ad
354 1.1 ad /*
355 1.1 ad * Initiate a physical drive rebuild.
356 1.1 ad */
357 1.1 ad int
358 1.1 ad cmd_rebuild(char **argv)
359 1.1 ad {
360 1.1 ad struct mlx_rebuild_request rb;
361 1.1 ad char *p;
362 1.1 ad
363 1.1 ad if (argv[0] == NULL || argv[1] != NULL)
364 1.1 ad usage();
365 1.1 ad
366 1.1 ad rb.rr_channel = strtol(*argv, &p, 0);
367 1.1 ad if (p[0] != ':' || p[1] == '\0')
368 1.1 ad usage();
369 1.1 ad
370 1.1 ad rb.rr_target = strtol(*argv, &p, 0);
371 1.1 ad if (p[0] != '\0')
372 1.1 ad usage();
373 1.1 ad
374 1.1 ad if (ioctl(mlxfd, MLX_REBUILDASYNC, &rb) == 0)
375 1.1 ad return (0);
376 1.1 ad
377 1.1 ad switch (rb.rr_status) {
378 1.1 ad case 0x0002:
379 1.1 ad warnx("the drive at %d:%d is already ONLINE", rb.rr_channel,
380 1.1 ad rb.rr_target);
381 1.1 ad break;
382 1.1 ad
383 1.1 ad case 0x0004:
384 1.1 ad warnx("drive failed during rebuild");
385 1.1 ad break;
386 1.1 ad
387 1.1 ad case 0x0105:
388 1.1 ad warnx("there is no drive at %d:%d", rb.rr_channel,
389 1.1 ad rb.rr_target);
390 1.1 ad break;
391 1.1 ad
392 1.1 ad case 0x0106:
393 1.1 ad warnx("drive rebuild or consistency check is already in ");
394 1.1 ad warnx("progress on this controller");
395 1.1 ad break;
396 1.1 ad
397 1.1 ad default:
398 1.1 ad err(EXIT_FAILURE, "ioctl(MLXD_CHECKASYNC)");
399 1.1 ad /* NOTREACHED */
400 1.1 ad }
401 1.1 ad
402 1.1 ad return(0);
403 1.1 ad }
404