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