xref: /titanic_51/usr/src/uts/common/sys/ddifm_impl.h (revision 33f2fefd46350ca5992567761c46a5b70f864340)
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_IMPL_H
27 #define	_DDIFM_IMPL_H
28 
29 #include <sys/dditypes.h>
30 #include <sys/errorq.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 struct i_ddi_fmkstat {
37 	kstat_named_t	fek_erpt_dropped;	/* total ereports dropped */
38 	kstat_named_t	fek_fmc_miss;		/* total fmc misses */
39 	kstat_named_t	fek_fmc_full;		/* total fmc allocs fail */
40 	kstat_named_t	fek_acc_err;		/* total access errors */
41 	kstat_named_t	fek_dma_err;		/* total dma errors */
42 };
43 
44 /* Fault management error handler support */
45 
46 #define	DDI_MAX_ERPT_CLASS	64
47 #define	DDI_FM_STKDEPTH		20
48 #define	DDI_FM_SYM_SZ		64
49 
50 struct i_ddi_errhdl {
51 	int (*eh_func)();	/* error handler callback */
52 	void *eh_impl;		/* callback arg */
53 };
54 
55 /* Fault management resource cache support */
56 
57 struct i_ddi_fmc_entry {
58 	struct i_ddi_fmc_entry *fce_prev;
59 	struct i_ddi_fmc_entry *fce_next;
60 	void *fce_resource;		/* acc or DMA handle cached */
61 	void *fce_bus_specific;		/* Bus-specific handle data */
62 };
63 
64 struct i_ddi_fmc {
65 	kmutex_t fc_lock;			/* cache active access */
66 	struct i_ddi_fmc_entry *fc_head;	/* active handle list */
67 	struct i_ddi_fmc_entry *fc_tail;	/* tail of active handle list */
68 };
69 
70 /* Error handler targets */
71 struct i_ddi_fmtgt {
72 	struct i_ddi_fmtgt *ft_next;	/* next fm child target */
73 	dev_info_t *ft_dip;		/* fm target error handler dip */
74 	struct i_ddi_errhdl *ft_errhdl;	/* error handler */
75 };
76 
77 struct i_ddi_fmhdl {
78 	kmutex_t fh_lock;		/* error handler lock */
79 	kthread_t *fh_lock_owner;
80 	struct i_ddi_fmc *fh_dma_cache;	/* fm dma handle cache */
81 	struct i_ddi_fmc *fh_acc_cache;	/* fm access handle cache */
82 	dev_info_t *fh_dip;
83 	kstat_t *fh_ksp;		/* pointer to installed kstat */
84 	int fh_cap;			/* fm level for this instance */
85 	struct i_ddi_fmkstat fh_kstat;	/* fm kstats for this inst */
86 	errorq_t *fh_errorq;		/* errorq for this instance */
87 	nvlist_t *fh_fmri;		/* optional fmri */
88 	ddi_iblock_cookie_t fh_ibc;	/* ibc for error handling */
89 	struct i_ddi_fmtgt *fh_tgts;	/* registered fm tgts */
90 	void *fh_bus_specific;		/* Bus specific FM info */
91 };
92 
93 typedef struct pci_fm_err {
94 	char *err_class;
95 	uint32_t reg_bit;
96 	char *terr_class;
97 	int flags;
98 } pci_fm_err_t;
99 
100 extern pci_fm_err_t pci_err_tbl[];
101 
102 #ifdef _KERNEL
103 typedef int (*ddi_fmcompare_t)(dev_info_t *, const void *, const void *,
104     const void *);
105 
106 extern void ndi_fm_init(void);
107 
108 /* driver defect error reporting */
109 extern void i_ddi_drv_ereport_post(dev_info_t *, const char *, nvlist_t *, int);
110 
111 /* target error handler add/remove/dispatch */
112 extern void i_ddi_fm_handler_enter(dev_info_t *);
113 extern void i_ddi_fm_handler_exit(dev_info_t *);
114 extern boolean_t i_ddi_fm_handler_owned(dev_info_t *);
115 
116 /* access and dma handle protection support */
117 extern void i_ddi_fm_acc_err_set(ddi_acc_handle_t, uint64_t, int, int);
118 extern void i_ddi_fm_dma_err_set(ddi_dma_handle_t, uint64_t, int, int);
119 extern ddi_fmcompare_t i_ddi_fm_acc_err_cf_get(ddi_acc_handle_t);
120 extern ddi_fmcompare_t i_ddi_fm_dma_err_cf_get(ddi_dma_handle_t);
121 
122 /* fm busop support */
123 extern void i_ndi_busop_access_enter(dev_info_t *, ddi_acc_handle_t);
124 extern void i_ndi_busop_access_exit(dev_info_t *, ddi_acc_handle_t);
125 extern int i_ndi_busop_fm_init(dev_info_t *, int, ddi_iblock_cookie_t *);
126 extern void i_ndi_busop_fm_fini(dev_info_t *);
127 
128 /* fm cache support */
129 void i_ndi_fmc_create(struct i_ddi_fmc **, int, ddi_iblock_cookie_t);
130 void i_ndi_fmc_destroy(struct i_ddi_fmc *);
131 
132 #endif /* _KERNEL */
133 
134 #ifdef	__cplusplus
135 }
136 #endif
137 
138 #endif	/* _DDIFM_IMPL_H */
139