xref: /illumos-gate/usr/src/uts/common/sys/ddifm.h (revision fafb665d337b69015870e0bcdb516fd2f869693f)
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 #ifndef	_DDIFM_H
27 #define	_DDIFM_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/dditypes.h>
34 #include <sys/va_list.h>
35 
36 extern int ddi_system_fmcap;
37 
38 /* Fault Management error handling */
39 
40 /* Error handling return status */
41 #define	DDI_FM_OK		0
42 #define	DDI_FM_FATAL	-1
43 #define	DDI_FM_NONFATAL	-2
44 #define	DDI_FM_UNKNOWN	-3
45 
46 /* Driver fault management capabilities */
47 #define	DDI_FM_NOT_CAPABLE	0x00000000
48 #define	DDI_FM_EREPORT_CAPABLE	0x00000001
49 #define	DDI_FM_ACCCHK_CAPABLE	0x00000002
50 #define	DDI_FM_DMACHK_CAPABLE	0x00000004
51 #define	DDI_FM_ERRCB_CAPABLE	0x00000008
52 
53 #define	DDI_FM_DEFAULT_CAP(cap)	(cap == DDI_FM_NOT_CAPABLE)
54 #define	DDI_FM_EREPORT_CAP(cap)	(cap & DDI_FM_EREPORT_CAPABLE)
55 #define	DDI_FM_ACC_ERR_CAP(cap)	(cap & DDI_FM_ACCCHK_CAPABLE)
56 #define	DDI_FM_DMA_ERR_CAP(cap)	(cap & DDI_FM_DMACHK_CAPABLE)
57 #define	DDI_FM_ERRCB_CAP(cap)	(cap & DDI_FM_ERRCB_CAPABLE)
58 
59 /* error expectation values */
60 #define	DDI_FM_ERR_UNEXPECTED	0
61 #define	DDI_FM_ERR_EXPECTED	1
62 #define	DDI_FM_ERR_POKE		2
63 #define	DDI_FM_ERR_PEEK		3
64 
65 #ifdef _KERNEL
66 
67 typedef struct ddi_fm_error {
68 	int fme_version;			/* version of this structure */
69 	int fme_status;				/* status for this error */
70 	int fme_flag;				/* error expectation flag */
71 	uint64_t fme_ena;			/* ENA for this error */
72 	ddi_acc_handle_t fme_acc_handle;	/* optional acc handle */
73 	ddi_dma_handle_t fme_dma_handle;	/* optional dma handle */
74 	void *fme_bus_specific;			/* optional bus specific err */
75 	int fme_bus_type;			/* optional bus type */
76 } ddi_fm_error_t;
77 
78 #define	DDI_FME_VER0	0
79 #define	DDI_FME_VER1	1
80 #define	DDI_FME_VERSION	DDI_FME_VER1
81 
82 #define	DDI_FME_BUS_TYPE_DFLT	0		/* bus type = default */
83 #define	DDI_FME_BUS_TYPE_PCI	1		/* bus type = pci/pcix/pcie */
84 
85 typedef int (*ddi_err_func_t)(dev_info_t *, ddi_fm_error_t *, const void *);
86 
87 /*
88  * DDI for error handling and ereport generation
89  */
90 
91 /*
92  * ereport generation: [ddi|ndi]_fm_ereport_post
93  */
94 extern void ddi_fm_ereport_post(dev_info_t *, const char *, uint64_t, int, ...);
95 extern void ndi_fm_ereport_post(dev_info_t *, const char *, uint64_t, int, ...);
96 
97 /*
98  * service changes:
99  *
100  * After a hardened driver raises an ereport (or after pci_ereport_post() has
101  * raised an ereport for an event which implecated one of a driver's access or
102  * dma handles), the driver should always determine the service impact and
103  * report it.
104  */
105 extern void ddi_fm_service_impact(dev_info_t *, int);
106 
107 /* error handling */
108 extern void ddi_fm_handler_register(dev_info_t *, ddi_err_func_t, void *);
109 extern void ddi_fm_handler_unregister(dev_info_t *);
110 
111 /* fault management initialization and clean-up */
112 extern void ddi_fm_init(dev_info_t *, int *, ddi_iblock_cookie_t *);
113 extern void ddi_fm_fini(dev_info_t *);
114 extern int ddi_fm_capable(dev_info_t *dip);
115 
116 /* access and dma handle error protection */
117 extern void ddi_fm_dma_err_get(ddi_dma_handle_t, ddi_fm_error_t *, int);
118 extern void ddi_fm_acc_err_get(ddi_acc_handle_t, ddi_fm_error_t *, int);
119 extern void ddi_fm_dma_err_clear(ddi_dma_handle_t, int);
120 extern void ddi_fm_acc_err_clear(ddi_acc_handle_t, int);
121 
122 #endif /* _KERNEL */
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif	/* _DDIFM_H */
129