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.
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.
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]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
26 * SCSI FMA implementation
29 #include <sys/scsi/scsi_types.h>
30 #include <sys/sunmdi.h>
31 #include <sys/va_list.h>
33 #include <sys/ddi_impldefs.h>
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);
42 #define FM_SCSI_CLASS "scsi"
43 #define ERPT_CLASS_SZ sizeof (FM_SCSI_CLASS) + 1 + DDI_MAX_ERPT_CLASS + 1
46 * scsi_fm_init: Initialize fma capabilities and register with IO
50 scsi_fm_init(struct scsi_device
*sd
)
52 dev_info_t
*dip
= sd
->sd_dev
;
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.
59 * NOTE: by default scsi_fm_capable sets DDI_FM_EREPORT_CAPABLE.
61 sd
->sd_fm_capable
= ddi_prop_get_int(DDI_DEV_T_ANY
, dip
,
62 DDI_PROP_DONTPASS
| DDI_PROP_NOTPROM
, "fm-capable",
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.
70 * NOTE: iblock cookies are not important because scsi HBAs
71 * always interrupt below LOCK_LEVEL.
73 if (sd
->sd_fm_capable
!= DDI_FM_NOT_CAPABLE
)
74 ddi_fm_init(dip
, &sd
->sd_fm_capable
, NULL
);
78 * scsi_fm_fini: un-register with IO fault services.
81 scsi_fm_fini(struct scsi_device
*sd
)
83 dev_info_t
*dip
= sd
->sd_dev
;
85 if (sd
->sd_fm_capable
!= DDI_FM_NOT_CAPABLE
)
91 * scsi_fm_ereport_post - Post an ereport
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
, ...)
98 char class[ERPT_CLASS_SZ
];
99 dev_info_t
*dip
= sd
->sd_dev
;
100 dev_info_t
*eqdip
= dip
;
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.
109 if (!DDI_FM_EREPORT_CAP(ddi_fm_capable(eqdip
)))
110 eqdip
= ddi_get_parent(eqdip
);
112 /* Add "scsi." as a prefix to the class */
113 (void) snprintf(class, ERPT_CLASS_SZ
, "%s.%s",
114 FM_SCSI_CLASS
, error_class
);
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.
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
129 devpath
= mdi_pi_pathname_by_instance(path_instance
);
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.
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.
147 /* Post the ereport */
149 fm_dev_ereport_postv(dip
, eqdip
, devpath
, minor_name
, devid
, tpl0
,
150 class, ena
, sflag
, pl
, ap
);