Mon Mar 16 11:18:10 2009 UTC ()
fix sign-compare issues


(lukem)
diff -r1.1 -r1.2 src/sbin/amrctl/amrctl.c

cvs diff -r1.1 -r1.2 src/sbin/amrctl/amrctl.c (switch to unified diff)

--- src/sbin/amrctl/amrctl.c 2006/07/23 12:01:26 1.1
+++ src/sbin/amrctl/amrctl.c 2009/03/16 11:18:10 1.2
@@ -1,683 +1,683 @@ @@ -1,683 +1,683 @@
1/*- 1/*-
2 * Copyright (c) 2002, Pierre David <Pierre.David@crc.u-strasbg.fr> 2 * Copyright (c) 2002, Pierre David <Pierre.David@crc.u-strasbg.fr>
3 * Copyright (c) 2006, Jung-uk Kim <jkim@FreeBSD.org> 3 * Copyright (c) 2006, Jung-uk Kim <jkim@FreeBSD.org>
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following 10 * notice unmodified, this list of conditions, and the following
11 * disclaimer. 11 * disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29 29
30#include <stdio.h> 30#include <stdio.h>
31#include <stdlib.h> 31#include <stdlib.h>
32#include <string.h> 32#include <string.h>
33#include <fcntl.h> 33#include <fcntl.h>
34#include <errno.h> 34#include <errno.h>
35#include <unistd.h> 35#include <unistd.h>
36 36
37#include <sys/ioctl.h> 37#include <sys/ioctl.h>
38 38
39#include <machine/param.h> 39#include <machine/param.h>
40 40
41#include <dev/pci/amrio.h> 41#include <dev/pci/amrio.h>
42#include <dev/pci/amrreg.h> 42#include <dev/pci/amrreg.h>
43 43
44#define NATTEMPTS 5 44#define NATTEMPTS 5
45#define SLEEPTIME 100000 /* microseconds */ 45#define SLEEPTIME 100000 /* microseconds */
46 46
47int nattempts = NATTEMPTS; /* # of attempts before giving up */ 47int nattempts = NATTEMPTS; /* # of attempts before giving up */
48int sleeptime = SLEEPTIME; /* between attempts, in ms */ 48int sleeptime = SLEEPTIME; /* between attempts, in ms */
49 49
50#define AMR_BUFSIZE 1024 50#define AMR_BUFSIZE 1024
51 51
52int enq_result = AMR_STATUS_FAILED; 52int enq_result = AMR_STATUS_FAILED;
53char enq_buffer[AMR_BUFSIZE]; 53char enq_buffer[AMR_BUFSIZE];
54 54
55#define AMR_MAX_NCTRLS 16 55#define AMR_MAX_NCTRLS 16
56#define AMR_MAX_NSDEVS 16 56#define AMR_MAX_NSDEVS 16
57 57
58u_int8_t nschan = 0; 58u_int8_t nschan = 0;
59 59
60/* 60/*
61 * Include lookup tables, and a function to match a code to a string. 61 * Include lookup tables, and a function to match a code to a string.
62 * 62 *
63 * XXX Lookup tables cannot be included, since they require symbols from 63 * XXX Lookup tables cannot be included, since they require symbols from
64 * amrreg.h which need in turn the _KERNEL define. 64 * amrreg.h which need in turn the _KERNEL define.
65 */ 65 */
66 66
67/* #define AMR_DEFINE_TABLES */ 67/* #define AMR_DEFINE_TABLES */
68/* #include "amr_tables.h" */ 68/* #include "amr_tables.h" */
69 69
70int amr_ioctl_enquiry(int, u_int8_t, u_int8_t, u_int8_t); 70int amr_ioctl_enquiry(int, u_int8_t, u_int8_t, u_int8_t);
71void usage(char *); 71void usage(char *);
72int describe_card(int, int, int); 72int describe_card(int, int, int);
73char * describe_property(u_int8_t, char *); 73char * describe_property(u_int8_t, char *);
74const char * describe_state(int, u_int8_t); 74const char * describe_state(int, u_int8_t);
75void describe_battery(int, int, int, int, int); 75void describe_battery(int, int, int, int, int);
76void describe_one_volume(int, int, u_int32_t, u_int8_t, u_int8_t); 76void describe_one_volume(int, int, u_int32_t, u_int8_t, u_int8_t);
77void describe_one_drive(int, int, u_int8_t); 77void describe_one_drive(int, int, u_int8_t);
78void describe_drive(int, int, int, int, int); 78void describe_drive(int, int, int, int, int);
79 79
80/* 80/*
81 * Offsets in an amr_user_ioctl.au_cmd [] array See amrio.h 81 * Offsets in an amr_user_ioctl.au_cmd [] array See amrio.h
82 */ 82 */
83 83
84#define MB_COMMAND 0 84#define MB_COMMAND 0
85#define MB_CHANNEL 1 85#define MB_CHANNEL 1
86#define MB_PARAM 2 86#define MB_PARAM 2
87#define MB_PAD 3 87#define MB_PAD 3
88#define MB_DRIVE 4 88#define MB_DRIVE 4
89 89
90#define FIRMWARE_40LD 1 90#define FIRMWARE_40LD 1
91#define FIRMWARE_8LD 2 91#define FIRMWARE_8LD 2
92 92
93static struct { 93static struct {
94 const char *product; 94 const char *product;
95 const int signature; 95 const uint32_t signature;
96} prodtable[] = { 96} prodtable[] = {
97 { "Series 431", AMR_SIG_431 }, 97 { "Series 431", AMR_SIG_431 },
98 { "Series 438", AMR_SIG_438 }, 98 { "Series 438", AMR_SIG_438 },
99 { "Series 762", AMR_SIG_762 }, 99 { "Series 762", AMR_SIG_762 },
100 { "Integrated HP NetRAID (T5)", AMR_SIG_T5 }, 100 { "Integrated HP NetRAID (T5)", AMR_SIG_T5 },
101 { "Series 466", AMR_SIG_466 }, 101 { "Series 466", AMR_SIG_466 },
102 { "Series 467", AMR_SIG_467 }, 102 { "Series 467", AMR_SIG_467 },
103 { "Integrated HP NetRAID (T7)", AMR_SIG_T7 }, 103 { "Integrated HP NetRAID (T7)", AMR_SIG_T7 },
104 { "Series 490", AMR_SIG_490 } 104 { "Series 490", AMR_SIG_490 }
105}; 105};
106 106
107static struct { 107static struct {
108 const int code; 108 const int code;
109 const char *ifyes, *ifno; 109 const char *ifyes, *ifno;
110} proptable[] = { 110} proptable[] = {
111 { AMR_DRV_WRITEBACK, 111 { AMR_DRV_WRITEBACK,
112 "writeback", "write-through" }, 112 "writeback", "write-through" },
113 { AMR_DRV_READHEAD, 113 { AMR_DRV_READHEAD,
114 "read-ahead", "no-read-ahead" }, 114 "read-ahead", "no-read-ahead" },
115 { AMR_DRV_ADAPTIVE, 115 { AMR_DRV_ADAPTIVE,
116 "adaptative-io", "no-adaptative-io" } 116 "adaptative-io", "no-adaptative-io" }
117}; 117};
118 118
119static struct { 119static struct {
120 const int code; 120 const int code;
121 const char *status; 121 const char *status;
122} statetable[] = { 122} statetable[] = {
123 { AMR_DRV_OFFLINE, "offline" }, 123 { AMR_DRV_OFFLINE, "offline" },
124 { AMR_DRV_DEGRADED, "degraded" }, 124 { AMR_DRV_DEGRADED, "degraded" },
125 { AMR_DRV_OPTIMAL, "optimal" }, 125 { AMR_DRV_OPTIMAL, "optimal" },
126 { AMR_DRV_ONLINE, "online" }, 126 { AMR_DRV_ONLINE, "online" },
127 { AMR_DRV_FAILED, "failed" }, 127 { AMR_DRV_FAILED, "failed" },
128 { AMR_DRV_REBUILD, "rebuild" }, 128 { AMR_DRV_REBUILD, "rebuild" },
129 { AMR_DRV_HOTSPARE, "hotspare" } 129 { AMR_DRV_HOTSPARE, "hotspare" }
130}; 130};
131 131
132static struct { 132static struct {
133 const u_int8_t code; 133 const u_int8_t code;
134 const char *status; 134 const char *status;
135} battable[] = { 135} battable[] = {
136 { AMR_BATT_MODULE_MISSING, "not present" }, 136 { AMR_BATT_MODULE_MISSING, "not present" },
137 { AMR_BATT_LOW_VOLTAGE, "low voltage" }, 137 { AMR_BATT_LOW_VOLTAGE, "low voltage" },
138 { AMR_BATT_TEMP_HIGH, "high temperature" }, 138 { AMR_BATT_TEMP_HIGH, "high temperature" },
139 { AMR_BATT_PACK_MISSING, "pack missing" }, 139 { AMR_BATT_PACK_MISSING, "pack missing" },
140 { AMR_BATT_CYCLES_EXCEEDED, "cycle exceeded" } 140 { AMR_BATT_CYCLES_EXCEEDED, "cycle exceeded" }
141}; 141};
142 142
143static struct { 143static struct {
144 const u_int8_t code; 144 const u_int8_t code;
145 const char *status; 145 const char *status;
146} bcstatble[] = { 146} bcstatble[] = {
147 { AMR_BATT_CHARGE_DONE, "charge done" }, 147 { AMR_BATT_CHARGE_DONE, "charge done" },
148 { AMR_BATT_CHARGE_INPROG, "charge in progress" }, 148 { AMR_BATT_CHARGE_INPROG, "charge in progress" },
149 { AMR_BATT_CHARGE_FAIL, "charge failed" } 149 { AMR_BATT_CHARGE_FAIL, "charge failed" }
150}; 150};
151 151
152#define NTAB(tab) (sizeof tab / sizeof tab [0]) 152#define NTAB(tab) (sizeof tab / sizeof tab [0])
153 153
154int 154int
155amr_ioctl_enquiry(int fd, u_int8_t cmd, u_int8_t cmdsub, u_int8_t cmdqual) 155amr_ioctl_enquiry(int fd, u_int8_t cmd, u_int8_t cmdsub, u_int8_t cmdqual)
156{ 156{
157 struct amr_user_ioctl am; 157 struct amr_user_ioctl am;
158 int r, i; 158 int r, i;
159 159
160 am.au_cmd[MB_COMMAND] = cmd; 160 am.au_cmd[MB_COMMAND] = cmd;
161 am.au_cmd[MB_CHANNEL] = cmdsub; 161 am.au_cmd[MB_CHANNEL] = cmdsub;
162 am.au_cmd[MB_PARAM] = cmdqual; 162 am.au_cmd[MB_PARAM] = cmdqual;
163 am.au_cmd[MB_PAD] = 0; 163 am.au_cmd[MB_PAD] = 0;
164 am.au_cmd[MB_DRIVE] = 0; 164 am.au_cmd[MB_DRIVE] = 0;
165 165
166 am.au_buffer = enq_buffer; 166 am.au_buffer = enq_buffer;
167 am.au_length = AMR_BUFSIZE; 167 am.au_length = AMR_BUFSIZE;
168 am.au_direction = AMR_IO_READ; 168 am.au_direction = AMR_IO_READ;
169 am.au_status = 0; 169 am.au_status = 0;
170 170
171 i = 0; 171 i = 0;
172 r = -1; 172 r = -1;
173 while (i < nattempts && r == -1) { 173 while (i < nattempts && r == -1) {
174 r = ioctl(fd, AMR_IO_COMMAND, &am); 174 r = ioctl(fd, AMR_IO_COMMAND, &am);
175 if (r == -1) { 175 if (r == -1) {
176 if (errno != EBUSY) { 176 if (errno != EBUSY) {
177 perror("ioctl enquiry"); 177 perror("ioctl enquiry");
178 exit(1); 178 exit(1);
179 } else 179 } else
180 usleep(sleeptime); 180 usleep(sleeptime);
181 } 181 }
182 i++; 182 i++;
183 } 183 }
184 return am.au_status; 184 return am.au_status;
185} 185}
186 186
187void 187void
188usage(char *prog) 188usage(char *prog)
189{ 189{
190 fprintf(stderr, "usage: %s stat [-a num] [-b] " 190 fprintf(stderr, "usage: %s stat [-a num] [-b] "
191 "[-c ctlr|-f dev] [-g] [-l vol]\n\t\t" 191 "[-c ctlr|-f dev] [-g] [-l vol]\n\t\t"
192 "[-p drive|-s bus[:target]] [-t usec] [-v]\n\n\t" 192 "[-p drive|-s bus[:target]] [-t usec] [-v]\n\n\t"
193 "-a num\t\tnumber of retries\n\t" 193 "-a num\t\tnumber of retries\n\t"
194 "-b\t\tbattery status\n\t" 194 "-b\t\tbattery status\n\t"
195 "-c ctrl\t\tcontroller ID\n\t" 195 "-c ctrl\t\tcontroller ID\n\t"
196 "-f dev\t\tdevice path\n\t" 196 "-f dev\t\tdevice path\n\t"
197 "-g\t\tprint global parameters\n\t" 197 "-g\t\tprint global parameters\n\t"
198 "-l vol\t\tlogical volume ID\n\t" 198 "-l vol\t\tlogical volume ID\n\t"
199 "-p drive\tphysical drive ID\n\t" 199 "-p drive\tphysical drive ID\n\t"
200 "-s bus[:target]\tSCSI bus (and optinal target)\n\t" 200 "-s bus[:target]\tSCSI bus (and optinal target)\n\t"
201 "-t usec\t\tsleep time between retries\n\t" 201 "-t usec\t\tsleep time between retries\n\t"
202 "-v\t\tverbose output\n", 202 "-v\t\tverbose output\n",
203 prog); 203 prog);
204 exit(1); 204 exit(1);
205} 205}
206 206
207/****************************************************************************** 207/******************************************************************************
208 * Card description 208 * Card description
209 */ 209 */
210 210
211int 211int
212describe_card(int fd, int verbosity, int globalparam) 212describe_card(int fd, int verbosity, int globalparam)
213{ 213{
214 struct amr_enquiry *ae; 214 struct amr_enquiry *ae;
215 int cardtype; 215 uint32_t cardtype;
216 216
217 /* 217 /*
218 * Try the 40LD firmware interface 218 * Try the 40LD firmware interface
219 */ 219 */
220 220
221 enq_result = amr_ioctl_enquiry(fd, AMR_CMD_CONFIG, 221 enq_result = amr_ioctl_enquiry(fd, AMR_CMD_CONFIG,
222 AMR_CONFIG_PRODUCT_INFO, 0); 222 AMR_CONFIG_PRODUCT_INFO, 0);
223 if (enq_result == AMR_STATUS_SUCCESS) { 223 if (enq_result == AMR_STATUS_SUCCESS) {
224 struct amr_prodinfo *ap; 224 struct amr_prodinfo *ap;
225 225
226 ap = (struct amr_prodinfo *)enq_buffer; 226 ap = (struct amr_prodinfo *)enq_buffer;
227 nschan = ap->ap_nschan; 227 nschan = ap->ap_nschan;
228 if (globalparam) { 228 if (globalparam) {
229 printf("Product\t\t\t<%.80s>\n", ap->ap_product); 229 printf("Product\t\t\t<%.80s>\n", ap->ap_product);
230 printf("Firmware\t\t%.16s\n", ap->ap_firmware); 230 printf("Firmware\t\t%.16s\n", ap->ap_firmware);
231 printf("BIOS\t\t\t%.16s\n", ap->ap_bios); 231 printf("BIOS\t\t\t%.16s\n", ap->ap_bios);
232 printf("SCSI channels\t\t%d\n", ap->ap_nschan); 232 printf("SCSI channels\t\t%d\n", ap->ap_nschan);
233 printf("Fibre loops\t\t%d\n", ap->ap_fcloops); 233 printf("Fibre loops\t\t%d\n", ap->ap_fcloops);
234 printf("Memory size\t\t%d MB\n", ap->ap_memsize); 234 printf("Memory size\t\t%d MB\n", ap->ap_memsize);
235 if (verbosity >= 1) { 235 if (verbosity >= 1) {
236 printf("Ioctl\t\t\t%d (%s)\n", FIRMWARE_40LD, 236 printf("Ioctl\t\t\t%d (%s)\n", FIRMWARE_40LD,
237 "40LD"); 237 "40LD");
238 printf("Signature\t\t0x%08x\n", 238 printf("Signature\t\t0x%08x\n",
239 ap->ap_signature); 239 ap->ap_signature);
240 printf("Configsig\t\t0x%08x\n", 240 printf("Configsig\t\t0x%08x\n",
241 ap->ap_configsig); 241 ap->ap_configsig);
242 printf("Subsystem\t\t0x%04x\n", 242 printf("Subsystem\t\t0x%04x\n",
243 ap->ap_subsystem); 243 ap->ap_subsystem);
244 printf("Subvendor\t\t0x%04x\n", 244 printf("Subvendor\t\t0x%04x\n",
245 ap->ap_subvendor); 245 ap->ap_subvendor);
246 printf("Notify counters\t\t%d\n", 246 printf("Notify counters\t\t%d\n",
247 ap->ap_numnotifyctr); 247 ap->ap_numnotifyctr);
248 } 248 }
249 } 249 }
250 return FIRMWARE_40LD; 250 return FIRMWARE_40LD;
251 } 251 }
252 /* 252 /*
253 * Try the 8LD firmware interface 253 * Try the 8LD firmware interface
254 */ 254 */
255 255
256 enq_result = amr_ioctl_enquiry(fd, AMR_CMD_EXT_ENQUIRY2, 0, 0); 256 enq_result = amr_ioctl_enquiry(fd, AMR_CMD_EXT_ENQUIRY2, 0, 0);
257 ae = (struct amr_enquiry *)enq_buffer; 257 ae = (struct amr_enquiry *)enq_buffer;
258 if (enq_result == AMR_STATUS_SUCCESS) { 258 if (enq_result == AMR_STATUS_SUCCESS) {
259 cardtype = ae->ae_signature; 259 cardtype = ae->ae_signature;
260 } else { 260 } else {
261 enq_result = amr_ioctl_enquiry(fd, AMR_CMD_ENQUIRY, 0, 0); 261 enq_result = amr_ioctl_enquiry(fd, AMR_CMD_ENQUIRY, 0, 0);
262 cardtype = 0; 262 cardtype = 0;
263 } 263 }
264 264
265 if (enq_result == AMR_STATUS_SUCCESS) { 265 if (enq_result == AMR_STATUS_SUCCESS) {
266 266
267 if (globalparam) { 267 if (globalparam) {
268 const char *product = NULL; 268 const char *product = NULL;
269 char bios[100], firmware[100]; 269 char bios[100], firmware[100];
270 int i; 270 size_t i;
271 271
272 for (i = 0; i < NTAB(prodtable); i++) { 272 for (i = 0; i < NTAB(prodtable); i++) {
273 if (cardtype == prodtable[i].signature) { 273 if (cardtype == prodtable[i].signature) {
274 product = prodtable[i].product; 274 product = prodtable[i].product;
275 break; 275 break;
276 } 276 }
277 } 277 }
278 if (product == NULL) 278 if (product == NULL)
279 product = "unknown card signature"; 279 product = "unknown card signature";
280 280
281 /* 281 /*
282 * HP NetRaid controllers have a special encoding of 282 * HP NetRaid controllers have a special encoding of
283 * the firmware and BIOS versions. The AMI version 283 * the firmware and BIOS versions. The AMI version
284 * seems to have it as strings whereas the HP version 284 * seems to have it as strings whereas the HP version
285 * does it with a leading uppercase character and two 285 * does it with a leading uppercase character and two
286 * binary numbers. 286 * binary numbers.
287 */ 287 */
288 288
289 if (ae->ae_adapter.aa_firmware[2] >= 'A' && 289 if (ae->ae_adapter.aa_firmware[2] >= 'A' &&
290 ae->ae_adapter.aa_firmware[2] <= 'Z' && 290 ae->ae_adapter.aa_firmware[2] <= 'Z' &&
291 ae->ae_adapter.aa_firmware[1] < ' ' && 291 ae->ae_adapter.aa_firmware[1] < ' ' &&
292 ae->ae_adapter.aa_firmware[0] < ' ' && 292 ae->ae_adapter.aa_firmware[0] < ' ' &&
293 ae->ae_adapter.aa_bios[2] >= 'A' && 293 ae->ae_adapter.aa_bios[2] >= 'A' &&
294 ae->ae_adapter.aa_bios[2] <= 'Z' && 294 ae->ae_adapter.aa_bios[2] <= 'Z' &&
295 ae->ae_adapter.aa_bios[1] < ' ' && 295 ae->ae_adapter.aa_bios[1] < ' ' &&
296 ae->ae_adapter.aa_bios[0] < ' ') { 296 ae->ae_adapter.aa_bios[0] < ' ') {
297 297
298 /* 298 /*
299 * looks like we have an HP NetRaid version 299 * looks like we have an HP NetRaid version
300 * of the MegaRaid 300 * of the MegaRaid
301 */ 301 */
302 302
303 if (cardtype == AMR_SIG_438) { 303 if (cardtype == AMR_SIG_438) {
304 /* 304 /*
305 * the AMI 438 is a NetRaid 3si in 305 * the AMI 438 is a NetRaid 3si in
306 * HP-land 306 * HP-land
307 */ 307 */
308 product = "HP NetRaid 3si"; 308 product = "HP NetRaid 3si";
309 } 309 }
310 sprintf(firmware, "%c.%02d.%02d", 310 sprintf(firmware, "%c.%02d.%02d",
311 ae->ae_adapter.aa_firmware[2], 311 ae->ae_adapter.aa_firmware[2],
312 ae->ae_adapter.aa_firmware[1], 312 ae->ae_adapter.aa_firmware[1],
313 ae->ae_adapter.aa_firmware[0]); 313 ae->ae_adapter.aa_firmware[0]);
314 sprintf(bios, "%c.%02d.%02d", 314 sprintf(bios, "%c.%02d.%02d",
315 ae->ae_adapter.aa_bios[2], 315 ae->ae_adapter.aa_bios[2],
316 ae->ae_adapter.aa_bios[1], 316 ae->ae_adapter.aa_bios[1],
317 ae->ae_adapter.aa_bios[0]); 317 ae->ae_adapter.aa_bios[0]);
318 } else { 318 } else {
319 sprintf(firmware, "%.4s", 319 sprintf(firmware, "%.4s",
320 ae->ae_adapter.aa_firmware); 320 ae->ae_adapter.aa_firmware);
321 sprintf(bios, "%.4s", ae->ae_adapter.aa_bios); 321 sprintf(bios, "%.4s", ae->ae_adapter.aa_bios);
322 } 322 }
323 323
324 printf("Ioctl = %d (%s)\n", FIRMWARE_8LD, "8LD"); 324 printf("Ioctl = %d (%s)\n", FIRMWARE_8LD, "8LD");
325 printf("Product =\t<%s>\n", product); 325 printf("Product =\t<%s>\n", product);
326 printf("Firmware =\t%s\n", firmware); 326 printf("Firmware =\t%s\n", firmware);
327 printf("BIOS =\t%s\n", bios); 327 printf("BIOS =\t%s\n", bios);
328 /* printf ("SCSI Channels =\t%d\n", ae->ae_nschan); */ 328 /* printf ("SCSI Channels =\t%d\n", ae->ae_nschan); */
329 /* printf ("Fibre Loops =\t%d\n", ae->ae_fcloops); */ 329 /* printf ("Fibre Loops =\t%d\n", ae->ae_fcloops); */
330 printf("Memory size =\t%d MB\n", 330 printf("Memory size =\t%d MB\n",
331 ae->ae_adapter.aa_memorysize); 331 ae->ae_adapter.aa_memorysize);
332 /* 332 /*
333 * printf ("Notify counters =\t%d\n", 333 * printf ("Notify counters =\t%d\n",
334 * ae->ae_numnotifyctr) ; 334 * ae->ae_numnotifyctr) ;
335 */ 335 */
336 } 336 }
337 return FIRMWARE_8LD; 337 return FIRMWARE_8LD;
338 } 338 }
339 /* 339 /*
340 * Neither firmware interface succeeded. Abort. 340 * Neither firmware interface succeeded. Abort.
341 */ 341 */
342 342
343 fprintf(stderr, "Firmware interface not supported\n"); 343 fprintf(stderr, "Firmware interface not supported\n");
344 exit(1); 344 exit(1);
345 345
346} 346}
347 347
348char * 348char *
349describe_property(u_int8_t prop, char *buffer) 349describe_property(u_int8_t prop, char *buffer)
350{ 350{
351 int i; 351 size_t i;
352 352
353 strcpy(buffer, "<"); 353 strcpy(buffer, "<");
354 for (i = 0; i < NTAB(proptable); i++) { 354 for (i = 0; i < NTAB(proptable); i++) {
355 if (i > 0) 355 if (i > 0)
356 strcat(buffer, ","); 356 strcat(buffer, ",");
357 if (prop & proptable[i].code) 357 if (prop & proptable[i].code)
358 strcat(buffer, proptable[i].ifyes); 358 strcat(buffer, proptable[i].ifyes);
359 else 359 else
360 strcat(buffer, proptable[i].ifno); 360 strcat(buffer, proptable[i].ifno);
361 } 361 }
362 strcat(buffer, ">"); 362 strcat(buffer, ">");
363 363
364 return buffer; 364 return buffer;
365} 365}
366 366
367const char * 367const char *
368describe_state(int verbosity, u_int8_t state) 368describe_state(int verbosity, u_int8_t state)
369{ 369{
370 int i; 370 size_t i;
371 371
372 if ((AMR_DRV_PREVSTATE(state) == AMR_DRV_CURSTATE(state)) && 372 if ((AMR_DRV_PREVSTATE(state) == AMR_DRV_CURSTATE(state)) &&
373 (AMR_DRV_CURSTATE(state) == AMR_DRV_OFFLINE) && verbosity == 0) 373 (AMR_DRV_CURSTATE(state) == AMR_DRV_OFFLINE) && verbosity == 0)
374 return NULL; 374 return NULL;
375 375
376 for (i = 0; i < NTAB(statetable); i++) 376 for (i = 0; i < NTAB(statetable); i++)
377 if (AMR_DRV_CURSTATE(state) == statetable[i].code) 377 if (AMR_DRV_CURSTATE(state) == statetable[i].code)
378 return (statetable[i].status); 378 return (statetable[i].status);
379 379
380 return NULL; 380 return NULL;
381} 381}
382 382
383/****************************************************************************** 383/******************************************************************************
384 * Battery status 384 * Battery status
385 */ 385 */
386void 386void
387describe_battery(int fd, int verbosity, int fwint, int bflags, int globalparam) 387describe_battery(int fd, int verbosity, int fwint, int bflags, int globalparam)
388{ 388{
389 u_int8_t batt_status; 389 u_int8_t batt_status;
390 int i; 390 size_t i;
391 391
392 if (fwint == FIRMWARE_40LD) { 392 if (fwint == FIRMWARE_40LD) {
393 enq_result = amr_ioctl_enquiry(fd, AMR_CMD_CONFIG, 393 enq_result = amr_ioctl_enquiry(fd, AMR_CMD_CONFIG,
394 AMR_CONFIG_ENQ3, AMR_CONFIG_ENQ3_SOLICITED_FULL); 394 AMR_CONFIG_ENQ3, AMR_CONFIG_ENQ3_SOLICITED_FULL);
395 if (enq_result == AMR_STATUS_SUCCESS) { 395 if (enq_result == AMR_STATUS_SUCCESS) {
396 struct amr_enquiry3 *ae3; 396 struct amr_enquiry3 *ae3;
397 397
398 ae3 = (struct amr_enquiry3 *)enq_buffer; 398 ae3 = (struct amr_enquiry3 *)enq_buffer;
399 if (bflags || globalparam) { 399 if (bflags || globalparam) {
400 batt_status = ae3->ae_batterystatus; 400 batt_status = ae3->ae_batterystatus;
401 printf("Battery status\t\t"); 401 printf("Battery status\t\t");
402 for (i = 0; i < NTAB(battable); i++) { 402 for (i = 0; i < NTAB(battable); i++) {
403 if (batt_status & battable[i].code) 403 if (batt_status & battable[i].code)
404 printf("%s, ", battable[i].status); 404 printf("%s, ", battable[i].status);
405 } 405 }
406 if (!(batt_status & 406 if (!(batt_status &
407 (AMR_BATT_MODULE_MISSING|AMR_BATT_PACK_MISSING))) { 407 (AMR_BATT_MODULE_MISSING|AMR_BATT_PACK_MISSING))) {
408 for (i = 0; i < NTAB(bcstatble); i++) 408 for (i = 0; i < NTAB(bcstatble); i++)
409 if (bcstatble[i].code == 409 if (bcstatble[i].code ==
410 (batt_status & AMR_BATT_CHARGE_MASK)) 410 (batt_status & AMR_BATT_CHARGE_MASK))
411 printf("%s", bcstatble[i].status); 411 printf("%s", bcstatble[i].status);
412 } else 412 } else
413 printf("charge unknown"); 413 printf("charge unknown");
414 if (verbosity) 414 if (verbosity)
415 printf(" (0x%02x)", batt_status); 415 printf(" (0x%02x)", batt_status);
416 printf("\n"); 416 printf("\n");
417 } 417 }
418 } 418 }
419 } else if (fwint == FIRMWARE_8LD) { 419 } else if (fwint == FIRMWARE_8LD) {
420 /* Nothing to do here. */ 420 /* Nothing to do here. */
421 return; 421 return;
422 } else { 422 } else {
423 fprintf(stderr, "Firmware interface not supported.\n"); 423 fprintf(stderr, "Firmware interface not supported.\n");
424 exit(1); 424 exit(1);
425 } 425 }
426 426
427 return; 427 return;
428} 428}
429 429
430/****************************************************************************** 430/******************************************************************************
431 * Logical volumes 431 * Logical volumes
432 */ 432 */
433 433
434void 434void
435describe_one_volume(int ldrv, int verbosity, 435describe_one_volume(int ldrv, int verbosity,
436 u_int32_t size, u_int8_t state, u_int8_t prop) 436 u_int32_t size, u_int8_t state, u_int8_t prop)
437{ 437{
438 float szgb; 438 float szgb;
439 int raid_level; 439 int raid_level;
440 char propstr[MAXPATHLEN]; 440 char propstr[MAXPATHLEN];
441 const char *statestr; 441 const char *statestr;
442 442
443 szgb = ((float)size) / (1024 * 1024 * 2); /* size in GB */ 443 szgb = ((float)size) / (1024 * 1024 * 2); /* size in GB */
444 444
445 raid_level = prop & AMR_DRV_RAID_MASK; 445 raid_level = prop & AMR_DRV_RAID_MASK;
446 446
447 printf("Logical volume %d\t", ldrv); 447 printf("Logical volume %d\t", ldrv);
448 statestr = describe_state(verbosity, state); 448 statestr = describe_state(verbosity, state);
449 printf("%s ", statestr); 449 printf("%s ", statestr);
450 printf("(%.2f GB, RAID%d", szgb, raid_level); 450 printf("(%.2f GB, RAID%d", szgb, raid_level);
451 if (verbosity >= 1) { 451 if (verbosity >= 1) {
452 describe_property(prop, propstr); 452 describe_property(prop, propstr);
453 printf(" %s", propstr); 453 printf(" %s", propstr);
454 } 454 }
455 printf(")\n"); 455 printf(")\n");
456} 456}
457 457
458/****************************************************************************** 458/******************************************************************************
459 * Physical drives 459 * Physical drives
460 */ 460 */
461 461
462void 462void
463describe_one_drive(int pdrv, int verbosity, u_int8_t state) 463describe_one_drive(int pdrv, int verbosity, u_int8_t state)
464{ 464{
465 const char *statestr; 465 const char *statestr;
466 466
467 statestr = describe_state(verbosity, state); 467 statestr = describe_state(verbosity, state);
468 if (statestr) { 468 if (statestr) {
469 if (nschan > 0) 469 if (nschan > 0)
470 printf("Physical drive %d:%d\t%s\n", 470 printf("Physical drive %d:%d\t%s\n",
471 pdrv / AMR_MAX_NSDEVS, pdrv % AMR_MAX_NSDEVS, 471 pdrv / AMR_MAX_NSDEVS, pdrv % AMR_MAX_NSDEVS,
472 statestr); 472 statestr);
473 else 473 else
474 printf("Physical drive %d:\t%s\n", pdrv, statestr); 474 printf("Physical drive %d:\t%s\n", pdrv, statestr);
475 } 475 }
476} 476}
477 477
478void 478void
479describe_drive(int verbosity, int fwint, int ldrv, int sbus, int sdev) 479describe_drive(int verbosity, int fwint, int ldrv, int sbus, int sdev)
480{ 480{
481 int drv, pdrv = -1; 481 int drv, pdrv = -1;
482 482
483 if (sbus > -1 && sdev > -1) 483 if (sbus > -1 && sdev > -1)
484 pdrv = (sbus * AMR_MAX_NSDEVS) + sdev; 484 pdrv = (sbus * AMR_MAX_NSDEVS) + sdev;
485 if (nschan != 0) { 485 if (nschan != 0) {
486 if (sbus > -1 && sbus >= nschan) { 486 if (sbus > -1 && sbus >= nschan) {
487 fprintf(stderr, "SCSI channel %d does not exist.\n", sbus); 487 fprintf(stderr, "SCSI channel %d does not exist.\n", sbus);
488 exit(1); 488 exit(1);
489 } else if (sdev > -1 && sdev >= AMR_MAX_NSDEVS) { 489 } else if (sdev > -1 && sdev >= AMR_MAX_NSDEVS) {
490 fprintf(stderr, "SCSI device %d:%d does not exist.\n", 490 fprintf(stderr, "SCSI device %d:%d does not exist.\n",
491 sbus, sdev); 491 sbus, sdev);
492 exit(1); 492 exit(1);
493 } 493 }
494 } 494 }
495 if (fwint == FIRMWARE_40LD) { 495 if (fwint == FIRMWARE_40LD) {
496 if (enq_result == AMR_STATUS_SUCCESS) { 496 if (enq_result == AMR_STATUS_SUCCESS) {
497 struct amr_enquiry3 *ae3; 497 struct amr_enquiry3 *ae3;
498 498
499 ae3 = (struct amr_enquiry3 *)enq_buffer; 499 ae3 = (struct amr_enquiry3 *)enq_buffer;
500 if ((ldrv < 0 && sbus < 0) || ldrv >= 0) { 500 if ((ldrv < 0 && sbus < 0) || ldrv >= 0) {
501 if (ldrv >= ae3->ae_numldrives) { 501 if (ldrv >= ae3->ae_numldrives) {
502 fprintf(stderr, "Logical volume %d " 502 fprintf(stderr, "Logical volume %d "
503 "does not exist.\n", ldrv); 503 "does not exist.\n", ldrv);
504 exit(1); 504 exit(1);
505 } 505 }
506 if (ldrv < 0) { 506 if (ldrv < 0) {
507 for (drv = 0; 507 for (drv = 0;
508 drv < ae3->ae_numldrives; 508 drv < ae3->ae_numldrives;
509 drv++) 509 drv++)
510 describe_one_volume(drv, 510 describe_one_volume(drv,
511 verbosity, 511 verbosity,
512 ae3->ae_drivesize[drv], 512 ae3->ae_drivesize[drv],
513 ae3->ae_drivestate[drv], 513 ae3->ae_drivestate[drv],
514 ae3->ae_driveprop[drv]); 514 ae3->ae_driveprop[drv]);
515 } else { 515 } else {
516 describe_one_volume(ldrv, 516 describe_one_volume(ldrv,
517 verbosity, 517 verbosity,
518 ae3->ae_drivesize[ldrv], 518 ae3->ae_drivesize[ldrv],
519 ae3->ae_drivestate[ldrv], 519 ae3->ae_drivestate[ldrv],
520 ae3->ae_driveprop[ldrv]); 520 ae3->ae_driveprop[ldrv]);
521 } 521 }
522 } 522 }
523 if ((ldrv < 0 && sbus < 0) || sbus >= 0) { 523 if ((ldrv < 0 && sbus < 0) || sbus >= 0) {
524 if (pdrv >= AMR_40LD_MAXPHYSDRIVES || 524 if (pdrv >= AMR_40LD_MAXPHYSDRIVES ||
525 (nschan != 0 && pdrv >= (nschan * AMR_MAX_NSDEVS))) { 525 (nschan != 0 && pdrv >= (nschan * AMR_MAX_NSDEVS))) {
526 fprintf(stderr, "Physical drive %d " 526 fprintf(stderr, "Physical drive %d "
527 "is out of range.\n", pdrv); 527 "is out of range.\n", pdrv);
528 exit(1); 528 exit(1);
529 } 529 }
530 if (sbus < 0) { 530 if (sbus < 0) {
531 for (drv = 0; 531 for (drv = 0;
532 drv < AMR_40LD_MAXPHYSDRIVES; 532 drv < AMR_40LD_MAXPHYSDRIVES;
533 drv++) { 533 drv++) {
534 if (nschan != 0 && 534 if (nschan != 0 &&
535 drv >= (nschan * AMR_MAX_NSDEVS)) 535 drv >= (nschan * AMR_MAX_NSDEVS))
536 break; 536 break;
537 describe_one_drive(drv, 537 describe_one_drive(drv,
538 verbosity, 538 verbosity,
539 ae3->ae_pdrivestate[drv]); 539 ae3->ae_pdrivestate[drv]);
540 } 540 }
541 } else if (sdev < 0) { 541 } else if (sdev < 0) {
542 for (drv = sbus * AMR_MAX_NSDEVS; 542 for (drv = sbus * AMR_MAX_NSDEVS;
543 drv < ((sbus + 1) * AMR_MAX_NSDEVS); 543 drv < ((sbus + 1) * AMR_MAX_NSDEVS);
544 drv++) { 544 drv++) {
545 if (nschan != 0 && 545 if (nschan != 0 &&
546 drv >= (nschan * AMR_MAX_NSDEVS)) 546 drv >= (nschan * AMR_MAX_NSDEVS))
547 break; 547 break;
548 describe_one_drive(drv, 548 describe_one_drive(drv,
549 verbosity, 549 verbosity,
550 ae3->ae_pdrivestate[drv]); 550 ae3->ae_pdrivestate[drv]);
551 } 551 }
552 } else { 552 } else {
553 if (nschan != 0 && 553 if (nschan != 0 &&
554 pdrv < (nschan * AMR_MAX_NSDEVS)) 554 pdrv < (nschan * AMR_MAX_NSDEVS))
555 describe_one_drive(pdrv, 1, 555 describe_one_drive(pdrv, 1,
556 ae3->ae_pdrivestate[pdrv]); 556 ae3->ae_pdrivestate[pdrv]);
557 } 557 }
558 } 558 }
559 } 559 }
560 } else if (fwint == FIRMWARE_8LD) { 560 } else if (fwint == FIRMWARE_8LD) {
561 /* Nothing to do here. */ 561 /* Nothing to do here. */
562 return; 562 return;
563 } else { 563 } else {
564 fprintf(stderr, "Firmware interface not supported.\n"); 564 fprintf(stderr, "Firmware interface not supported.\n");
565 exit(1); 565 exit(1);
566 } 566 }
567} 567}
568 568
569/****************************************************************************** 569/******************************************************************************
570 * Main function 570 * Main function
571 */ 571 */
572 572
573int 573int
574main(int argc, char *argv[]) 574main(int argc, char *argv[])
575{ 575{
576 int i; 576 int i;
577 int fd = -1; 577 int fd = -1;
578 int globalparam = 0, verbosity = 0; 578 int globalparam = 0, verbosity = 0;
579 int bflags = 0, fflags = 0, sflags = 0; 579 int bflags = 0, fflags = 0, sflags = 0;
580 int lvolno = -1, physno = -1; 580 int lvolno = -1, physno = -1;
581 int sbusno = -1, targetno = -1; 581 int sbusno = -1, targetno = -1;
582 char filename[MAXPATHLEN]; 582 char filename[MAXPATHLEN];
583 char sdev[MAXPATHLEN]; 583 char sdev[MAXPATHLEN];
584 char *pdev; 584 char *pdev;
585 585
586 extern char *optarg; 586 extern char *optarg;
587 extern int optind; 587 extern int optind;
588 588
589 /* 589 /*
590 * Parse arguments 590 * Parse arguments
591 */ 591 */
592 if (argc < 2) 592 if (argc < 2)
593 usage(argv[0]); 593 usage(argv[0]);
594 if (strcmp(argv[1], "stat") != 0) /* only stat implemented for now */ 594 if (strcmp(argv[1], "stat") != 0) /* only stat implemented for now */
595 usage(argv[0]); 595 usage(argv[0]);
596 596
597 optind = 2; 597 optind = 2;
598 while ((i = getopt(argc, argv, "a:bc:f:gl:p:s:t:v")) != -1) 598 while ((i = getopt(argc, argv, "a:bc:f:gl:p:s:t:v")) != -1)
599 switch (i) { 599 switch (i) {
600 case 'a': 600 case 'a':
601 nattempts = atoi(optarg); 601 nattempts = atoi(optarg);
602 break; 602 break;
603 case 'b': 603 case 'b':
604 bflags++; 604 bflags++;
605 break; 605 break;
606 case 'f': 606 case 'f':
607 snprintf(filename, MAXPATHLEN, "%s", optarg); 607 snprintf(filename, MAXPATHLEN, "%s", optarg);
608 filename[MAXPATHLEN - 1] = '\0'; 608 filename[MAXPATHLEN - 1] = '\0';
609 fflags++; 609 fflags++;
610 break; 610 break;
611 case 'g': 611 case 'g':
612 globalparam = 1; 612 globalparam = 1;
613 break; 613 break;
614 case 'l': 614 case 'l':
615 lvolno = atoi(optarg); 615 lvolno = atoi(optarg);
616 break; 616 break;
617 case 'p': 617 case 'p':
618 physno = atoi(optarg); 618 physno = atoi(optarg);
619 break; 619 break;
620 case 's': 620 case 's':
621 snprintf(sdev, MAXPATHLEN, "%s", optarg); 621 snprintf(sdev, MAXPATHLEN, "%s", optarg);
622 sdev[MAXPATHLEN - 1] = '\0'; 622 sdev[MAXPATHLEN - 1] = '\0';
623 sflags++; 623 sflags++;
624 break; 624 break;
625 case 't': 625 case 't':
626 sleeptime = atoi(optarg); 626 sleeptime = atoi(optarg);
627 break; 627 break;
628 case 'v': 628 case 'v':
629 verbosity++; 629 verbosity++;
630 break; 630 break;
631 case '?': 631 case '?':
632 default: 632 default:
633 usage(argv[0]); 633 usage(argv[0]);
634 } 634 }
635 argc -= optind; 635 argc -= optind;
636 argv += optind; 636 argv += optind;
637 637
638 if (argc != 0) 638 if (argc != 0)
639 usage(argv[0]); 639 usage(argv[0]);
640 640
641 if (!fflags) { 641 if (!fflags) {
642 snprintf(filename, MAXPATHLEN, "/dev/amr0"); 642 snprintf(filename, MAXPATHLEN, "/dev/amr0");
643 } 643 }
644  644
645 fd = open(filename, O_RDONLY); 645 fd = open(filename, O_RDONLY);
646 if (fd == -1) { 646 if (fd == -1) {
647 perror("open"); 647 perror("open");
648 exit(1); 648 exit(1);
649 } 649 }
650 if (ioctl(fd, AMR_IO_VERSION, &i) == -1) { 650 if (ioctl(fd, AMR_IO_VERSION, &i) == -1) {
651 perror("ioctl version"); 651 perror("ioctl version");
652 exit(1); 652 exit(1);
653 } 653 }
654 654
655 if (sflags) { 655 if (sflags) {
656 if(physno > -1) 656 if(physno > -1)
657 usage(argv[0]); 657 usage(argv[0]);
658 else { 658 else {
659 sbusno = atoi(sdev); 659 sbusno = atoi(sdev);
660 if ((pdev = index(sdev, ':'))) 660 if ((pdev = index(sdev, ':')))
661 targetno = atoi(++pdev); 661 targetno = atoi(++pdev);
662 } 662 }
663 } else if (physno > -1) { 663 } else if (physno > -1) {
664 sbusno = physno / AMR_MAX_NSDEVS; 664 sbusno = physno / AMR_MAX_NSDEVS;
665 targetno = physno % AMR_MAX_NSDEVS; 665 targetno = physno % AMR_MAX_NSDEVS;
666 } 666 }
667  667
668 if (globalparam && verbosity >= 1) 668 if (globalparam && verbosity >= 1)
669 printf("Version\t\t\t%d\n", i); 669 printf("Version\t\t\t%d\n", i);
670#if 0 670#if 0
671 if (i != 1) { 671 if (i != 1) {
672 fprintf(stderr, "Driver version (%d) not supported\n", i); 672 fprintf(stderr, "Driver version (%d) not supported\n", i);
673 exit(1); 673 exit(1);
674 } 674 }
675#endif 675#endif
676 676
677 i = describe_card(fd, verbosity, globalparam); 677 i = describe_card(fd, verbosity, globalparam);
678 describe_battery(fd, verbosity, i, bflags, globalparam); 678 describe_battery(fd, verbosity, i, bflags, globalparam);
679 if (!bflags || lvolno > -1 || physno > -1 || sbusno > -1 || targetno > -1) 679 if (!bflags || lvolno > -1 || physno > -1 || sbusno > -1 || targetno > -1)
680 describe_drive(verbosity, i, lvolno, sbusno, targetno); 680 describe_drive(verbosity, i, lvolno, sbusno, targetno);
681 681
682 return 0; 682 return 0;
683} 683}