xref: /dragonfly/usr.sbin/mlxcontrol/util.c (revision 86d7f5d3)
1*86d7f5d3SJohn Marino /*-
2*86d7f5d3SJohn Marino  * Copyright (c) 1999 Michael Smith
3*86d7f5d3SJohn Marino  * All rights reserved.
4*86d7f5d3SJohn Marino  *
5*86d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
6*86d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
7*86d7f5d3SJohn Marino  * are met:
8*86d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
11*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
12*86d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
13*86d7f5d3SJohn Marino  *
14*86d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*86d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*86d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*86d7f5d3SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*86d7f5d3SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*86d7f5d3SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*86d7f5d3SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*86d7f5d3SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*86d7f5d3SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*86d7f5d3SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*86d7f5d3SJohn Marino  * SUCH DAMAGE.
25*86d7f5d3SJohn Marino  *
26*86d7f5d3SJohn Marino  *	$FreeBSD: src/usr.sbin/mlxcontrol/util.c,v 1.2 2000/04/11 23:04:17 msmith Exp $
27*86d7f5d3SJohn Marino  */
28*86d7f5d3SJohn Marino 
29*86d7f5d3SJohn Marino #include <sys/types.h>
30*86d7f5d3SJohn Marino #include <stdio.h>
31*86d7f5d3SJohn Marino #include <paths.h>
32*86d7f5d3SJohn Marino #include <string.h>
33*86d7f5d3SJohn Marino 
34*86d7f5d3SJohn Marino #include <dev/raid/mlx/mlxio.h>
35*86d7f5d3SJohn Marino #include <dev/raid/mlx/mlxreg.h>
36*86d7f5d3SJohn Marino 
37*86d7f5d3SJohn Marino #include "mlxcontrol.h"
38*86d7f5d3SJohn Marino 
39*86d7f5d3SJohn Marino /********************************************************************************
40*86d7f5d3SJohn Marino  * Various name-producing and -parsing functions
41*86d7f5d3SJohn Marino  */
42*86d7f5d3SJohn Marino 
43*86d7f5d3SJohn Marino /* return path of controller (unit) */
44*86d7f5d3SJohn Marino char *
ctrlrpath(int unit)45*86d7f5d3SJohn Marino ctrlrpath(int unit)
46*86d7f5d3SJohn Marino {
47*86d7f5d3SJohn Marino     static char	buf[32];
48*86d7f5d3SJohn Marino 
49*86d7f5d3SJohn Marino     sprintf(buf, "%s%s", _PATH_DEV, ctrlrname(unit));
50*86d7f5d3SJohn Marino     return(buf);
51*86d7f5d3SJohn Marino }
52*86d7f5d3SJohn Marino 
53*86d7f5d3SJohn Marino /* return name of controller (unit) */
54*86d7f5d3SJohn Marino char *
ctrlrname(int unit)55*86d7f5d3SJohn Marino ctrlrname(int unit)
56*86d7f5d3SJohn Marino {
57*86d7f5d3SJohn Marino     static char	buf[32];
58*86d7f5d3SJohn Marino 
59*86d7f5d3SJohn Marino     sprintf(buf, "mlx%d", unit);
60*86d7f5d3SJohn Marino     return(buf);
61*86d7f5d3SJohn Marino }
62*86d7f5d3SJohn Marino 
63*86d7f5d3SJohn Marino /* return path of drive (unit) */
64*86d7f5d3SJohn Marino char *
drivepath(int unit)65*86d7f5d3SJohn Marino drivepath(int unit)
66*86d7f5d3SJohn Marino {
67*86d7f5d3SJohn Marino     static char	buf[32];
68*86d7f5d3SJohn Marino 
69*86d7f5d3SJohn Marino     sprintf(buf, "%s%s", _PATH_DEV, drivename(unit));
70*86d7f5d3SJohn Marino     return(buf);
71*86d7f5d3SJohn Marino }
72*86d7f5d3SJohn Marino 
73*86d7f5d3SJohn Marino /* return name of drive (unit) */
74*86d7f5d3SJohn Marino char *
drivename(int unit)75*86d7f5d3SJohn Marino drivename(int unit)
76*86d7f5d3SJohn Marino {
77*86d7f5d3SJohn Marino     static char	buf[32];
78*86d7f5d3SJohn Marino 
79*86d7f5d3SJohn Marino     sprintf(buf, "mlxd%d", unit);
80*86d7f5d3SJohn Marino     return(buf);
81*86d7f5d3SJohn Marino }
82*86d7f5d3SJohn Marino 
83*86d7f5d3SJohn Marino /* get controller unit number from name in (str) */
84*86d7f5d3SJohn Marino int
ctrlrunit(char * str)85*86d7f5d3SJohn Marino ctrlrunit(char *str)
86*86d7f5d3SJohn Marino {
87*86d7f5d3SJohn Marino     int		unit;
88*86d7f5d3SJohn Marino 
89*86d7f5d3SJohn Marino     if (sscanf(str, "mlx%d", &unit) == 1)
90*86d7f5d3SJohn Marino 	return(unit);
91*86d7f5d3SJohn Marino     return(-1);
92*86d7f5d3SJohn Marino }
93*86d7f5d3SJohn Marino 
94*86d7f5d3SJohn Marino /* get drive unit number from name in (str) */
95*86d7f5d3SJohn Marino int
driveunit(char * str)96*86d7f5d3SJohn Marino driveunit(char *str)
97*86d7f5d3SJohn Marino {
98*86d7f5d3SJohn Marino     int		unit;
99*86d7f5d3SJohn Marino 
100*86d7f5d3SJohn Marino     if (sscanf(str, "mlxd%d", &unit) == 1)
101*86d7f5d3SJohn Marino 	return(unit);
102*86d7f5d3SJohn Marino     return(-1);
103*86d7f5d3SJohn Marino }
104*86d7f5d3SJohn Marino 
105*86d7f5d3SJohn Marino /********************************************************************************
106*86d7f5d3SJohn Marino  * Standardised output of various data structures.
107*86d7f5d3SJohn Marino  */
108*86d7f5d3SJohn Marino 
109*86d7f5d3SJohn Marino void
mlx_print_phys_drv(struct mlx_phys_drv * drv,int chn,int targ,const char * prefix,int verbose)110*86d7f5d3SJohn Marino mlx_print_phys_drv(struct mlx_phys_drv *drv, int chn, int targ, const char *prefix, int verbose)
111*86d7f5d3SJohn Marino {
112*86d7f5d3SJohn Marino     const char	*type;
113*86d7f5d3SJohn Marino     char	*device, *vendor, *revision;
114*86d7f5d3SJohn Marino 
115*86d7f5d3SJohn Marino     switch(drv->pd_flags2 & 0x03) {
116*86d7f5d3SJohn Marino     case MLX_PHYS_DRV_DISK:
117*86d7f5d3SJohn Marino 	type = "disk";
118*86d7f5d3SJohn Marino 	break;
119*86d7f5d3SJohn Marino     case MLX_PHYS_DRV_SEQUENTIAL:
120*86d7f5d3SJohn Marino 	type = "tape";
121*86d7f5d3SJohn Marino 	break;
122*86d7f5d3SJohn Marino     case MLX_PHYS_DRV_CDROM:
123*86d7f5d3SJohn Marino 	type= "cdrom";
124*86d7f5d3SJohn Marino 	break;
125*86d7f5d3SJohn Marino     case MLX_PHYS_DRV_OTHER:
126*86d7f5d3SJohn Marino     default:
127*86d7f5d3SJohn Marino 	type = "unknown";
128*86d7f5d3SJohn Marino 	break;
129*86d7f5d3SJohn Marino     }
130*86d7f5d3SJohn Marino     printf("%s%s%02d%02d ", prefix, type, chn, targ);
131*86d7f5d3SJohn Marino     switch(drv->pd_status) {
132*86d7f5d3SJohn Marino     case MLX_PHYS_DRV_DEAD:
133*86d7f5d3SJohn Marino 	printf(" (dead)       ");
134*86d7f5d3SJohn Marino 	break;
135*86d7f5d3SJohn Marino     case MLX_PHYS_DRV_WRONLY:
136*86d7f5d3SJohn Marino 	printf(" (write-only) ");
137*86d7f5d3SJohn Marino 	break;
138*86d7f5d3SJohn Marino     case MLX_PHYS_DRV_ONLINE:
139*86d7f5d3SJohn Marino 	printf(" (online)     ");
140*86d7f5d3SJohn Marino 	break;
141*86d7f5d3SJohn Marino     case MLX_PHYS_DRV_STANDBY:
142*86d7f5d3SJohn Marino 	printf(" (standby)    ");
143*86d7f5d3SJohn Marino 	break;
144*86d7f5d3SJohn Marino     default:
145*86d7f5d3SJohn Marino 	printf(" (0x%02x)   ", drv->pd_status);
146*86d7f5d3SJohn Marino     }
147*86d7f5d3SJohn Marino     printf("\n");
148*86d7f5d3SJohn Marino 
149*86d7f5d3SJohn Marino     if (verbose) {
150*86d7f5d3SJohn Marino 
151*86d7f5d3SJohn Marino 	printf("%s   ", prefix);
152*86d7f5d3SJohn Marino 	if (!mlx_scsi_inquiry(0, chn, targ, &vendor, &device, &revision)) {
153*86d7f5d3SJohn Marino 	    printf("'%8.8s' '%16.16s' '%4.4s'", vendor, device, revision);
154*86d7f5d3SJohn Marino 	} else {
155*86d7f5d3SJohn Marino 	    printf("<IDENTIFY FAILED>");
156*86d7f5d3SJohn Marino 	}
157*86d7f5d3SJohn Marino 
158*86d7f5d3SJohn Marino 	printf(" %dMB ", drv->pd_config_size / 2048);
159*86d7f5d3SJohn Marino 
160*86d7f5d3SJohn Marino 	if (drv->pd_flags2 & MLX_PHYS_DRV_FAST20) {
161*86d7f5d3SJohn Marino 	    printf(" fast20");
162*86d7f5d3SJohn Marino 	} else if (drv->pd_flags2 & MLX_PHYS_DRV_FAST) {
163*86d7f5d3SJohn Marino 	    printf(" fast");
164*86d7f5d3SJohn Marino 	}
165*86d7f5d3SJohn Marino 	if (drv->pd_flags2 & MLX_PHYS_DRV_WIDE)
166*86d7f5d3SJohn Marino 	    printf(" wide");
167*86d7f5d3SJohn Marino 	if (drv->pd_flags2 & MLX_PHYS_DRV_SYNC)
168*86d7f5d3SJohn Marino 	    printf(" sync");
169*86d7f5d3SJohn Marino 	if (drv->pd_flags2 & MLX_PHYS_DRV_TAG)
170*86d7f5d3SJohn Marino 	    printf(" tag-enabled");
171*86d7f5d3SJohn Marino 	printf("\n");
172*86d7f5d3SJohn Marino     }
173*86d7f5d3SJohn Marino }
174