1b6a7bef2SMike Smith /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro 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
29b6a7bef2SMike Smith #include <sys/types.h>
30b6a7bef2SMike Smith #include <stdio.h>
31b6a7bef2SMike Smith #include <paths.h>
32b6a7bef2SMike Smith #include <string.h>
33b6a7bef2SMike Smith
34bb441a15SMike Smith #include <dev/mlx/mlxio.h>
35bb441a15SMike Smith #include <dev/mlx/mlxreg.h>
36b6a7bef2SMike Smith
37b6a7bef2SMike Smith #include "mlxcontrol.h"
38b6a7bef2SMike Smith
39b6a7bef2SMike Smith /********************************************************************************
40b6a7bef2SMike Smith * Various name-producing and -parsing functions
41b6a7bef2SMike Smith */
42b6a7bef2SMike Smith
43b6a7bef2SMike Smith /* return path of controller (unit) */
44b6a7bef2SMike Smith char *
ctrlrpath(int unit)45b6a7bef2SMike Smith ctrlrpath(int unit)
46b6a7bef2SMike Smith {
47b6a7bef2SMike Smith static char buf[32];
48b6a7bef2SMike Smith
49b6a7bef2SMike Smith sprintf(buf, "%s%s", _PATH_DEV, ctrlrname(unit));
50b6a7bef2SMike Smith return(buf);
51b6a7bef2SMike Smith }
52b6a7bef2SMike Smith
53b6a7bef2SMike Smith /* return name of controller (unit) */
54b6a7bef2SMike Smith char *
ctrlrname(int unit)55b6a7bef2SMike Smith ctrlrname(int unit)
56b6a7bef2SMike Smith {
57b6a7bef2SMike Smith static char buf[32];
58b6a7bef2SMike Smith
59b6a7bef2SMike Smith sprintf(buf, "mlx%d", unit);
60b6a7bef2SMike Smith return(buf);
61b6a7bef2SMike Smith }
62b6a7bef2SMike Smith
63b6a7bef2SMike Smith /* return path of drive (unit) */
64b6a7bef2SMike Smith char *
drivepath(int unit)65b6a7bef2SMike Smith drivepath(int unit)
66b6a7bef2SMike Smith {
67b6a7bef2SMike Smith static char buf[32];
68b6a7bef2SMike Smith
69b6a7bef2SMike Smith sprintf(buf, "%s%s", _PATH_DEV, drivename(unit));
70b6a7bef2SMike Smith return(buf);
71b6a7bef2SMike Smith }
72b6a7bef2SMike Smith
73b6a7bef2SMike Smith /* return name of drive (unit) */
74b6a7bef2SMike Smith char *
drivename(int unit)75b6a7bef2SMike Smith drivename(int unit)
76b6a7bef2SMike Smith {
77b6a7bef2SMike Smith static char buf[32];
78b6a7bef2SMike Smith
79b6a7bef2SMike Smith sprintf(buf, "mlxd%d", unit);
80b6a7bef2SMike Smith return(buf);
81b6a7bef2SMike Smith }
82b6a7bef2SMike Smith
83b6a7bef2SMike Smith /* get controller unit number from name in (str) */
84b6a7bef2SMike Smith int
ctrlrunit(char * str)85b6a7bef2SMike Smith ctrlrunit(char *str)
86b6a7bef2SMike Smith {
87b6a7bef2SMike Smith int unit;
88b6a7bef2SMike Smith
89b6a7bef2SMike Smith if (sscanf(str, "mlx%d", &unit) == 1)
90b6a7bef2SMike Smith return(unit);
91b6a7bef2SMike Smith return(-1);
92b6a7bef2SMike Smith }
93b6a7bef2SMike Smith
94b6a7bef2SMike Smith /* get drive unit number from name in (str) */
95b6a7bef2SMike Smith int
driveunit(char * str)96b6a7bef2SMike Smith driveunit(char *str)
97b6a7bef2SMike Smith {
98b6a7bef2SMike Smith int unit;
99b6a7bef2SMike Smith
100b6a7bef2SMike Smith if (sscanf(str, "mlxd%d", &unit) == 1)
101b6a7bef2SMike Smith return(unit);
102b6a7bef2SMike Smith return(-1);
103b6a7bef2SMike Smith }
104b6a7bef2SMike Smith
105b6a7bef2SMike Smith /********************************************************************************
106b6a7bef2SMike Smith * Standardised output of various data structures.
107b6a7bef2SMike Smith */
108b6a7bef2SMike Smith
109b6a7bef2SMike Smith void
mlx_print_phys_drv(struct mlx_phys_drv * drv,int chn,int targ,char * prefix,int verbose)110b6a7bef2SMike Smith mlx_print_phys_drv(struct mlx_phys_drv *drv, int chn, int targ, char *prefix, int verbose)
111b6a7bef2SMike Smith {
112b6a7bef2SMike Smith char *type, *device, *vendor, *revision;
113b6a7bef2SMike Smith
114b6a7bef2SMike Smith switch(drv->pd_flags2 & 0x03) {
115b6a7bef2SMike Smith case MLX_PHYS_DRV_DISK:
116b6a7bef2SMike Smith type = "disk";
117b6a7bef2SMike Smith break;
118b6a7bef2SMike Smith case MLX_PHYS_DRV_SEQUENTIAL:
119b6a7bef2SMike Smith type = "tape";
120b6a7bef2SMike Smith break;
121b6a7bef2SMike Smith case MLX_PHYS_DRV_CDROM:
122b6a7bef2SMike Smith type= "cdrom";
123b6a7bef2SMike Smith break;
124b6a7bef2SMike Smith case MLX_PHYS_DRV_OTHER:
125b6a7bef2SMike Smith default:
126b6a7bef2SMike Smith type = "unknown";
127b6a7bef2SMike Smith break;
128b6a7bef2SMike Smith }
129b6a7bef2SMike Smith printf("%s%s%02d%02d ", prefix, type, chn, targ);
130b6a7bef2SMike Smith switch(drv->pd_status) {
131b6a7bef2SMike Smith case MLX_PHYS_DRV_DEAD:
132b6a7bef2SMike Smith printf(" (dead) ");
133b6a7bef2SMike Smith break;
134b6a7bef2SMike Smith case MLX_PHYS_DRV_WRONLY:
135b6a7bef2SMike Smith printf(" (write-only) ");
136b6a7bef2SMike Smith break;
137b6a7bef2SMike Smith case MLX_PHYS_DRV_ONLINE:
138b6a7bef2SMike Smith printf(" (online) ");
139b6a7bef2SMike Smith break;
140b6a7bef2SMike Smith case MLX_PHYS_DRV_STANDBY:
141b6a7bef2SMike Smith printf(" (standby) ");
142b6a7bef2SMike Smith break;
143b6a7bef2SMike Smith default:
144b6a7bef2SMike Smith printf(" (0x%02x) ", drv->pd_status);
145b6a7bef2SMike Smith }
146b6a7bef2SMike Smith printf("\n");
147b6a7bef2SMike Smith
148b6a7bef2SMike Smith if (verbose) {
149b6a7bef2SMike Smith
150b6a7bef2SMike Smith printf("%s ", prefix);
151b6a7bef2SMike Smith if (!mlx_scsi_inquiry(0, chn, targ, &vendor, &device, &revision)) {
152b6a7bef2SMike Smith printf("'%8.8s' '%16.16s' '%4.4s'", vendor, device, revision);
153b6a7bef2SMike Smith } else {
154b6a7bef2SMike Smith printf("<IDENTIFY FAILED>");
155b6a7bef2SMike Smith }
156b6a7bef2SMike Smith
157b6a7bef2SMike Smith printf(" %dMB ", drv->pd_config_size / 2048);
158b6a7bef2SMike Smith
159b6a7bef2SMike Smith if (drv->pd_flags2 & MLX_PHYS_DRV_FAST20) {
160b6a7bef2SMike Smith printf(" fast20");
161b6a7bef2SMike Smith } else if (drv->pd_flags2 & MLX_PHYS_DRV_FAST) {
162b6a7bef2SMike Smith printf(" fast");
163b6a7bef2SMike Smith }
164b6a7bef2SMike Smith if (drv->pd_flags2 & MLX_PHYS_DRV_WIDE)
165b6a7bef2SMike Smith printf(" wide");
166b6a7bef2SMike Smith if (drv->pd_flags2 & MLX_PHYS_DRV_SYNC)
167b6a7bef2SMike Smith printf(" sync");
168b6a7bef2SMike Smith if (drv->pd_flags2 & MLX_PHYS_DRV_TAG)
169b6a7bef2SMike Smith printf(" tag-enabled");
170b6a7bef2SMike Smith printf("\n");
171b6a7bef2SMike Smith }
172b6a7bef2SMike Smith }
173