summaryrefslogtreecommitdiff
path: root/usr/src/cmd/fm/modules/common/fdd-msg/fdd_msg.c
blob: 73db613f998a77ea430419662448b05967faf13f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 */

/*
 * FMA capability messenger
 *
 * fdd-msg module is called once when fmd starts up. It does the following
 * based on different scenarios
 *
 * 1. If it's on a x86 platform, fdd-msg module sends fdd running on service
 * processor a message (ILOM) which indicates the Solaris host FMA capability.
 * The message is sent via the BMC driver (KCS interface) to the IPMI stack
 * of ILOM using the IPMI Sun OEM core tunnel command. The sub-command is
 * CORE_TUNNEL_SUBCMD_HOSTCAP. The IPMI stack posts an host FMA capability
 * event to the event manager upon receiving this message. fdd subscribes to
 * the event manager for this event. Upon receving this event, fdd will adjust
 * its configuration.
 *
 * 2. If it's on a Sparc platform, fdd-msg module just exit for now.
 */

#include <errno.h>
#include <stdio.h>
#include <strings.h>
#include <sys/systeminfo.h>
#include <libipmi.h>
#include <sys/devfm.h>
#include <fm/fmd_api.h>
#if defined(__x86)
#include <sys/x86_archext.h>
#include <fm/fmd_agent.h>
#include <libnvpair.h>
#endif

#define	CMD_SUNOEM_CORE_TUNNEL 0x44
#define	CORE_TUNNEL_SUBCMD_HOSTFMACAP 2
#define	OEM_DATA_LENGTH 3
#define	VERSION 0x10

#if defined(__x86)
typedef struct cpu_tbl {
	char vendor[X86_VENDOR_STRLEN];
	int32_t family;
	int32_t model;
	char *propname;
} cpu_tbl_t;

static cpu_tbl_t fma_cap_list[] = {
	{"GenuineIntel", 6, 26, "NHMEP_fma_cap"},
	{"GenuineIntel", 6, 46, "NHMEX_fma_cap"},
	{"GenuineIntel", 6, 44, "WSMEP_fma_cap"},
	{"GenuineIntel", 6, 47, "INTLN_fma_cap"},
	{0, 0, 0, 0}
};
#endif

static int
check_sunoem(ipmi_handle_t *ipmi_hdl)
{
	ipmi_deviceid_t *devid;

	if ((devid = ipmi_get_deviceid(ipmi_hdl)) == NULL)
		return (-1);

	if (!ipmi_is_sun_ilom(devid))
		return (-2);

	return (0);
}

#if defined(__x86)
static int32_t
fma_cap_cpu_info(cpu_tbl_t *ci)
{
	nvlist_t **cpus, *nvl;
	uint_t ncpu, i;
	fmd_agent_hdl_t *hdl;
	char *ven;
	int32_t family, model;

	if ((hdl = fmd_agent_open(FMD_AGENT_VERSION)) == NULL)
		return (-1);
	if (fmd_agent_physcpu_info(hdl, &cpus, &ncpu) != 0) {
		fmd_agent_close(hdl);
		return (-1);
	}
	fmd_agent_close(hdl);

	if (cpus == NULL)
		return (-1);

	/*
	 * There is no mixed CPU type on x86 systems, it's ok to
	 * just pick the first one
	 */
	nvl = cpus[0];
	if (nvlist_lookup_string(nvl, FM_PHYSCPU_INFO_VENDOR_ID, &ven) != 0 ||
	    nvlist_lookup_int32(nvl, FM_PHYSCPU_INFO_FAMILY, &family) != 0 ||
	    nvlist_lookup_int32(nvl, FM_PHYSCPU_INFO_MODEL, &model) != 0) {
		for (i = 0; i < ncpu; i++)
			nvlist_free(cpus[i]);
		umem_free(cpus, sizeof (nvlist_t *) * ncpu);
		return (-1);
	}

	(void) snprintf(ci->vendor, X86_VENDOR_STRLEN, "%s", ven);
	ci->family = family;
	ci->model = model;

	for (i = 0; i < ncpu; i++)
		nvlist_free(cpus[i]);
	umem_free(cpus, sizeof (nvlist_t *) * ncpu);
	return (0);
}
#endif

