164987Smsmith/*-
264987Smsmith * Copyright (c) 2000 Michael Smith
364987Smsmith * Copyright (c) 2000 BSDi
464987Smsmith * All rights reserved.
564987Smsmith *
664987Smsmith * Redistribution and use in source and binary forms, with or without
764987Smsmith * modification, are permitted provided that the following conditions
864987Smsmith * are met:
964987Smsmith * 1. Redistributions of source code must retain the above copyright
1064987Smsmith *    notice, this list of conditions and the following disclaimer.
1164987Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1264987Smsmith *    notice, this list of conditions and the following disclaimer in the
1364987Smsmith *    documentation and/or other materials provided with the distribution.
1464987Smsmith *
1564987Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1664987Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1764987Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1864987Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1964987Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2064987Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2164987Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2264987Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2364987Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2464987Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2564987Smsmith * SUCH DAMAGE.
2664987Smsmith *
2764987Smsmith *	$FreeBSD$
2864987Smsmith */
2964987Smsmith
3064987Smsmith/*
3164987Smsmith * Lookup table for code-to-text translations.
3264987Smsmith */
3364987Smsmithstruct mly_code_lookup {
3464987Smsmith    char	*string;
3564987Smsmith    u_int32_t	code;
3664987Smsmith};
3764987Smsmith
3879695Smsmithstatic char	*mly_describe_code(struct mly_code_lookup *table, u_int32_t code);
3964987Smsmith
4064987Smsmith/********************************************************************************
4164987Smsmith * Look up a text description of a numeric code and return a pointer to same.
4264987Smsmith */
4379695Smsmithstatic char *
4464987Smsmithmly_describe_code(struct mly_code_lookup *table, u_int32_t code)
4564987Smsmith{
4664987Smsmith    int		i;
4764987Smsmith
4864987Smsmith    for (i = 0; table[i].string != NULL; i++)
4964987Smsmith	if (table[i].code == code)
5064987Smsmith	    return(table[i].string);
5164987Smsmith    return(table[i+1].string);
5264987Smsmith}
5364987Smsmith
5491448Speter#if 0
5579695Smsmithstatic struct mly_code_lookup mly_table_bustype[] = {
5664987Smsmith    {"SCSI",		0x00},
5764987Smsmith    {"FC-AL",		0x01},
5864987Smsmith    {"PCI",		0x03},
5964987Smsmith    {NULL,		0},
6064987Smsmith    {"unknown bus",	0}
6164987Smsmith};
6291448Speter#endif
6364987Smsmith
6479695Smsmithstatic struct mly_code_lookup mly_table_controllertype[] = {
6564987Smsmith#if 0	/* not supported by this driver */
6664987Smsmith    {"DAC960E",		0x01},	/* EISA */
6764987Smsmith    {"DAC960M",		0x08},	/* MCA */
6864987Smsmith    {"DAC960PD",	0x10},	/* PCI Dual */
6964987Smsmith    {"DAC960PL",	0x11},	/* PCU low-cost */
7064987Smsmith    {"DAC960PDU",	0x12},	/* PD Ultra */
7164987Smsmith    {"DAC960PE",	0x13},	/* Peregrine low-cost */
7264987Smsmith    {"DAC960PG",	0x14},	/* Peregrine high-performance */
7364987Smsmith    {"DAC960PJ",	0x15},	/* Road Runner */
7464987Smsmith    {"DAC960PTL0",	0x16},	/* Jaguar */
7564987Smsmith    {"DAC960PR",	0x17},	/* Road Runner (again?) */
7664987Smsmith    {"DAC960PRL",	0x18},	/* Tomcat */
7764987Smsmith    {"DAC960PT",	0x19},	/* Road Runner (yet again?) */
7864987Smsmith    {"DAC1164P",	0x1a},	/* Little Apple */
7964987Smsmith    {"DAC960PTL1",	0x1b},	/* Jaguar+ */
8064987Smsmith#endif
8164987Smsmith    {"EXR2000P",	0x1c},	/* Big Apple */
8264987Smsmith    {"EXR3000P",	0x1d},	/* Fibre Apple */
8364987Smsmith    {"AcceleRAID 352",	0x1e},	/* Leopard */
8464987Smsmith    {"AcceleRAID 170",	0x1f},	/* Lynx */
8564987Smsmith    {"AcceleRAID 160",	0x20},	/* Bobcat */
8664987Smsmith    {NULL,		0},
8764987Smsmith    {"unknown adapter",	0}
8864987Smsmith};
8964987Smsmith
9079695Smsmithstatic struct mly_code_lookup mly_table_oemname[] = {
9164987Smsmith    {"Mylex",		MLY_OEM_MYLEX},
9264987Smsmith    {"IBM",		MLY_OEM_IBM},
9364987Smsmith    {"Hewlett-Packard",	MLY_OEM_HP},
9464987Smsmith    {"DEC/Compaq",	MLY_OEM_DEC},
9564987Smsmith    {"Siemens",		MLY_OEM_SIEMENS},
9664987Smsmith    {"Intel",		MLY_OEM_INTEL},
9764987Smsmith    {NULL,		0},
9864987Smsmith    {"unknown OEM",	0}
9964987Smsmith};
10064987Smsmith
10179695Smsmithstatic struct mly_code_lookup mly_table_memorytype[] = {
10264987Smsmith    {"DRAM",		0x01},
10364987Smsmith    {"EDRAM",		0x02},
10464987Smsmith    {"EDO RAM",		0x03},
10564987Smsmith    {"SDRAM",		0x04},
10664987Smsmith    {NULL,		0},
10764987Smsmith    {"unknown memory",	0}
10864987Smsmith};
10964987Smsmith
11079695Smsmithstatic struct mly_code_lookup mly_table_cputype[] = {
11164987Smsmith    {"i960CA",		0x01},
11264987Smsmith    {"i960RD",		0x02},
11364987Smsmith    {"i960RN",		0x03},
11464987Smsmith    {"i960RP",		0x04},
11564987Smsmith    {"NorthBay(?)",	0x05},
11664987Smsmith    {"StrongArm",	0x06},
11764987Smsmith    {"i960RM",		0x07},
11864987Smsmith    {NULL,		0},
11964987Smsmith    {"unknown CPU",	0}
12064987Smsmith};
12164987Smsmith
12264987Smsmith/*
12364987Smsmith * This table is directly derived from the corresponding table in the
12464987Smsmith * Linux driver, and uses a derivative encoding for simplicity's sake.
12564987Smsmith *
12664987Smsmith * The first character of the string determines the format of the message.
12764987Smsmith *
12864987Smsmith * p  "physical device <channel>:<target> <text>"	(physical device status)
12964987Smsmith * s  "physical device <channel>:<target> <text>"	(scsi message or error)
13064987Smsmith *    "  sense key <key>  asc <asc>  ascq <ascq>"
13164987Smsmith *    "  info <info>   csi <csi>"
13264987Smsmith * l  "logical drive <unit>: <text>"			(logical device status)
13364987Smsmith * m  "logical drive <unit>: <text>"			(logical device message)
13464987Smsmith *
13564987Smsmith * Messages which are typically suppressed have the first character capitalised.
13664987Smsmith * These messages will only be printed if bootverbose is set.
13764987Smsmith *
13864987Smsmith * The second character in the string indicates an action to be taken as a
13964987Smsmith * result of the event.
14064987Smsmith *
14164987Smsmith * r	rescan the device for possible state change
14264987Smsmith *
14364987Smsmith */
14479695Smsmithstatic struct mly_code_lookup mly_table_event[] = {
14564987Smsmith    /* physical device events (0x0000 - 0x007f) */
14664987Smsmith    {"pr online",							0x0001},
14764987Smsmith    {"pr standby",							0x0002},
14864987Smsmith    {"p  automatic rebuild started",					0x0005},
14964987Smsmith    {"p  manual rebuild started",					0x0006},
15064987Smsmith    {"pr rebuild completed",						0x0007},
15164987Smsmith    {"pr rebuild cancelled",						0x0008},
15264987Smsmith    {"pr rebuild failed for unknown reasons",				0x0009},
15364987Smsmith    {"pr rebuild failed due to new physical device",			0x000a},
15464987Smsmith    {"pr rebuild failed due to logical drive failure",			0x000b},
15564987Smsmith    {"sr offline",							0x000c},
15664987Smsmith    {"pr found",							0x000d},
15764987Smsmith    {"pr gone",								0x000e},
15864987Smsmith    {"p  unconfigured",							0x000f},
15964987Smsmith    {"p  expand capacity started",					0x0010},
16064987Smsmith    {"pr expand capacity completed",					0x0011},
16164987Smsmith    {"pr expand capacity failed",					0x0012},
16264987Smsmith    {"p  parity error",							0x0016},
16364987Smsmith    {"p  soft error",							0x0017},
16464987Smsmith    {"p  miscellaneous error",						0x0018},
16564987Smsmith    {"p  reset",							0x0019},
16664987Smsmith    {"p  active spare found",						0x001a},
16764987Smsmith    {"p  warm spare found",						0x001b},
16864987Smsmith    {"s  sense data received",						0x001c},
16964987Smsmith    {"p  initialization started",					0x001d},
17064987Smsmith    {"pr initialization completed",					0x001e},
17164987Smsmith    {"pr initialization failed",					0x001f},
17264987Smsmith    {"pr initialization cancelled",					0x0020},
17364987Smsmith    {"P  write recovery failed",					0x0021},
17464987Smsmith    {"p  scsi bus reset failed",					0x0022},
17564987Smsmith    {"p  double check condition",					0x0023},
17664987Smsmith    {"p  device cannot be accessed",					0x0024},
17764987Smsmith    {"p  gross error on scsi processor",				0x0025},
17864987Smsmith    {"p  bad tag from device",						0x0026},
17964987Smsmith    {"p  command timeout",						0x0027},
18064987Smsmith    {"pr system reset",							0x0028},
18164987Smsmith    {"p  busy status or parity error",					0x0029},
18264987Smsmith    {"pr host set device to failed state",				0x002a},
18364987Smsmith    {"pr selection timeout",						0x002b},
18464987Smsmith    {"p  scsi bus phase error",						0x002c},
18564987Smsmith    {"pr device returned unknown status",				0x002d},
18664987Smsmith    {"pr device not ready",						0x002e},
18764987Smsmith    {"p  device not found at startup",					0x002f},
18864987Smsmith    {"p  COD write operation failed",					0x0030},
18964987Smsmith    {"p  BDT write operation failed",					0x0031},
19064987Smsmith    {"p  missing at startup",						0x0039},
19164987Smsmith    {"p  start rebuild failed due to physical drive too small",		0x003a},
19264987Smsmith    /* logical device events (0x0080 - 0x00ff) */
19364987Smsmith    {"m  consistency check started",					0x0080},
19464987Smsmith    {"mr consistency check completed",					0x0081},
19564987Smsmith    {"mr consistency check cancelled",					0x0082},
19664987Smsmith    {"mr consistency check completed with errors",			0x0083},
19764987Smsmith    {"mr consistency check failed due to logical drive failure",	0x0084},
19864987Smsmith    {"mr consistency check failed due to physical device failure",	0x0085},
19964987Smsmith    {"lr offline",							0x0086},
20064987Smsmith    {"lr critical",							0x0087},
20164987Smsmith    {"lr online",							0x0088},
20264987Smsmith    {"m  automatic rebuild started",					0x0089},
20364987Smsmith    {"m  manual rebuild started",					0x008a},
20464987Smsmith    {"mr rebuild completed",						0x008b},
20564987Smsmith    {"mr rebuild cancelled",						0x008c},
20664987Smsmith    {"mr rebuild failed for unknown reasons",				0x008d},
20764987Smsmith    {"mr rebuild failed due to new physical device",			0x008e},
20864987Smsmith    {"mr rebuild failed due to logical drive failure",			0x008f},
20964987Smsmith    {"l  initialization started",					0x0090},
21064987Smsmith    {"lr initialization completed",					0x0091},
21164987Smsmith    {"lr initialization cancelled",					0x0092},
21264987Smsmith    {"lr initialization failed",					0x0093},
21364987Smsmith    {"lr found",							0x0094},
21464987Smsmith    {"lr gone",								0x0095},
21564987Smsmith    {"l  expand capacity started",					0x0096},
21664987Smsmith    {"lr expand capacity completed",					0x0097},
21764987Smsmith    {"lr expand capacity failed",					0x0098},
21864987Smsmith    {"l  bad block found",						0x0099},
21964987Smsmith    {"lr size changed",							0x009a},
22064987Smsmith    {"lr type changed",							0x009b},
22164987Smsmith    {"l  bad data block found",						0x009c},
22264987Smsmith    {"l  read of data block in bdt",					0x009e},
22364987Smsmith    {"l  write back data for disk block lost",				0x009f},
22464987Smsmith    /* enclosure management events (0x0100 - 0x017f) */
22564987Smsmith    {"e  enclosure %d fan %d failed",					0x0140},
22664987Smsmith    {"e  enclosure %d fan %d ok",					0x0141},
22764987Smsmith    {"e  enclosure %d fan %d not present",				0x0142},
22864987Smsmith    {"e  enclosure %d power supply %d failed",				0x0143},
22964987Smsmith    {"e  enclosure %d power supply %d ok",				0x0144},
23064987Smsmith    {"e  enclosure %d power supply %d not present",			0x0145},
23164987Smsmith    {"e  enclosure %d temperature sensor %d failed",			0x0146},
23264987Smsmith    {"e  enclosure %d temperature sensor %d critical",			0x0147},
23364987Smsmith    {"e  enclosure %d temperature sensor %d ok",			0x0148},
23464987Smsmith    {"e  enclosure %d temperature sensor %d not present",		0x0149},
23564987Smsmith    {"e  enclosure %d unit %d access critical",				0x014a},
23664987Smsmith    {"e  enclosure %d unit %d access ok",				0x014b},
23764987Smsmith    {"e  enclosure %d unit %d access offline",				0x014c},
23864987Smsmith    /* controller events (0x0180 - 0x01ff) */
23964987Smsmith    {"c  cache write back error",					0x0181},
24064987Smsmith    {"c  battery backup unit found",					0x0188},
24164987Smsmith    {"c  battery backup unit charge level low",				0x0189},
24264987Smsmith    {"c  battery backup unit charge level ok",				0x018a},
24364987Smsmith    {"c  installation aborted",						0x0193},
24464987Smsmith    {"c  mirror race recovery in progress",				0x0195},
24564987Smsmith    {"c  mirror race on critical drive",				0x0196},
24664987Smsmith    {"c  memory soft ecc error",					0x019e},
24764987Smsmith    {"c  memory hard ecc error",					0x019f},
24864987Smsmith    {"c  battery backup unit failed",					0x01a2},
24964987Smsmith    {NULL, 0},
25064987Smsmith    {"?  unknown event code",						0}
25164987Smsmith};
25264987Smsmith
25364987Smsmith/*
25464987Smsmith * Values here must be 16 characters or less, as they are packed into
25564987Smsmith * the 'product' field in the SCSI inquiry data.
25664987Smsmith */
25779695Smsmithstatic struct mly_code_lookup mly_table_device_state[] = {
25864987Smsmith    {"offline",		MLY_DEVICE_STATE_OFFLINE},
25964987Smsmith    {"unconfigured",	MLY_DEVICE_STATE_UNCONFIGURED},
26064987Smsmith    {"online",		MLY_DEVICE_STATE_ONLINE},
26164987Smsmith    {"critical",	MLY_DEVICE_STATE_CRITICAL},
26264987Smsmith    {"writeonly",	MLY_DEVICE_STATE_WRITEONLY},
26364987Smsmith    {"standby",		MLY_DEVICE_STATE_STANDBY},
26464987Smsmith    {"missing",		MLY_DEVICE_STATE_MISSING},
26564987Smsmith    {NULL, 0},
26664987Smsmith    {"unknown state",	0}
26764987Smsmith};
26864987Smsmith
26964987Smsmith/*
27064987Smsmith * Values here must be 8 characters or less, as they are packed into
27164987Smsmith * the 'vendor' field in the SCSI inquiry data.
27264987Smsmith */
27379695Smsmithstatic struct mly_code_lookup mly_table_device_type[] = {
27464987Smsmith    {"RAID 0",		MLY_DEVICE_TYPE_RAID0},
27564987Smsmith    {"RAID 1",		MLY_DEVICE_TYPE_RAID1},
27664987Smsmith    {"RAID 3",		MLY_DEVICE_TYPE_RAID3},		/* right asymmetric parity */
27764987Smsmith    {"RAID 5",		MLY_DEVICE_TYPE_RAID5},		/* right asymmetric parity */
27864987Smsmith    {"RAID 6",		MLY_DEVICE_TYPE_RAID6},		/* Mylex RAID 6 */
27964987Smsmith    {"RAID 7",		MLY_DEVICE_TYPE_RAID7},		/* JBOD */
28064987Smsmith    {"SPAN",		MLY_DEVICE_TYPE_NEWSPAN},	/* New Mylex SPAN */
28164987Smsmith    {"RAID 3",		MLY_DEVICE_TYPE_RAID3F},	/* fixed parity */
28264987Smsmith    {"RAID 3",		MLY_DEVICE_TYPE_RAID3L},	/* left symmetric parity */
28364987Smsmith    {"SPAN",		MLY_DEVICE_TYPE_SPAN},		/* current spanning implementation */
28464987Smsmith    {"RAID 5",		MLY_DEVICE_TYPE_RAID5L},	/* left symmetric parity */
28564987Smsmith    {"RAID E",		MLY_DEVICE_TYPE_RAIDE},		/* concatenation */
28664987Smsmith    {"PHYSICAL",	MLY_DEVICE_TYPE_PHYSICAL},	/* physical device */
28764987Smsmith    {NULL, 0},
28864987Smsmith    {"UNKNOWN",		0}
28964987Smsmith};
29064987Smsmith
29191448Speter#if 0
29279695Smsmithstatic struct mly_code_lookup mly_table_stripe_size[] = {
29364987Smsmith    {"NONE",		MLY_STRIPE_ZERO},
29464987Smsmith    {"512B",		MLY_STRIPE_512b},
29564987Smsmith    {"1k",		MLY_STRIPE_1k},
29664987Smsmith    {"2k",		MLY_STRIPE_2k},
29764987Smsmith    {"4k",		MLY_STRIPE_4k},
29864987Smsmith    {"8k",		MLY_STRIPE_8k},
29964987Smsmith    {"16k",		MLY_STRIPE_16k},
30064987Smsmith    {"32k",		MLY_STRIPE_32k},
30164987Smsmith    {"64k",		MLY_STRIPE_64k},
30264987Smsmith    {"128k",		MLY_STRIPE_128k},
30364987Smsmith    {"256k",		MLY_STRIPE_256k},
30464987Smsmith    {"512k",		MLY_STRIPE_512k},
30564987Smsmith    {"1M",		MLY_STRIPE_1m},
30664987Smsmith    {NULL, 0},
30764987Smsmith    {"unknown",		0}
30864987Smsmith};
30964987Smsmith
31079695Smsmithstatic struct mly_code_lookup mly_table_cacheline_size[] = {
31164987Smsmith    {"NONE",		MLY_CACHELINE_ZERO},
31264987Smsmith    {"512B",		MLY_CACHELINE_512b},
31364987Smsmith    {"1k",		MLY_CACHELINE_1k},
31464987Smsmith    {"2k",		MLY_CACHELINE_2k},
31564987Smsmith    {"4k",		MLY_CACHELINE_4k},
31664987Smsmith    {"8k",		MLY_CACHELINE_8k},
31764987Smsmith    {"16k",		MLY_CACHELINE_16k},
31864987Smsmith    {"32k",		MLY_CACHELINE_32k},
31964987Smsmith    {"64k",		MLY_CACHELINE_64k},
32064987Smsmith    {NULL, 0},
32164987Smsmith    {"unknown",		0}
32264987Smsmith};
32391448Speter#endif
324