1 /* $FreeBSD$ */ 2 /* 3 * Copyright (c) 2000 by Matthew Jacob 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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. 14 * 15 * Alternatively, this software may be distributed under the terms of the 16 * the GNU Public License ("GPL"). 17 * 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 28 * SUCH DAMAGE. 29 * 30 * Matthew Jacob 31 * Feral Software 32 * mjacob@feral.com 33 */ 34 35 #include <sys/endian.h> 36 #include <sys/types.h> 37 #include <sys/sbuf.h> 38 39 #include <err.h> 40 #include <unistd.h> 41 #include <stddef.h> 42 #include <stdint.h> 43 #include <stdlib.h> 44 #include <stdio.h> 45 #include <sys/ioctl.h> 46 #include <cam/scsi/scsi_all.h> 47 #include <cam/scsi/scsi_enc.h> 48 49 #include "eltsub.h" 50 51 /* 52 * offset by +20 degrees. 53 * The range of the value expresses a temperature between -19 and +235 degrees 54 * Celsius. A value of 00h is reserved. 55 */ 56 #define TEMPERATURE_OFFSET 20 57 58 char * 59 geteltnm(int type) 60 { 61 static char rbuf[132]; 62 63 switch (type) { 64 case ELMTYP_UNSPECIFIED: 65 sprintf(rbuf, "Unspecified"); 66 break; 67 case ELMTYP_DEVICE: 68 sprintf(rbuf, "Device Slot"); 69 break; 70 case ELMTYP_POWER: 71 sprintf(rbuf, "Power Supply"); 72 break; 73 case ELMTYP_FAN: 74 sprintf(rbuf, "Cooling"); 75 break; 76 case ELMTYP_THERM: 77 sprintf(rbuf, "Temperature Sensors"); 78 break; 79 case ELMTYP_DOORLOCK: 80 sprintf(rbuf, "Door Lock"); 81 break; 82 case ELMTYP_ALARM: 83 sprintf(rbuf, "Audible alarm"); 84 break; 85 case ELMTYP_ESCC: 86 sprintf(rbuf, "Enclosure Services Controller Electronics"); 87 break; 88 case ELMTYP_SCC: 89 sprintf(rbuf, "SCC Controller Electronics"); 90 break; 91 case ELMTYP_NVRAM: 92 sprintf(rbuf, "Nonvolatile Cache"); 93 break; 94 case ELMTYP_INV_OP_REASON: 95 sprintf(rbuf, "Invalid Operation Reason"); 96 break; 97 case ELMTYP_UPS: 98 sprintf(rbuf, "Uninterruptible Power Supply"); 99 break; 100 case ELMTYP_DISPLAY: 101 sprintf(rbuf, "Display"); 102 break; 103 case ELMTYP_KEYPAD: 104 sprintf(rbuf, "Key Pad Entry"); 105 break; 106 case ELMTYP_ENCLOSURE: 107 sprintf(rbuf, "Enclosure"); 108 break; 109 case ELMTYP_SCSIXVR: 110 sprintf(rbuf, "SCSI Port/Transceiver"); 111 break; 112 case ELMTYP_LANGUAGE: 113 sprintf(rbuf, "Language"); 114 break; 115 case ELMTYP_COMPORT: 116 sprintf(rbuf, "Communication Port"); 117 break; 118 case ELMTYP_VOM: 119 sprintf(rbuf, "Voltage Sensor"); 120 break; 121 case ELMTYP_AMMETER: 122 sprintf(rbuf, "Current Sensor"); 123 break; 124 case ELMTYP_SCSI_TGT: 125 sprintf(rbuf, "SCSI Target Port"); 126 break; 127 case ELMTYP_SCSI_INI: 128 sprintf(rbuf, "SCSI Initiator Port"); 129 break; 130 case ELMTYP_SUBENC: 131 sprintf(rbuf, "Simple Subenclosure"); 132 break; 133 case ELMTYP_ARRAY_DEV: 134 sprintf(rbuf, "Array Device Slot"); 135 break; 136 case ELMTYP_SAS_EXP: 137 sprintf(rbuf, "SAS Expander"); 138 break; 139 case ELMTYP_SAS_CONN: 140 sprintf(rbuf, "SAS Connector"); 141 break; 142 default: 143 (void) sprintf(rbuf, "<Type 0x%x>", type); 144 break; 145 } 146 return (rbuf); 147 } 148 149 char * 150 scode2ascii(u_char code) 151 { 152 static char rbuf[32]; 153 switch (code & 0xf) { 154 case SES_OBJSTAT_UNSUPPORTED: 155 sprintf(rbuf, "Unsupported"); 156 break; 157 case SES_OBJSTAT_OK: 158 sprintf(rbuf, "OK"); 159 break; 160 case SES_OBJSTAT_CRIT: 161 sprintf(rbuf, "Critical"); 162 break; 163 case SES_OBJSTAT_NONCRIT: 164 sprintf(rbuf, "Noncritical"); 165 break; 166 case SES_OBJSTAT_UNRECOV: 167 sprintf(rbuf, "Unrecoverable"); 168 break; 169 case SES_OBJSTAT_NOTINSTALLED: 170 sprintf(rbuf, "Not Installed"); 171 break; 172 case SES_OBJSTAT_UNKNOWN: 173 sprintf(rbuf, "Unknown"); 174 break; 175 case SES_OBJSTAT_NOTAVAIL: 176 sprintf(rbuf, "Not Available"); 177 break; 178 case SES_OBJSTAT_NOACCESS: 179 sprintf(rbuf, "No Access Allowed"); 180 break; 181 default: 182 sprintf(rbuf, "<Status 0x%x>", code & 0xf); 183 break; 184 } 185 return (rbuf); 186 } 187 188 struct sbuf * 189 stat2sbuf(int eletype, u_char *cstat) 190 { 191 struct sbuf *buf; 192 193 buf = sbuf_new_auto(); 194 if (buf == NULL) 195 err(EXIT_FAILURE, "sbuf_new_auto()"); 196 197 if (cstat[0] & 0x40) 198 sbuf_printf(buf, "\t\t- Predicted Failure\n"); 199 if (cstat[0] & 0x20) 200 sbuf_printf(buf, "\t\t- Disabled\n"); 201 if (cstat[0] & 0x10) 202 sbuf_printf(buf, "\t\t- Swapped\n"); 203 switch (eletype) { 204 case ELMTYP_DEVICE: 205 if (cstat[2] & 0x02) 206 sbuf_printf(buf, "\t\t- LED=locate\n"); 207 if (cstat[2] & 0x20) 208 sbuf_printf(buf, "\t\t- LED=fault\n"); 209 break; 210 case ELMTYP_ARRAY_DEV: 211 if (cstat[2] & 0x02) 212 sbuf_printf(buf, "\t\t- LED=locate\n"); 213 if (cstat[2] & 0x20) 214 sbuf_printf(buf, "\t\t- LED=fault\n"); 215 break; 216 case ELMTYP_FAN: 217 sbuf_printf(buf, "\t\t- Speed: %d rpm\n", 218 (((0x7 & cstat[1]) << 8) + cstat[2]) * 10); 219 break; 220 case ELMTYP_THERM: 221 if (cstat[2]) { 222 sbuf_printf(buf, "\t\t- Temperature: %d C\n", 223 cstat[2] - TEMPERATURE_OFFSET); 224 } else { 225 sbuf_printf(buf, "\t\t- Temperature: -reserved-\n"); 226 } 227 break; 228 case ELMTYP_VOM: 229 sbuf_printf(buf, "\t\t- Voltage: %.2f V\n", 230 be16dec(cstat + 2) / 100.0); 231 break; 232 } 233 sbuf_finish(buf); 234 return (buf); 235 } 236