cmds.c revision 1.1 1 1.1 ad /* $NetBSD: cmds.c,v 1.1 2001/02/04 17:30:37 ad 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.1 ad __RCSID("$NetBSD: cmds.c,v 1.1 2001/02/04 17:30:37 ad 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 const char *statusfmt;
122 1.1 ad int result;
123 1.1 ad
124 1.1 ad result = md->hwunit;
125 1.1 ad if (ioctl(mlxfd, MLXD_STATUS, &result) < 0)
126 1.1 ad err(EXIT_FAILURE, "ioctl(MLXD_STATUS)");
127 1.1 ad
128 1.1 ad switch(result) {
129 1.1 ad case MLX_SYSD_ONLINE:
130 1.1 ad statusfmt = "%s: online\n";
131 1.1 ad break;
132 1.1 ad
133 1.1 ad case MLX_SYSD_CRITICAL:
134 1.1 ad statusfmt = "%s: critical\n";
135 1.1 ad if (!rstatus)
136 1.1 ad rstatus = 1;
137 1.1 ad break;
138 1.1 ad
139 1.1 ad case MLX_SYSD_OFFLINE:
140 1.1 ad statusfmt = "%s: offline\n";
141 1.1 ad rstatus = 2;
142 1.1 ad break;
143 1.1 ad
144 1.1 ad default:
145 1.1 ad statusfmt = "%s: unknown status 0x%02x\n";
146 1.1 ad break;
147 1.1 ad }
148 1.1 ad
149 1.1 ad printf(statusfmt, md->name, result);
150 1.1 ad
151 1.1 ad /* Rebuild/check in progress on this drive? */
152 1.1 ad if (rs.rs_drive == md->hwunit &&
153 1.1 ad rs.rs_code != MLX_REBUILDSTAT_IDLE) {
154 1.1 ad switch(rs.rs_code) {
155 1.1 ad case MLX_REBUILDSTAT_REBUILDCHECK:
156 1.1 ad printf(" [consistency check");
157 1.1 ad break;
158 1.1 ad
159 1.1 ad case MLX_REBUILDSTAT_ADDCAPACITY:
160 1.1 ad printf(" [add capacity");
161 1.1 ad break;
162 1.1 ad
163 1.1 ad case MLX_REBUILDSTAT_ADDCAPACITYINIT:
164 1.1 ad printf(" [add capacity init");
165 1.1 ad break;
166 1.1 ad
167 1.1 ad default:
168 1.1 ad printf(" [unknown operation");
169 1.1 ad break;
170 1.1 ad }
171 1.1 ad
172 1.1 ad printf(": %d/%d, %d%% complete]\n", rs.rs_remaining, rs.rs_size,
173 1.1 ad ((rs.rs_size - rs.rs_remaining) / (rs.rs_size / 100)));
174 1.1 ad }
175 1.1 ad }
176 1.1 ad
177 1.1 ad int
178 1.1 ad cmd_status(char **argv)
179 1.1 ad {
180 1.1 ad
181 1.1 ad if (ioctl(mlxfd, MLX_REBUILDSTAT, &rs) < 0)
182 1.1 ad err(EXIT_FAILURE, "ioctl(MLX_REBUILDSTAT)");
183 1.1 ad
184 1.1 ad mlx_disk_iterate(cmd_status0);
185 1.1 ad return (rstatus);
186 1.1 ad }
187 1.1 ad
188 1.1 ad /*
189 1.1 ad * Display controller status.
190 1.1 ad */
191 1.1 ad int
192 1.1 ad cmd_cstatus(char **argv)
193 1.1 ad {
194 1.1 ad struct mlx_enquiry2 enq;
195 1.1 ad struct mlx_phys_drv pd;
196 1.1 ad static char buf[80];
197 1.1 ad const char *model;
198 1.1 ad int i, channel, target;
199 1.1 ad
200 1.1 ad mlx_enquiry(&enq);
201 1.1 ad
202 1.1 ad for (i = 0; i < sizeof(mlx_ctlr_names) / sizeof(mlx_ctlr_names[0]); i++)
203 1.1 ad if (enq.me_hardware_id[0] == mlx_ctlr_names[i].hwid) {
204 1.1 ad model = mlx_ctlr_names[i].name;
205 1.1 ad break;
206 1.1 ad }
207 1.1 ad
208 1.1 ad if (i == sizeof(mlx_ctlr_names) / sizeof(mlx_ctlr_names[0])) {
209 1.1 ad sprintf(buf, " model 0x%x", enq.me_hardware_id[0]);
210 1.1 ad model = buf;
211 1.1 ad }
212 1.1 ad
213 1.1 ad printf("DAC%s, %d channel%s, firmware %d.%02d-%c-%02d, %dMB RAM\n",
214 1.1 ad model, enq.me_actual_channels,
215 1.1 ad enq.me_actual_channels > 1 ? "s" : "",
216 1.1 ad enq.me_firmware_id[0], enq.me_firmware_id[1],
217 1.1 ad enq.me_firmware_id[2], enq.me_firmware_id[3],
218 1.1 ad le32toh(enq.me_mem_size) / (1024 * 1024));
219 1.1 ad
220 1.1 ad if (verbosity > 0) {
221 1.1 ad printf(" Hardware ID\t\t\t0x%08x\n",
222 1.1 ad le32toh(*(u_int32_t *)enq.me_hardware_id));
223 1.1 ad printf(" Firmware ID\t\t\t0x%08x\n",
224 1.1 ad le32toh(*(u_int32_t *)enq.me_firmware_id));
225 1.1 ad printf(" Configured/Actual channels\t%d/%d\n",
226 1.1 ad enq.me_configured_channels, enq.me_actual_channels);
227 1.1 ad printf(" Max Targets\t\t\t%d\n", enq.me_max_targets);
228 1.1 ad printf(" Max Tags\t\t\t%d\n", enq.me_max_tags);
229 1.1 ad printf(" Max System Drives\t\t%d\n", enq.me_max_sys_drives);
230 1.1 ad printf(" Max Arms\t\t\t%d\n", enq.me_max_arms);
231 1.1 ad printf(" Max Spans\t\t\t%d\n", enq.me_max_spans);
232 1.1 ad printf(" DRAM/cache/flash/NVRAM size\t%d/%d/%d/%d\n",
233 1.1 ad le32toh(enq.me_mem_size), le32toh(enq.me_cache_size),
234 1.1 ad le32toh(enq.me_flash_size), le32toh(enq.me_nvram_size));
235 1.1 ad printf(" DRAM type\t\t\t%d\n", le16toh(enq.me_mem_type));
236 1.1 ad printf(" Clock Speed\t\t\t%dns\n",
237 1.1 ad le16toh(enq.me_clock_speed));
238 1.1 ad printf(" Hardware Speed\t\t%dns\n",
239 1.1 ad le16toh(enq.me_hardware_speed));
240 1.1 ad printf(" Max Commands\t\t\t%d\n",
241 1.1 ad le16toh(enq.me_max_commands));
242 1.1 ad printf(" Max SG Entries\t\t%d\n", le16toh(enq.me_max_sg));
243 1.1 ad printf(" Max DP\t\t\t%d\n", le16toh(enq.me_max_dp));
244 1.1 ad printf(" Max IOD\t\t\t%d\n", le16toh(enq.me_max_iod));
245 1.1 ad printf(" Max Comb\t\t\t%d\n", le16toh(enq.me_max_comb));
246 1.1 ad printf(" Latency\t\t\t%ds\n", enq.me_latency);
247 1.1 ad printf(" SCSI Timeout\t\t\t%ds\n", enq.me_scsi_timeout);
248 1.1 ad printf(" Min Free Lines\t\t%d\n",
249 1.1 ad le16toh(enq.me_min_freelines));
250 1.1 ad printf(" Rate Constant\t\t\t%d\n", enq.me_rate_const);
251 1.1 ad printf(" MAXBLK\t\t\t%d\n", le16toh(enq.me_maxblk));
252 1.1 ad printf(" Blocking Factor\t\t%d sectors\n",
253 1.1 ad le16toh(enq.me_blocking_factor));
254 1.1 ad printf(" Cache Line Size\t\t%d blocks\n",
255 1.1 ad le16toh(enq.me_cacheline));
256 1.1 ad printf(" SCSI Capability\t\t%s%dMHz, %d bit\n",
257 1.1 ad enq.me_scsi_cap & (1<<4) ? "differential " : "",
258 1.1 ad (1 << ((enq.me_scsi_cap >> 2) & 3)) * 10,
259 1.1 ad 8 << (enq.me_scsi_cap & 0x3));
260 1.1 ad printf(" Firmware Build Number\t\t%d\n",
261 1.1 ad le16toh(enq.me_firmware_build));
262 1.1 ad printf(" Fault Management Type\t\t%d\n",
263 1.1 ad enq.me_fault_mgmt_type);
264 1.1 ad #if 0
265 1.1 ad printf(" Features\t\t\t%b\n", enq.me_firmware_features,
266 1.1 ad "\20\4Background Init\3Read Ahead\2MORE\1Cluster\n");
267 1.1 ad #endif
268 1.1 ad }
269 1.1 ad
270 1.1 ad fflush(stdout);
271 1.1 ad
272 1.1 ad /*
273 1.1 ad * Fetch and print physical drive data.
274 1.1 ad */
275 1.1 ad for (channel = 0; channel < enq.me_configured_channels; channel++) {
276 1.1 ad for (target = 0; target < enq.me_max_targets; target++)
277 1.1 ad if (mlx_get_device_state(channel, target, &pd) == 0 &&
278 1.1 ad (pd.pd_flags1 & MLX_PHYS_DRV_PRESENT) != 0)
279 1.1 ad mlx_print_phys_drv(&pd, channel, target, " ");
280 1.1 ad }
281 1.1 ad
282 1.1 ad return (0);
283 1.1 ad }
284 1.1 ad
285 1.1 ad /*
286 1.1 ad * Recscan for new or changed system drives.
287 1.1 ad */
288 1.1 ad int
289 1.1 ad cmd_rescan(char **argv)
290 1.1 ad {
291 1.1 ad
292 1.1 ad if (ioctl(mlxfd, MLX_RESCAN_DRIVES) < 0)
293 1.1 ad err(EXIT_FAILURE, "rescan failed");
294 1.1 ad return (0);
295 1.1 ad }
296 1.1 ad
297 1.1 ad /*
298 1.1 ad * Detach one or more system drives from a controller.
299 1.1 ad */
300 1.1 ad static void
301 1.1 ad cmd_detach0(struct mlx_disk *md)
302 1.1 ad {
303 1.1 ad
304 1.1 ad if (ioctl(mlxfd, MLXD_DETACH, &md->hwunit) < 0)
305 1.1 ad warn("can't detach %s", md->name);
306 1.1 ad }
307 1.1 ad
308 1.1 ad int
309 1.1 ad cmd_detach(char **argv)
310 1.1 ad {
311 1.1 ad
312 1.1 ad mlx_disk_iterate(cmd_detach0);
313 1.1 ad return (0);
314 1.1 ad }
315 1.1 ad
316 1.1 ad /*
317 1.1 ad * Initiate a consistency check on a system drive.
318 1.1 ad */
319 1.1 ad static void
320 1.1 ad cmd_check0(struct mlx_disk *md)
321 1.1 ad {
322 1.1 ad int result;
323 1.1 ad
324 1.1 ad if (ioctl(mlxfd, MLXD_CHECKASYNC, &result) == 0)
325 1.1 ad return;
326 1.1 ad
327 1.1 ad switch (result) {
328 1.1 ad case 0x0002:
329 1.1 ad warnx("one or more of the SCSI disks on which %s", md->name);
330 1.1 ad warnx("depends is DEAD.", md->name);
331 1.1 ad break;
332 1.1 ad
333 1.1 ad case 0x0105:
334 1.1 ad warnx("drive %s is invalid, or not a drive which ", md->name);
335 1.1 ad warnx("can be checked.");
336 1.1 ad break;
337 1.1 ad
338 1.1 ad case 0x0106:
339 1.1 ad warnx("drive rebuild or consistency check is already ");
340 1.1 ad warnx("in progress on this controller.");
341 1.1 ad break;
342 1.1 ad
343 1.1 ad default:
344 1.1 ad err(EXIT_FAILURE, "ioctl(MLXD_CHECKASYNC)");
345 1.1 ad /* NOTREACHED */
346 1.1 ad }
347 1.1 ad }
348 1.1 ad
349 1.1 ad int
350 1.1 ad cmd_check(char **argv)
351 1.1 ad {
352 1.1 ad
353 1.1 ad mlx_disk_iterate(cmd_check0);
354 1.1 ad return (0);
355 1.1 ad }
356 1.1 ad
357 1.1 ad /*
358 1.1 ad * Initiate a physical drive rebuild.
359 1.1 ad */
360 1.1 ad int
361 1.1 ad cmd_rebuild(char **argv)
362 1.1 ad {
363 1.1 ad struct mlx_rebuild_request rb;
364 1.1 ad char *p;
365 1.1 ad
366 1.1 ad if (argv[0] == NULL || argv[1] != NULL)
367 1.1 ad usage();
368 1.1 ad
369 1.1 ad rb.rr_channel = strtol(*argv, &p, 0);
370 1.1 ad if (p[0] != ':' || p[1] == '\0')
371 1.1 ad usage();
372 1.1 ad
373 1.1 ad rb.rr_target = strtol(*argv, &p, 0);
374 1.1 ad if (p[0] != '\0')
375 1.1 ad usage();
376 1.1 ad
377 1.1 ad if (ioctl(mlxfd, MLX_REBUILDASYNC, &rb) == 0)
378 1.1 ad return (0);
379 1.1 ad
380 1.1 ad switch (rb.rr_status) {
381 1.1 ad case 0x0002:
382 1.1 ad warnx("the drive at %d:%d is already ONLINE", rb.rr_channel,
383 1.1 ad rb.rr_target);
384 1.1 ad break;
385 1.1 ad
386 1.1 ad case 0x0004:
387 1.1 ad warnx("drive failed during rebuild");
388 1.1 ad break;
389 1.1 ad
390 1.1 ad case 0x0105:
391 1.1 ad warnx("there is no drive at %d:%d", rb.rr_channel,
392 1.1 ad rb.rr_target);
393 1.1 ad break;
394 1.1 ad
395 1.1 ad case 0x0106:
396 1.1 ad warnx("drive rebuild or consistency check is already in ");
397 1.1 ad warnx("progress on this controller");
398 1.1 ad break;
399 1.1 ad
400 1.1 ad default:
401 1.1 ad err(EXIT_FAILURE, "ioctl(MLXD_CHECKASYNC)");
402 1.1 ad /* NOTREACHED */
403 1.1 ad }
404 1.1 ad
405 1.1 ad return(0);
406 1.1 ad }
407