xref: /titanic_51/usr/src/uts/common/io/net_dacf.c (revision ff3124eff995e6cd8ebd8c6543648e0670920034)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * This module provides the dacf functions to be called after a device
30  * of "ddi_network" node type has attached and before it detaches.
31  * Specifically, net_postattach() will be called during the post-attach
32  * process of each "ddi_network" device, and net_predetach() will be
33  * called during the pre-detach process of each device.
34  */
35 #include <sys/modctl.h>
36 #include <sys/sunddi.h>
37 #include <sys/ddi.h>
38 #include <sys/dacf.h>
39 #include <sys/softmac.h>
40 
41 /*
42  * DACF entry points
43  */
44 static int	net_postattach(dacf_infohdl_t, dacf_arghdl_t, int);
45 static int	net_predetach(dacf_infohdl_t, dacf_arghdl_t, int);
46 
47 static dacf_op_t net_config_op[] = {
48 	{ DACF_OPID_POSTATTACH,	net_postattach	},
49 	{ DACF_OPID_PREDETACH,	net_predetach	},
50 	{ DACF_OPID_END,	NULL		},
51 };
52 
53 static dacf_opset_t opsets[] = {
54 	{ "net_config", net_config_op 		},
55 	{ NULL,		NULL 			}
56 };
57 
58 static struct dacfsw dacfsw = {
59 	DACF_MODREV_1,
60 	opsets
61 };
62 
63 static struct modldacf modldacf = {
64 	&mod_dacfops,
65 	"net DACF",
66 	&dacfsw
67 };
68 
69 struct modlinkage modlinkage = {
70 	MODREV_1, &modldacf, NULL
71 };
72 
73 int
74 _init(void)
75 {
76 	return (mod_install(&modlinkage));
77 }
78 
79 int
80 _fini(void)
81 {
82 	return (mod_remove(&modlinkage));
83 }
84 
85 int
86 _info(struct modinfo *modinfop)
87 {
88 	return (mod_info(&modlinkage, modinfop));
89 }
90 
91 /*
92  * Post-attach routine invoked for DDI_NT_NET drivers by DACF framework
93  */
94 /* ARGSUSED */
95 static int
96 net_postattach(dacf_infohdl_t info_hdl, dacf_arghdl_t arg_hdl, int flags)
97 {
98 	dev_info_t	*dip;
99 	dev_t		dev;
100 	int		err;
101 
102 	dip = dacf_devinfo_node(info_hdl);
103 	dev = dacf_get_dev(info_hdl);
104 
105 	if ((err = softmac_create(dip, dev)) != 0) {
106 		const char	*drvname;
107 		int		ppa;
108 
109 		drvname = ddi_driver_name(dip);
110 		ppa = i_ddi_devi_get_ppa(dip);
111 		cmn_err(CE_WARN, "net_postattach: cannot create softmac "
112 		    "for device %s%d (%d)", drvname, ppa, err);
113 		return (DACF_FAILURE);
114 	}
115 
116 	return (DACF_SUCCESS);
117 }
118 
119 /*
120  * Pre-detach routine invoked for DDI_NT_NET drivers by DACF framework
121  */
122 /* ARGSUSED */
123 static int
124 net_predetach(dacf_infohdl_t info_hdl, dacf_arghdl_t arg_hdl, int flags)
125 {
126 	dev_info_t	*dip;
127 	dev_t		dev;
128 
129 	dip = dacf_devinfo_node(info_hdl);
130 	dev = dacf_get_dev(info_hdl);
131 
132 	if (softmac_destroy(dip, dev) != 0)
133 		return (DACF_FAILURE);
134 
135 	return (DACF_SUCCESS);
136 }
137