3 * Copyright (c) 2000 by Matthew Jacob
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * Alternatively, this software may be distributed under the terms of the
16 * the GNU Public License ("GPL").
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/endian.h>
36 #include <sys/types.h>
43 #include <cam/scsi/scsi_enc.h>
48 * offset by +20 degrees.
49 * The range of the value expresses a temperature between -19 and +235 degrees
50 * Celsius. A value of 00h is reserved.
52 #define TEMPERATURE_OFFSET 20
57 static char rbuf[132];
60 case ELMTYP_UNSPECIFIED:
61 sprintf(rbuf, "Unspecified");
64 sprintf(rbuf, "Device Slot");
67 sprintf(rbuf, "Power Supply");
70 sprintf(rbuf, "Cooling");
73 sprintf(rbuf, "Temperature Sensors");
76 sprintf(rbuf, "Door Lock");
79 sprintf(rbuf, "Audible alarm");
82 sprintf(rbuf, "Enclosure Services Controller Electronics");
85 sprintf(rbuf, "SCC Controller Electronics");
88 sprintf(rbuf, "Nonvolatile Cache");
90 case ELMTYP_INV_OP_REASON:
91 sprintf(rbuf, "Invalid Operation Reason");
94 sprintf(rbuf, "Uninterruptible Power Supply");
97 sprintf(rbuf, "Display");
100 sprintf(rbuf, "Key Pad Entry");
102 case ELMTYP_ENCLOSURE:
103 sprintf(rbuf, "Enclosure");
106 sprintf(rbuf, "SCSI Port/Transceiver");
108 case ELMTYP_LANGUAGE:
109 sprintf(rbuf, "Language");
112 sprintf(rbuf, "Communication Port");
115 sprintf(rbuf, "Voltage Sensor");
118 sprintf(rbuf, "Current Sensor");
120 case ELMTYP_SCSI_TGT:
121 sprintf(rbuf, "SCSI Target Port");
123 case ELMTYP_SCSI_INI:
124 sprintf(rbuf, "SCSI Initiator Port");
127 sprintf(rbuf, "Simple Subenclosure");
129 case ELMTYP_ARRAY_DEV:
130 sprintf(rbuf, "Array Device Slot");
133 sprintf(rbuf, "SAS Expander");
135 case ELMTYP_SAS_CONN:
136 sprintf(rbuf, "SAS Connector");
139 (void) sprintf(rbuf, "<Type 0x%x>", type);
146 scode2ascii(u_char code)
148 static char rbuf[32];
149 switch (code & 0xf) {
150 case SES_OBJSTAT_UNSUPPORTED:
151 sprintf(rbuf, "Unsupported");
156 case SES_OBJSTAT_CRIT:
157 sprintf(rbuf, "Critical");
159 case SES_OBJSTAT_NONCRIT:
160 sprintf(rbuf, "Noncritical");
162 case SES_OBJSTAT_UNRECOV:
163 sprintf(rbuf, "Unrecoverable");
165 case SES_OBJSTAT_NOTINSTALLED:
166 sprintf(rbuf, "Not Installed");
168 case SES_OBJSTAT_UNKNOWN:
169 sprintf(rbuf, "Unknown");
171 case SES_OBJSTAT_NOTAVAIL:
172 sprintf(rbuf, "Not Available");
174 case SES_OBJSTAT_NOACCESS:
175 sprintf(rbuf, "No Access Allowed");
178 sprintf(rbuf, "<Status 0x%x>", code & 0xf);
185 stat2sbuf(int eletype, u_char *cstat)
189 buf = sbuf_new_auto();
191 err(EXIT_FAILURE, "sbuf_new_auto()");
194 sbuf_printf(buf, "\t\t- Predicted Failure\n");
196 sbuf_printf(buf, "\t\t- Disabled\n");
198 sbuf_printf(buf, "\t\t- Swapped\n");
202 sbuf_printf(buf, "\t\t- LED=locate\n");
204 sbuf_printf(buf, "\t\t- LED=fault\n");
206 case ELMTYP_ARRAY_DEV:
208 sbuf_printf(buf, "\t\t- LED=locate\n");
210 sbuf_printf(buf, "\t\t- LED=fault\n");
213 sbuf_printf(buf, "\t\t- Speed: %d rpm\n",
214 (((0x7 & cstat[1]) << 8) + cstat[2]) * 10);
218 sbuf_printf(buf, "\t\t- Temperature: %d C\n",
219 cstat[2] - TEMPERATURE_OFFSET);
221 sbuf_printf(buf, "\t\t- Temperature: -reserved-\n");
225 sbuf_printf(buf, "\t\t- Voltage: %.2f V\n",
226 be16dec(cstat + 2) / 100.0);