1*0dc974a9SCathy Zhou /*
2*0dc974a9SCathy Zhou  * CDDL HEADER START
3*0dc974a9SCathy Zhou  *
4*0dc974a9SCathy Zhou  * The contents of this file are subject to the terms of the
5*0dc974a9SCathy Zhou  * Common Development and Distribution License (the "License").
6*0dc974a9SCathy Zhou  * You may not use this file except in compliance with the License.
7*0dc974a9SCathy Zhou  *
8*0dc974a9SCathy Zhou  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*0dc974a9SCathy Zhou  * or http://www.opensolaris.org/os/licensing.
10*0dc974a9SCathy Zhou  * See the License for the specific language governing permissions
11*0dc974a9SCathy Zhou  * and limitations under the License.
12*0dc974a9SCathy Zhou  *
13*0dc974a9SCathy Zhou  * When distributing Covered Code, include this CDDL HEADER in each
14*0dc974a9SCathy Zhou  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*0dc974a9SCathy Zhou  * If applicable, add the following below this CDDL HEADER, with the
16*0dc974a9SCathy Zhou  * fields enclosed by brackets "[]" replaced with your own identifying
17*0dc974a9SCathy Zhou  * information: Portions Copyright [yyyy] [name of copyright owner]
18*0dc974a9SCathy Zhou  *
19*0dc974a9SCathy Zhou  * CDDL HEADER END
20*0dc974a9SCathy Zhou  */
21*0dc974a9SCathy Zhou /*
22*0dc974a9SCathy Zhou  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*0dc974a9SCathy Zhou  * Use is subject to license terms.
24*0dc974a9SCathy Zhou  */
25*0dc974a9SCathy Zhou 
26*0dc974a9SCathy Zhou /*
27*0dc974a9SCathy Zhou  * datalink syseventd module.
28*0dc974a9SCathy Zhou  *
29*0dc974a9SCathy Zhou  * The purpose of this module is to identify all datalink related events,
30*0dc974a9SCathy Zhou  * and react accordingly.
31*0dc974a9SCathy Zhou  */
32*0dc974a9SCathy Zhou 
33*0dc974a9SCathy Zhou #include <errno.h>
34*0dc974a9SCathy Zhou #include <sys/sysevent/eventdefs.h>
35*0dc974a9SCathy Zhou #include <string.h>
36*0dc974a9SCathy Zhou #include <libnvpair.h>
37*0dc974a9SCathy Zhou #include <librcm.h>
38*0dc974a9SCathy Zhou #include <libsysevent.h>
39*0dc974a9SCathy Zhou 
40*0dc974a9SCathy Zhou static rcm_handle_t *rcm_hdl = NULL;
41*0dc974a9SCathy Zhou 
42*0dc974a9SCathy Zhou /*ARGSUSED*/
43*0dc974a9SCathy Zhou static int
44*0dc974a9SCathy Zhou datalink_deliver_event(sysevent_t *ev, int unused)
45*0dc974a9SCathy Zhou {
46*0dc974a9SCathy Zhou 	const char *class = sysevent_get_class_name(ev);
47*0dc974a9SCathy Zhou 	const char *subclass = sysevent_get_subclass_name(ev);
48*0dc974a9SCathy Zhou 	nvlist_t *nvl;
49*0dc974a9SCathy Zhou 	int err = 0;
50*0dc974a9SCathy Zhou 
51*0dc974a9SCathy Zhou 	if (strcmp(class, EC_DATALINK) != 0 ||
52*0dc974a9SCathy Zhou 	    strcmp(subclass, ESC_DATALINK_PHYS_ADD) != 0) {
53*0dc974a9SCathy Zhou 		return (0);
54*0dc974a9SCathy Zhou 	}
55*0dc974a9SCathy Zhou 
56*0dc974a9SCathy Zhou 	if (sysevent_get_attr_list(ev, &nvl) != 0)
57*0dc974a9SCathy Zhou 		return (EINVAL);
58*0dc974a9SCathy Zhou 
59*0dc974a9SCathy Zhou 	if (rcm_notify_event(rcm_hdl, RCM_RESOURCE_LINK_NEW, 0, nvl, NULL) !=
60*0dc974a9SCathy Zhou 	    RCM_SUCCESS) {
61*0dc974a9SCathy Zhou 		err = EINVAL;
62*0dc974a9SCathy Zhou 	}
63*0dc974a9SCathy Zhou 
64*0dc974a9SCathy Zhou 	nvlist_free(nvl);
65*0dc974a9SCathy Zhou 	return (err);
66*0dc974a9SCathy Zhou }
67*0dc974a9SCathy Zhou 
68*0dc974a9SCathy Zhou static struct slm_mod_ops datalink_mod_ops = {
69*0dc974a9SCathy Zhou 	SE_MAJOR_VERSION,
70*0dc974a9SCathy Zhou 	SE_MINOR_VERSION,
71*0dc974a9SCathy Zhou 	SE_MAX_RETRY_LIMIT,
72*0dc974a9SCathy Zhou 	datalink_deliver_event
73*0dc974a9SCathy Zhou };
74*0dc974a9SCathy Zhou 
75*0dc974a9SCathy Zhou struct slm_mod_ops *
76*0dc974a9SCathy Zhou slm_init()
77*0dc974a9SCathy Zhou {
78*0dc974a9SCathy Zhou 	if (rcm_alloc_handle(NULL, 0, NULL, &rcm_hdl) != RCM_SUCCESS)
79*0dc974a9SCathy Zhou 		return (NULL);
80*0dc974a9SCathy Zhou 
81*0dc974a9SCathy Zhou 	return (&datalink_mod_ops);
82*0dc974a9SCathy Zhou }
83*0dc974a9SCathy Zhou 
84*0dc974a9SCathy Zhou void
85*0dc974a9SCathy Zhou slm_fini()
86*0dc974a9SCathy Zhou {
87*0dc974a9SCathy Zhou 	(void) rcm_free_handle(rcm_hdl);
88*0dc974a9SCathy Zhou 	rcm_hdl = NULL;
89*0dc974a9SCathy Zhou }
90