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 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef _CMD_STATE_H
27#define	_CMD_STATE_H
28
29/*
30 * Case management and saved state restoration
31 */
32
33#include <cmd_list.h>
34
35#include <fm/fmd_api.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/*
42 * Our maximum persistent buffer name length, used to allocate fixed-size
43 * arrays for name storage.
44 */
45#define	CMD_BUFNMLEN		48
46
47/* cmd_evdisp_t, cmd_evdisp_stat_t, and cmd_evdisp_names must be in sync */
48typedef enum cmd_evdisp {
49	CMD_EVD_OK,
50	CMD_EVD_BAD,
51	CMD_EVD_UNUSED,
52	CMD_EVD_REDUND
53} cmd_evdisp_t;
54
55/*
56 * Each handled ereport type has four statistics, designed to indicate the
57 * eventual disposition of the ereport.
58 */
59typedef struct cmd_evdisp_stat {
60	fmd_stat_t evs_ok;		/* # of erpts processed successfully */
61	fmd_stat_t evs_bad;		/* # of malformed ereports */
62	fmd_stat_t evs_unused;		/* # of erpts unusable or not needed */
63	fmd_stat_t evs_redund;		/* # of erpts already explained */
64} cmd_evdisp_stat_t;
65
66/* Must be in sync with cmd_case_restorers */
67typedef enum cmd_nodetype {
68	CMD_NT_CPU = 1,
69	CMD_NT_DIMM,
70	CMD_NT_BANK,
71	CMD_NT_PAGE,
72#ifdef sun4u
73	CMD_NT_DP,
74	CMD_NT_LxCACHE
75#endif
76#ifdef sun4v
77	CMD_NT_BRANCH
78#endif
79} cmd_nodetype_t;
80
81/*
82 * Must be in sync with cmd_case_closers.  Additional types must be
83 * appended to this enum otherwise interpretation of existing logs
84 * and checkpoints will be confused.
85 */
86typedef enum cmd_ptrsubtype {
87	CMD_PTR_CPU_ICACHE = 1,
88	CMD_PTR_CPU_DCACHE,
89	CMD_PTR_CPU_PCACHE,
90	CMD_PTR_CPU_ITLB,
91	CMD_PTR_CPU_DTLB,
92	CMD_PTR_CPU_L2DATA,
93	CMD_PTR_CPU_L2DATA_UERETRY,	/* no longer used */
94	CMD_PTR_CPU_L2TAG,
95	CMD_PTR_CPU_L3DATA,
96	CMD_PTR_CPU_L3DATA_UERETRY,	/* no longer used */
97	CMD_PTR_CPU_L3TAG,
98	CMD_PTR_DIMM_CASE,
99	CMD_PTR_BANK_CASE,
100	CMD_PTR_PAGE_CASE,
101	CMD_PTR_CPU_FPU,
102	CMD_PTR_CPU_XR_RETRY,
103	CMD_PTR_CPU_IREG,
104	CMD_PTR_CPU_FREG,
105	CMD_PTR_CPU_MAU,
106	CMD_PTR_CPU_L2CTL,
107	CMD_PTR_DP_CASE,
108	CMD_PTR_DP_PAGE_DEFER,
109	CMD_PTR_CPU_INV_SFSR,
110	CMD_PTR_CPU_UE_DET_CPU,
111	CMD_PTR_CPU_UE_DET_IO,
112	CMD_PTR_CPU_MTLB,
113	CMD_PTR_CPU_TLBP,
114	CMD_PTR_CPU_UGESR_INV_URG,
115	CMD_PTR_CPU_UGESR_CRE,
116	CMD_PTR_CPU_UGESR_TSB_CTX,
117	CMD_PTR_CPU_UGESR_TSBP,
118	CMD_PTR_CPU_UGESR_PSTATE,
119	CMD_PTR_CPU_UGESR_TSTATE,
120	CMD_PTR_CPU_UGESR_IUG_F,
121	CMD_PTR_CPU_UGESR_IUG_R,
122	CMD_PTR_CPU_UGESR_SDC,
123	CMD_PTR_CPU_UGESR_WDT,
124	CMD_PTR_CPU_UGESR_DTLB,
125	CMD_PTR_CPU_UGESR_ITLB,
126	CMD_PTR_CPU_UGESR_CORE_ERR,
127	CMD_PTR_CPU_UGESR_DAE,
128	CMD_PTR_CPU_UGESR_IAE,
129	CMD_PTR_CPU_UGESR_UGE,
130	CMD_PTR_CPU_MISC_REGS,
131	CMD_PTR_CPU_LFU,
132	CMD_PTR_BRANCH_CASE,
133	CMD_PTR_LxCACHE_CASE
134} cmd_ptrsubtype_t;
135
136/*
137 * A change was made to the above enum that violated the ordering requirement
138 * described in the comment.  As such, there exist development machines in
139 * the wild that have pre-violation pointer buffers.  Attempts to run the DE
140 * on those machines will cause the state-restoration code to fail, as it
141 * won't know what to do with the old pointer types.  Unfortunately, the old
142 * and new values overlapped for the CPU pointers, so there's not much we
143 * can do there.  The memory pointers, on the other hand, changed from 6-8 to
144 * 12-14, thus allowing us to make the dimm, bank, and page restoration code
145 * check for both values.
146 *
147 * This should go away soon into the next release.
148 */
149typedef enum cmd_BUG_ptrsubtype {
150	BUG_PTR_DIMM_CASE = 6,
151	BUG_PTR_BANK_CASE = 7,
152	BUG_PTR_PAGE_CASE = 8
153} cmd_BUG_ptrsubtype_t;
154
155#define	CMD_TIMERTYPE_CPU_UEC_FLUSH	1
156#define	CMD_TIMERTYPE_CPU_XR_WAITER	2
157#define	CMD_TIMERTYPE_MEM		3
158#define	CMD_TIMERTYPE_DP		4
159#define	CMD_TIMERTYPE_ANONYMOUS_TAG_ERROR 	5
160
161#define	CMD_TIMERTYPE_ISCPU(timer)	((timer) != CMD_TIMERTYPE_MEM && \
162					(timer) != CMD_TIMERTYPE_DP)
163
164/*
165 * There are three types of general-purpose buffers, used to track CPUs, DIMMs,
166 * and pages.  Created on-demand as ereports arrive, one buffer is created for
167 * each thing tracked.  The general-purpose buffers are used to track common
168 * state, and are used to support case-specific buffers.  Each open case has
169 * a case-specific pointer buffer, used to aid in the rediscovery of the
170 * associated general-purpose buffer.  When restoration begins, we iterate
171 * through each of the open cases, restoring the case-specific pointer buffers
172 * for each.  The pointer buffers are then used to restore the general-purpose
173 * buffers.
174 */
175
176typedef	struct cmd_case_ptr {
177	cmd_nodetype_t ptr_type;	/* The type of associated G.P. buffer */
178	cmd_ptrsubtype_t ptr_subtype;	/* The case within the G.P. buffer */
179	char ptr_name[CMD_BUFNMLEN];	/* G.P. buffer name */
180} cmd_case_ptr_t;
181
182/*
183 * All general-purpose buffers begin with a common header.  This header contains
184 * identification information used in the construction of new cases.
185 *
186 * Note that versioned structs (currently cmd_cpu_t) depend upon the size of
187 * this struct remaining fixed.
188 */
189typedef struct cmd_header {
190	cmd_list_t hdr_list;		/* List of G.P. structs of this type */
191	cmd_nodetype_t hdr_nodetype;	/* Type of this G.P. struct */
192	char hdr_bufname[CMD_BUFNMLEN]; /* G.P. buffer name */
193} cmd_header_t;
194
195/*
196 * Per-case-subtype case closing routines.  Stored in per-case state when the
197 * case is generated, and regenerated from saved state upon restore.
198 */
199typedef void cmd_case_closer_f(fmd_hdl_t *, void *);
200typedef void *cmd_case_restorer_f(fmd_hdl_t *, fmd_case_t *, cmd_case_ptr_t *);
201
202typedef struct cmd_case_closer {
203	cmd_case_closer_f *cl_func;
204	void *cl_arg;
205} cmd_case_closer_t;
206
207typedef struct cmd_case {
208	fmd_case_t *cc_cp;
209	char *cc_serdnm;
210} cmd_case_t;
211
212/*
213 * Utility functions which ease the management of cases.
214 */
215extern fmd_case_t *cmd_case_create(fmd_hdl_t *, cmd_header_t *,
216    cmd_ptrsubtype_t, const char **);
217extern void cmd_case_redirect(fmd_hdl_t *, fmd_case_t *, cmd_ptrsubtype_t);
218extern void cmd_case_fini(fmd_hdl_t *, fmd_case_t *, int);
219extern void cmd_case_restore(fmd_hdl_t *, cmd_case_t *, fmd_case_t *, char *);
220
221extern int cmd_state_restore(fmd_hdl_t *);
222
223#ifdef __cplusplus
224}
225#endif
226
227#endif /* _CMD_STATE_H */
228