xref: /illumos-gate/usr/src/uts/common/io/scsi/impl/scsi_fm.c (revision e4d060fb4c00d44cd578713eb9a921f594b733b8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * SCSI FMA implementation
28  */
29 
30 #include <sys/scsi/scsi_types.h>
31 #include <sys/sunmdi.h>
32 #include <sys/va_list.h>
33 
34 #include <sys/ddi_impldefs.h>
35 
36 /* consolidation private interface to generate dev scheme ereport */
37 extern void fm_dev_ereport_postv(dev_info_t *dip, dev_info_t *eqdip,
38     const char *devpath, const char *minor_name, const char *devid,
39     const char *error_class, uint64_t ena, int sflag, va_list ap);
40 extern char *mdi_pi_pathname_by_instance(int);
41 
42 #define	FM_SCSI_CLASS	"scsi"
43 #define	ERPT_CLASS_SZ   sizeof (FM_SCSI_CLASS) + 1 + DDI_MAX_ERPT_CLASS + 1
44 
45 /*
46  * scsi_fm_init: Initialize fma capabilities and register with IO
47  * fault services.
48  */
49 void
50 scsi_fm_init(struct scsi_device *sd)
51 {
52 	dev_info_t	*dip = sd->sd_dev;
53 
54 	/*
55 	 * fm-capable in driver.conf can be used to set fm_capabilities.
56 	 * If fm-capable is not defined, then the last argument passed to
57 	 * ddi_prop_get_int will be returned as the capabilities.
58 	 *
59 	 * NOTE: by default scsi_fm_capable sets DDI_FM_EREPORT_CAPABLE.
60 	 */
61 	sd->sd_fm_capable = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
62 	    DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "fm-capable",
63 	    scsi_fm_capable);
64 
65 	/*
66 	 * Register capabilities with IO Fault Services. The capabilities
67 	 * set above may not be supported by the parent nexus, in that
68 	 * case some/all capability bits may be cleared.
69 	 *
70 	 * NOTE: iblock cookies are not important because scsi HBAs
71 	 * always interrupt below LOCK_LEVEL.
72 	 */
73 	if (sd->sd_fm_capable != DDI_FM_NOT_CAPABLE)
74 		ddi_fm_init(dip, &sd->sd_fm_capable, NULL);
75 }
76 
77 /*
78  * scsi_fm_fini: un-register with IO fault services.
79  */
80 void
81 scsi_fm_fini(struct scsi_device *sd)
82 {
83 	dev_info_t	*dip = sd->sd_dev;
84 
85 	if (sd->sd_fm_capable != DDI_FM_NOT_CAPABLE)
86 		ddi_fm_fini(dip);
87 }
88 
89 /*
90  *
91  * scsi_fm_erepot_post - Post an ereport.
92  */
93 void
94 scsi_fm_ereport_post(struct scsi_device *sd, int path_instance,
95     const char *error_class, uint64_t ena, char *devid, int sflag, ...)
96 {
97 	char		class[ERPT_CLASS_SZ];
98 	dev_info_t	*dip = sd->sd_dev;
99 	char		*devpath, *minor_name;
100 	va_list		ap;
101 
102 	/* Add "scsi." as a prefix to the class */
103 	(void) snprintf(class, ERPT_CLASS_SZ, "%s.%s",
104 	    FM_SCSI_CLASS, error_class);
105 
106 	/*
107 	 * Get the path: If pkt_path_instance is non-zero then the packet was
108 	 * sent to scsi_vhci. We return the pathinfo path_string associated
109 	 * with the path_instance path - which refers to the actual hardware.
110 	 */
111 	if (path_instance)
112 		devpath = mdi_pi_pathname_by_instance(path_instance);
113 	else
114 		devpath = NULL;
115 
116 	/*
117 	 * Set the minor_name to NULL. The block location of a media error
118 	 * is described by the 'lba' property. We use the 'lba' instead of
119 	 * the partition (minor_name) because the defect stays in the same
120 	 * place even when a repartition operation may result in the defect
121 	 * showing up in a different partition (minor_name). To support
122 	 * retire at the block/partition level, the user level retire agent
123 	 * should map the 'lba' to the current effected partition.
124 	 */
125 	minor_name = NULL;
126 
127 	/*
128 	 * NOTE: If there is a 'linked' ena to be had, it should likely come
129 	 * from the buf structure via the scsi_pkt pkt->pkt_bp.
130 	 */
131 
132 	/* Post the ereport */
133 	va_start(ap, sflag);
134 	fm_dev_ereport_postv(dip, dip, devpath, minor_name, devid,
135 	    class, ena, sflag, ap);
136 	va_end(ap);
137 }
138