static uint32_t
get_cap_conf(fmd_hdl_t *hdl)
{
	uint32_t fma_cap;
#if defined(__x86)
	int found = 0;
	cpu_tbl_t *cl, ci;

	if (fma_cap_cpu_info(&ci) == 0) {
		fmd_hdl_debug(hdl, "Got CPU info: vendor=%s, family=%d, "
		    "model=%d\n", ci.vendor, ci.family, ci.model);
		for (cl = fma_cap_list; cl->propname != NULL; cl++) {
			if (strncmp(ci.vendor, cl->vendor,
			    X86_VENDOR_STRLEN) == 0 &&
			    ci.family == cl->family &&
			    ci.model == cl->model) {
				found++;
				break;
			}
		}
	} else {
		fmd_hdl_debug(hdl, "Failed to get CPU info");
	}

	if (found) {
		fma_cap = fmd_prop_get_int32(hdl, cl->propname);
		fmd_hdl_debug(hdl, "Found property, FMA capability=0x%x",
		    fma_cap);
	} else {
#endif
		fma_cap = fmd_prop_get_int32(hdl, "default_fma_cap");
		fmd_hdl_debug(hdl, "Didn't find FMA capability property, "
		    "use default=0x%x", fma_cap);
#if defined(__x86)
	}
#endif

	return (fma_cap);
}

static void
send_fma_cap_to_ilom(fmd_hdl_t *hdl, uint32_t fma_cap)
{
	int error;
	char *msg;
	ipmi_handle_t *ipmi_hdl;
	ipmi_cmd_t cmd;
	uint8_t oem_data[OEM_DATA_LENGTH];

	if ((ipmi_hdl = ipmi_open(&error, &msg, IPMI_TRANSPORT_BMC, NULL))
	    == NULL) {
		/*
		 * If /dev/ipmi0 doesn't exist on the system, then return
		 * without doing anything.
		 */
		if (error != EIPMI_BMC_OPEN_FAILED)
			fmd_hdl_abort(hdl, "Failed to initialize IPMI "
			    "connection: %s\n", msg);
		fmd_hdl_debug(hdl, "Failed: no IPMI connection present");
		return;
	}

	/*
	 * Check if it's Sun ILOM
	 */
	if (check_sunoem(ipmi_hdl) != 0) {
		fmd_hdl_debug(hdl, "Service Processor does not run "
		    "Sun ILOM");
		ipmi_close(ipmi_hdl);
		return;
	}

	oem_data[0] = CORE_TUNNEL_SUBCMD_HOSTFMACAP;
	oem_data[1] = VERSION;
	oem_data[2] = fma_cap;

	cmd.ic_netfn = IPMI_NETFN_OEM;
	cmd.ic_lun = 0;
	cmd.ic_cmd = CMD_SUNOEM_CORE_TUNNEL;
	cmd.ic_dlen = OEM_DATA_LENGTH;
	cmd.ic_data = oem_data;

	if (ipmi_send(ipmi_hdl, &cmd) == NULL) {
		fmd_hdl_debug(hdl, "Failed to send Solaris FMA "
		    "capability to ilom: %s", ipmi_errmsg(ipmi_hdl));
	}

	ipmi_close(ipmi_hdl);
}

/*ARGSUSED*/
static void
fma_cap_init(fmd_hdl_t *hdl, id_t id, void *data)
{
	uint32_t	fma_cap;

	fma_cap = get_cap_conf(hdl);
	send_fma_cap_to_ilom(hdl, fma_cap);

	fmd_hdl_unregister(hdl);
}

static const fmd_hdl_ops_t fmd_ops = {
	NULL,		/* fmdo_recv */
	fma_cap_init,	/* fmdo_timeout */
	NULL,		/* fmdo_close */
	NULL,		/* fmdo_stats */
	NULL,		/* fmdo_gc */
	NULL,		/* fmdo_send */
	NULL,		/* fmdo_topo */
};

static const fmd_prop_t fmd_props[] = {
	{ "interval", FMD_TYPE_TIME, "1s" },
	{ "default_fma_cap", FMD_TYPE_UINT32, "0x3" },
	{ "NHMEP_fma_cap", FMD_TYPE_UINT32, "0x3" },
	{ "NHMEX_fma_cap", FMD_TYPE_UINT32, "0x2" },
	{ "WSMEP_fma_cap", FMD_TYPE_UINT32, "0x3" },
	{ "INTLN_fma_cap", FMD_TYPE_UINT32, "0x2" },
	{ NULL, 0, NULL }
};

static const fmd_hdl_info_t fmd_info = {
	"FMA Capability Messenger", "1.1", &fmd_ops, fmd_props
};

void
_fmd_init(fmd_hdl_t *hdl)
{
	char isa[8];

	/*
	 * For now the module only sends message to ILOM on i386 platforms
	 * till CR 6933053 is fixed. Module unregister may cause etm module
	 * core dump due to 6933053.
	 */
	if ((sysinfo(SI_ARCHITECTURE, isa, sizeof (isa)) == -1) ||
	    (strncmp(isa, "i386", 4) != 0))
		return;

	if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0)
		return;

	/*
	 * Setup the timer.
	 */
	(void) fmd_timer_install(hdl, NULL, NULL, 2000000000ULL);
}

/*ARGSUSED*/
void
_fmd_fini(fmd_hdl_t *hdl)
{
}