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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 /*
26 * SCSI FMA implementation
27 */
28
29 #include <sys/scsi/scsi_types.h>
30 #include <sys/sunmdi.h>
31 #include <sys/va_list.h>
32
33 #include <sys/ddi_impldefs.h>
34
35 /* consolidation private interface to generate dev scheme ereport */
36 extern void fm_dev_ereport_postv(dev_info_t *dip, dev_info_t *eqdip,
37 const char *devpath, const char *minor_name, const char *devid,
38 const char *tpl0, const char *error_class, uint64_t ena, int sflag,
39 nvlist_t *, 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
scsi_fm_init(struct scsi_device * sd)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
scsi_fm_fini(struct scsi_device * sd)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_ereport_post - Post an ereport
92 */
93 void
scsi_fm_ereport_post(struct scsi_device * sd,int path_instance,char * devpath,const char * error_class,uint64_t ena,char * devid,char * tpl0,int sflag,nvlist_t * pl,...)94 scsi_fm_ereport_post(struct scsi_device *sd, int path_instance,
95 char *devpath, const char *error_class, uint64_t ena,
96 char *devid, char *tpl0, int sflag, nvlist_t *pl, ...)
97 {
98 char class[ERPT_CLASS_SZ];
99 dev_info_t *dip = sd->sd_dev;
100 dev_info_t *eqdip = dip;
101 char *minor_name;
102 va_list ap;
103
104 /*
105 * If the scsi_device eqdip is not yet ereport capable, send the
106 * report based on parent capabilities. This is needed for
107 * telemetry during enumeration.
108 */
109 if (!DDI_FM_EREPORT_CAP(ddi_fm_capable(eqdip)))
110 eqdip = ddi_get_parent(eqdip);
111
112 /* Add "scsi." as a prefix to the class */
113 (void) snprintf(class, ERPT_CLASS_SZ, "%s.%s",
114 FM_SCSI_CLASS, error_class);
115
116 /*
117 * Get the path:
118 *
119 * If path_instance is non-zero then the packet was
120 * sent to scsi_vhci. We return the pathinfo path_string associated
121 * with the path_instance path - which refers to the actual hardware.
122 *
123 * If path_instance is zero then use the devpath provided by the
124 * caller; if it was NULL then this will cause fm_dev_ereport_post
125 * to use the devinfo path of the first devi we pass to it, ie
126 * sd->sd_dev.
127 */
128 if (path_instance)
129 devpath = mdi_pi_pathname_by_instance(path_instance);
130
131 /*
132 * Set the minor_name to NULL. The block location of a media error
133 * is described by the 'lba' property. We use the 'lba' instead of
134 * the partition (minor_name) because the defect stays in the same
135 * place even when a repartition operation may result in the defect
136 * showing up in a different partition (minor_name). To support
137 * retire at the block/partition level, the user level retire agent
138 * should map the 'lba' to the current effected partition.
139 */
140 minor_name = NULL;
141
142 /*
143 * NOTE: If there is a 'linked' ena to be had, it should likely come
144 * from the buf structure via the scsi_pkt pkt->pkt_bp.
145 */
146
147 /* Post the ereport */
148 va_start(ap, pl);
149 fm_dev_ereport_postv(dip, eqdip, devpath, minor_name, devid, tpl0,
150 class, ena, sflag, pl, ap);
151 va_end(ap);
152 }
153