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 _GMEM_DIMM_H
27 #define	_GMEM_DIMM_H
28 
29 
30 /*
31  * Memory modules are described by the gmem_dimm general-purpose state
32  * structure.
33  *
34  * Data structure	P?  Case? Notes
35  * ----------------	--- ----- ----------------------------------------------
36  * gmem_dimm_t		Yes No    Name is derived from the serial ("dimm_%s")
37  * gmem_case_ptr_t	Yes Yes   Name is case's UUID
38  * dimm_asru		Yes No    Name is derived from the serial
39  *                                ("dimm_asru_%s")
40  * dimm_serial		No  No    Pointer into ASRU - relinked during restore
41  */
42 
43 #include <gmem_mem.h>
44 #include <values.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /*
51  * GMEM_MAX_CKWDS denotes the highest number, across all covered
52  * SPARC architectures, of checkwords per cache line.
53  */
54 
55 #define	GMEM_MAX_CKWDS	8
56 #define	FINDRSC		0
57 #define	FINDFRU		1
58 #define	FINDASRU	2
59 
60 #define	DIMM_MKVERSION(version)	(version)
61 
62 #define	GMEM_DIMM_VERSION_0	DIMM_MKVERSION(0)
63 #define	GMEM_DIMM_VERSION	GMEM_DIMM_VERSION_0
64 
65 #define	GMEM_DIMM_VERSIONED(dimm)	((dimm)->dimm_version)
66 
67 #define	GMEM_DIMM_STAT_PREFIX		"DIMM_"
68 
69 typedef struct gmem_dimm_pers {
70 	gmem_header_t dimmp_header;	/* Nodetype must be GMEM_NT_DIMM */
71 	uint_t dimmp_version;
72 	gmem_fmri_t dimmp_asru;		/* ASRU for this DIMM */
73 	uint_t dimmp_flags;		/* GMEM_MEM_F_* */
74 	uint_t dimmp_nretired;		/* # ret'd pages for CEs in DIMM */
75 } gmem_dimm_pers_t;
76 
77 /*
78  * Index block for MQSC rules 4A and 4B correlation of memory CEs
79  * on a single DIMM. "Unit Position" refers to bit or nibble depending
80  * on the memory ECC.  This structure is not persisted.
81  */
82 
83 typedef struct gmem_mq {
84 	gmem_list_t mq_l;		/* pointers to prev and next */
85 	uint64_t mq_tstamp;		/* timestamp of ereport in secs */
86 	uint16_t mq_ckwd;		/* phys addr mod 64 */
87 	uint64_t mq_phys_addr;		/* from ereport */
88 	uint16_t mq_unit_position;	/* bit for sun4u, nibble for sun4v */
89 	int16_t mq_dram;		/* by table lookup from unit pos */
90 	fmd_event_t *mq_ep;		/* ereport - for potential fault */
91 	char *mq_serdnm;		/* serd eng to retain CE events */
92 } gmem_mq_t;
93 
94 struct gmem_dimm {
95 	gmem_dimm_pers_t dimm_pers;
96 	char *dimm_serial;		/* Dimm serial number */
97 	gmem_case_t dimm_case;		/* Open CE case against this DIMM */
98 	fmd_stat_t dimm_retstat;	/* retirement statistics, this DIMM */
99 	gmem_list_t
100 	    mq_root[GMEM_MAX_CKWDS];	/* per-checkword CEs to correlate */
101 };
102 
103 #define	GMEM_MQ_TIMELIM		(72*60*60)	/* 72 hours */
104 #define	GMEM_MQ_SERDT		MAXINT		/* Never expected to fire */
105 #define	GMEM_MQ_SERDN		2		/* Dup CEs not allowed */
106 
107 #define	GMEM_DIMM_MAXSIZE sizeof (gmem_dimm_pers_t)
108 #define	GMEM_DIMM_MINSIZE sizeof (gmem_dimm_pers_t)
109 
110 #define	dimm_header		dimm_pers.dimmp_header
111 #define	dimm_nodetype		dimm_pers.dimmp_header.hdr_nodetype
112 #define	dimm_bufname		dimm_pers.dimmp_header.hdr_bufname
113 #define	dimm_version		dimm_pers.dimmp_version
114 #define	dimm_asru		dimm_pers.dimmp_asru
115 #define	dimm_asru_nvl		dimm_pers.dimmp_asru.fmri_nvl
116 #define	dimm_flags		dimm_pers.dimmp_flags
117 #define	dimm_nretired		dimm_pers.dimmp_nretired
118 
119 extern gmem_dimm_t *gmem_dimm_lookup(fmd_hdl_t *, nvlist_t *);
120 extern gmem_dimm_t *gmem_dimm_create(fmd_hdl_t *, nvlist_t *);
121 extern nvlist_t *gmem_dimm_fru(gmem_dimm_t *);
122 extern int gmem_dimm_thresh_reached(fmd_hdl_t *, gmem_dimm_t *, uint64_t,
123     uint16_t);
124 extern nvlist_t *gmem_find_dimm_fru(fmd_hdl_t *, char *);
125 extern nvlist_t *gmem_find_dimm_rsc(fmd_hdl_t *, char *);
126 extern nvlist_t *gmem_find_dimm_asru(fmd_hdl_t *, char *);
127 extern int gmem_dimm_present(fmd_hdl_t *, nvlist_t *asru);
128 extern void gmem_dimm_dirty(fmd_hdl_t *, gmem_dimm_t *);
129 extern void *gmem_dimm_restore(fmd_hdl_t *, fmd_case_t *, gmem_case_ptr_t *);
130 extern void gmem_dimm_destroy(fmd_hdl_t *, gmem_dimm_t *);
131 extern void gmem_dimm_validate(fmd_hdl_t *);
132 extern void gmem_dimm_gc(fmd_hdl_t *);
133 extern void gmem_dimm_fini(fmd_hdl_t *);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif /* _GMEM_DIMM_H */
140