xref: /titanic_50/usr/src/uts/common/xen/io/xnbe.c (revision 582271e8d649568c83e9a016cc0d54265389c5d9)
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 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Xen network backend - ioemu version.
31  *
32  * HVM guest domains use an emulated network device (typically the
33  * rtl8139) to access the physical network via IO emulation running in
34  * a backend domain (generally domain 0).
35  *
36  * The IO emulation code sends and receives packets using DLPI, usually
37  * through a virtual NIC (vnic).
38  *
39  * The creation of the relevant vnic to correspond to the network interface
40  * in the guest domain requires the use of 'hotplug' scripts in the backend
41  * domain. This driver ensures that the hotplug scripts are run when
42  * such guest domains are created.
43  *
44  * It is used as a result of the 'compatible' property associated with
45  * IO emulated devices. See /etc/driver_aliases and common/xen/os/xvdi.c.
46  */
47 
48 #ifdef DEBUG
49 #define	XNBE_DEBUG 1
50 #endif /* DEBUG */
51 
52 #include <sys/types.h>
53 #include <sys/conf.h>
54 #include <sys/sunddi.h>
55 #include <sys/modctl.h>
56 #include <xen/sys/xendev.h>
57 #ifdef XNBE_DEBUG
58 #include <sys/cmn_err.h>
59 #endif /* XNBE_DEBUG */
60 
61 #ifdef XNBE_DEBUG
62 int xnbe_debug = 0;
63 #endif /* XNBE_DEBUG */
64 
65 static int
66 xnbe_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
67 {
68 #ifdef XNBE_DEBUG
69 	if (xnbe_debug > 0)
70 		cmn_err(CE_NOTE, "xnbe_attach: dip 0x%p, cmd %d",
71 		    (void *)dip, cmd);
72 #endif /* XNBE_DEBUG */
73 
74 	switch (cmd) {
75 	case DDI_ATTACH:
76 		break;
77 	case DDI_RESUME:
78 		return (DDI_SUCCESS);
79 	default:
80 		return (DDI_FAILURE);
81 	}
82 
83 	(void) xvdi_post_event(dip, XEN_HP_ADD);
84 
85 	return (DDI_SUCCESS);
86 }
87 
88 static int
89 xnbe_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
90 {
91 #ifdef XNBE_DEBUG
92 	if (xnbe_debug > 0)
93 		cmn_err(CE_NOTE, "detach: dip 0x%p, cmd %d",
94 		    (void *)dip, cmd);
95 #endif /* XNBE_DEBUG */
96 
97 	switch (cmd) {
98 	case DDI_DETACH:
99 		return (DDI_SUCCESS);
100 	case DDI_SUSPEND:
101 		return (DDI_SUCCESS);
102 	default:
103 		return (DDI_FAILURE);
104 	}
105 }
106 
107 static struct cb_ops cb_ops = {
108 	nulldev,		/* open */
109 	nulldev,		/* close */
110 	nodev,			/* strategy */
111 	nodev,			/* print */
112 	nodev,			/* dump */
113 	nodev,			/* read */
114 	nodev,			/* write */
115 	nodev,			/* ioctl */
116 	nodev,			/* devmap */
117 	nodev,			/* mmap */
118 	nodev,			/* segmap */
119 	nochpoll,		/* poll */
120 	ddi_prop_op,		/* cb_prop_op */
121 	0,			/* streamtab  */
122 	D_NEW | D_MP | D_64BIT	/* Driver compatibility flag */
123 };
124 
125 static struct dev_ops ops = {
126 	DEVO_REV,		/* devo_rev */
127 	0,			/* devo_refcnt  */
128 	nulldev,		/* devo_getinfo */
129 	nulldev,		/* devo_identify */
130 	nulldev,		/* devo_probe */
131 	xnbe_attach,		/* devo_attach */
132 	xnbe_detach,		/* devo_detach */
133 	nodev,			/* devo_reset */
134 	&cb_ops,		/* devo_cb_ops */
135 	(struct bus_ops *)0,	/* devo_bus_ops */
136 	NULL			/* devo_power */
137 };
138 
139 static struct modldrv modldrv = {
140 	&mod_driverops, "xnbe driver %I%", &ops,
141 };
142 
143 static struct modlinkage modlinkage = {
144 	MODREV_1, &modldrv, NULL
145 };
146 
147 int
148 _init(void)
149 {
150 	return (mod_install(&modlinkage));
151 }
152 
153 int
154 _info(struct modinfo *modinfop)
155 {
156 	return (mod_info(&modlinkage, modinfop));
157 }
158 
159 int
160 _fini(void)
161 {
162 	return (mod_remove(&modlinkage));
163 }
164