xref: /titanic_41/usr/src/uts/common/io/net_dacf.c (revision e8ed0869d5c65afe0c37c4755bf81f7381d1f43c)
1d62bc4baSyz147064 /*
2d62bc4baSyz147064  * CDDL HEADER START
3d62bc4baSyz147064  *
4d62bc4baSyz147064  * The contents of this file are subject to the terms of the
5d62bc4baSyz147064  * Common Development and Distribution License (the "License").
6d62bc4baSyz147064  * You may not use this file except in compliance with the License.
7d62bc4baSyz147064  *
8d62bc4baSyz147064  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9d62bc4baSyz147064  * or http://www.opensolaris.org/os/licensing.
10d62bc4baSyz147064  * See the License for the specific language governing permissions
11d62bc4baSyz147064  * and limitations under the License.
12d62bc4baSyz147064  *
13d62bc4baSyz147064  * When distributing Covered Code, include this CDDL HEADER in each
14d62bc4baSyz147064  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15d62bc4baSyz147064  * If applicable, add the following below this CDDL HEADER, with the
16d62bc4baSyz147064  * fields enclosed by brackets "[]" replaced with your own identifying
17d62bc4baSyz147064  * information: Portions Copyright [yyyy] [name of copyright owner]
18d62bc4baSyz147064  *
19d62bc4baSyz147064  * CDDL HEADER END
20d62bc4baSyz147064  */
21*e8ed0869SJohn Beck 
22d62bc4baSyz147064 /*
23d62bc4baSyz147064  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24d62bc4baSyz147064  * Use is subject to license terms.
25d62bc4baSyz147064  */
26d62bc4baSyz147064 
27d62bc4baSyz147064 /*
28d62bc4baSyz147064  * This module provides the dacf functions to be called after a device
29d62bc4baSyz147064  * of "ddi_network" node type has attached and before it detaches.
30d62bc4baSyz147064  * Specifically, net_postattach() will be called during the post-attach
31d62bc4baSyz147064  * process of each "ddi_network" device, and net_predetach() will be
32d62bc4baSyz147064  * called during the pre-detach process of each device.
33d62bc4baSyz147064  */
34d62bc4baSyz147064 #include <sys/modctl.h>
35d62bc4baSyz147064 #include <sys/sunddi.h>
36d62bc4baSyz147064 #include <sys/ddi.h>
37d62bc4baSyz147064 #include <sys/dacf.h>
38d62bc4baSyz147064 #include <sys/softmac.h>
39d62bc4baSyz147064 
40d62bc4baSyz147064 /*
41d62bc4baSyz147064  * DACF entry points
42d62bc4baSyz147064  */
43d62bc4baSyz147064 static int	net_postattach(dacf_infohdl_t, dacf_arghdl_t, int);
44d62bc4baSyz147064 static int	net_predetach(dacf_infohdl_t, dacf_arghdl_t, int);
45d62bc4baSyz147064 
46d62bc4baSyz147064 static dacf_op_t net_config_op[] = {
47d62bc4baSyz147064 	{ DACF_OPID_POSTATTACH,	net_postattach	},
48d62bc4baSyz147064 	{ DACF_OPID_PREDETACH,	net_predetach	},
49d62bc4baSyz147064 	{ DACF_OPID_END,	NULL		},
50d62bc4baSyz147064 };
51d62bc4baSyz147064 
52d62bc4baSyz147064 static dacf_opset_t opsets[] = {
53d62bc4baSyz147064 	{ "net_config", net_config_op 		},
54d62bc4baSyz147064 	{ NULL,		NULL 			}
55d62bc4baSyz147064 };
56d62bc4baSyz147064 
57d62bc4baSyz147064 static struct dacfsw dacfsw = {
58d62bc4baSyz147064 	DACF_MODREV_1,
59d62bc4baSyz147064 	opsets
60d62bc4baSyz147064 };
61d62bc4baSyz147064 
62d62bc4baSyz147064 static struct modldacf modldacf = {
63d62bc4baSyz147064 	&mod_dacfops,
64d62bc4baSyz147064 	"net DACF",
65d62bc4baSyz147064 	&dacfsw
66d62bc4baSyz147064 };
67d62bc4baSyz147064 
68*e8ed0869SJohn Beck static struct modlinkage modlinkage = {
69d62bc4baSyz147064 	MODREV_1, &modldacf, NULL
70d62bc4baSyz147064 };
71d62bc4baSyz147064 
72d62bc4baSyz147064 int
_init(void)73d62bc4baSyz147064 _init(void)
74d62bc4baSyz147064 {
75d62bc4baSyz147064 	return (mod_install(&modlinkage));
76d62bc4baSyz147064 }
77d62bc4baSyz147064 
78d62bc4baSyz147064 int
_fini(void)79d62bc4baSyz147064 _fini(void)
80d62bc4baSyz147064 {
81d62bc4baSyz147064 	return (mod_remove(&modlinkage));
82d62bc4baSyz147064 }
83d62bc4baSyz147064 
84d62bc4baSyz147064 int
_info(struct modinfo * modinfop)85d62bc4baSyz147064 _info(struct modinfo *modinfop)
86d62bc4baSyz147064 {
87d62bc4baSyz147064 	return (mod_info(&modlinkage, modinfop));
88d62bc4baSyz147064 }
89d62bc4baSyz147064 
90d62bc4baSyz147064 /*
91d62bc4baSyz147064  * Post-attach routine invoked for DDI_NT_NET drivers by DACF framework
92d62bc4baSyz147064  */
93d62bc4baSyz147064 /* ARGSUSED */
94d62bc4baSyz147064 static int
net_postattach(dacf_infohdl_t info_hdl,dacf_arghdl_t arg_hdl,int flags)95d62bc4baSyz147064 net_postattach(dacf_infohdl_t info_hdl, dacf_arghdl_t arg_hdl, int flags)
96d62bc4baSyz147064 {
97d62bc4baSyz147064 	dev_info_t	*dip;
98d62bc4baSyz147064 	dev_t		dev;
99d62bc4baSyz147064 	int		err;
100d62bc4baSyz147064 
101d62bc4baSyz147064 	dip = dacf_devinfo_node(info_hdl);
102d62bc4baSyz147064 	dev = dacf_get_dev(info_hdl);
103d62bc4baSyz147064 
104d62bc4baSyz147064 	if ((err = softmac_create(dip, dev)) != 0) {
105d62bc4baSyz147064 		const char	*drvname;
106d62bc4baSyz147064 		int		ppa;
107d62bc4baSyz147064 
108d62bc4baSyz147064 		drvname = ddi_driver_name(dip);
109d62bc4baSyz147064 		ppa = i_ddi_devi_get_ppa(dip);
110d62bc4baSyz147064 		cmn_err(CE_WARN, "net_postattach: cannot create softmac "
111d62bc4baSyz147064 		    "for device %s%d (%d)", drvname, ppa, err);
112d62bc4baSyz147064 		return (DACF_FAILURE);
113d62bc4baSyz147064 	}
114d62bc4baSyz147064 
115d62bc4baSyz147064 	return (DACF_SUCCESS);
116d62bc4baSyz147064 }
117d62bc4baSyz147064 
118d62bc4baSyz147064 /*
119d62bc4baSyz147064  * Pre-detach routine invoked for DDI_NT_NET drivers by DACF framework
120d62bc4baSyz147064  */
121d62bc4baSyz147064 /* ARGSUSED */
122d62bc4baSyz147064 static int
net_predetach(dacf_infohdl_t info_hdl,dacf_arghdl_t arg_hdl,int flags)123d62bc4baSyz147064 net_predetach(dacf_infohdl_t info_hdl, dacf_arghdl_t arg_hdl, int flags)
124d62bc4baSyz147064 {
125d62bc4baSyz147064 	dev_info_t	*dip;
126d62bc4baSyz147064 	dev_t		dev;
127d62bc4baSyz147064 
128d62bc4baSyz147064 	dip = dacf_devinfo_node(info_hdl);
129d62bc4baSyz147064 	dev = dacf_get_dev(info_hdl);
130d62bc4baSyz147064 
131d62bc4baSyz147064 	if (softmac_destroy(dip, dev) != 0)
132d62bc4baSyz147064 		return (DACF_FAILURE);
133d62bc4baSyz147064 
134d62bc4baSyz147064 	return (DACF_SUCCESS);
135d62bc4baSyz147064 }
136