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