1843e1988Sjohnlev /*
2843e1988Sjohnlev * CDDL HEADER START
3843e1988Sjohnlev *
4843e1988Sjohnlev * The contents of this file are subject to the terms of the
5843e1988Sjohnlev * Common Development and Distribution License (the "License").
6843e1988Sjohnlev * You may not use this file except in compliance with the License.
7843e1988Sjohnlev *
8843e1988Sjohnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9843e1988Sjohnlev * or http://www.opensolaris.org/os/licensing.
10843e1988Sjohnlev * See the License for the specific language governing permissions
11843e1988Sjohnlev * and limitations under the License.
12843e1988Sjohnlev *
13843e1988Sjohnlev * When distributing Covered Code, include this CDDL HEADER in each
14843e1988Sjohnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15843e1988Sjohnlev * If applicable, add the following below this CDDL HEADER, with the
16843e1988Sjohnlev * fields enclosed by brackets "[]" replaced with your own identifying
17843e1988Sjohnlev * information: Portions Copyright [yyyy] [name of copyright owner]
18843e1988Sjohnlev *
19843e1988Sjohnlev * CDDL HEADER END
20843e1988Sjohnlev */
21843e1988Sjohnlev
22843e1988Sjohnlev /*
23*19397407SSherry Moore * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24843e1988Sjohnlev * Use is subject to license terms.
25843e1988Sjohnlev */
26843e1988Sjohnlev
27843e1988Sjohnlev
28843e1988Sjohnlev /*
29843e1988Sjohnlev * Xen network backend - ioemu version.
30843e1988Sjohnlev *
31843e1988Sjohnlev * HVM guest domains use an emulated network device (typically the
32843e1988Sjohnlev * rtl8139) to access the physical network via IO emulation running in
33843e1988Sjohnlev * a backend domain (generally domain 0).
34843e1988Sjohnlev *
35843e1988Sjohnlev * The IO emulation code sends and receives packets using DLPI, usually
36843e1988Sjohnlev * through a virtual NIC (vnic).
37843e1988Sjohnlev *
38843e1988Sjohnlev * The creation of the relevant vnic to correspond to the network interface
39843e1988Sjohnlev * in the guest domain requires the use of 'hotplug' scripts in the backend
40843e1988Sjohnlev * domain. This driver ensures that the hotplug scripts are run when
41843e1988Sjohnlev * such guest domains are created.
42843e1988Sjohnlev *
43843e1988Sjohnlev * It is used as a result of the 'compatible' property associated with
44843e1988Sjohnlev * IO emulated devices. See /etc/driver_aliases and common/xen/os/xvdi.c.
45843e1988Sjohnlev */
46843e1988Sjohnlev
47843e1988Sjohnlev #ifdef DEBUG
48843e1988Sjohnlev #define XNBE_DEBUG 1
49843e1988Sjohnlev #endif /* DEBUG */
50843e1988Sjohnlev
51843e1988Sjohnlev #include <sys/types.h>
52843e1988Sjohnlev #include <sys/conf.h>
53843e1988Sjohnlev #include <sys/sunddi.h>
54843e1988Sjohnlev #include <sys/modctl.h>
55843e1988Sjohnlev #include <xen/sys/xendev.h>
56843e1988Sjohnlev #ifdef XNBE_DEBUG
57843e1988Sjohnlev #include <sys/cmn_err.h>
58843e1988Sjohnlev #endif /* XNBE_DEBUG */
59843e1988Sjohnlev
60843e1988Sjohnlev #ifdef XNBE_DEBUG
61843e1988Sjohnlev int xnbe_debug = 0;
62843e1988Sjohnlev #endif /* XNBE_DEBUG */
63843e1988Sjohnlev
64843e1988Sjohnlev static int
xnbe_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)65843e1988Sjohnlev xnbe_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
66843e1988Sjohnlev {
67843e1988Sjohnlev #ifdef XNBE_DEBUG
68843e1988Sjohnlev if (xnbe_debug > 0)
69843e1988Sjohnlev cmn_err(CE_NOTE, "xnbe_attach: dip 0x%p, cmd %d",
70843e1988Sjohnlev (void *)dip, cmd);
71843e1988Sjohnlev #endif /* XNBE_DEBUG */
72843e1988Sjohnlev
73843e1988Sjohnlev switch (cmd) {
74843e1988Sjohnlev case DDI_ATTACH:
75843e1988Sjohnlev break;
76843e1988Sjohnlev case DDI_RESUME:
77843e1988Sjohnlev return (DDI_SUCCESS);
78843e1988Sjohnlev default:
79843e1988Sjohnlev return (DDI_FAILURE);
80843e1988Sjohnlev }
81843e1988Sjohnlev
82843e1988Sjohnlev (void) xvdi_post_event(dip, XEN_HP_ADD);
83843e1988Sjohnlev
84843e1988Sjohnlev return (DDI_SUCCESS);
85843e1988Sjohnlev }
86843e1988Sjohnlev
87843e1988Sjohnlev static int
xnbe_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)88843e1988Sjohnlev xnbe_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
89843e1988Sjohnlev {
90843e1988Sjohnlev #ifdef XNBE_DEBUG
91843e1988Sjohnlev if (xnbe_debug > 0)
92843e1988Sjohnlev cmn_err(CE_NOTE, "detach: dip 0x%p, cmd %d",
93843e1988Sjohnlev (void *)dip, cmd);
94843e1988Sjohnlev #endif /* XNBE_DEBUG */
95843e1988Sjohnlev
96843e1988Sjohnlev switch (cmd) {
97843e1988Sjohnlev case DDI_DETACH:
98843e1988Sjohnlev return (DDI_SUCCESS);
99843e1988Sjohnlev case DDI_SUSPEND:
100843e1988Sjohnlev return (DDI_SUCCESS);
101843e1988Sjohnlev default:
102843e1988Sjohnlev return (DDI_FAILURE);
103843e1988Sjohnlev }
104843e1988Sjohnlev }
105843e1988Sjohnlev
106843e1988Sjohnlev static struct cb_ops cb_ops = {
107843e1988Sjohnlev nulldev, /* open */
108843e1988Sjohnlev nulldev, /* close */
109843e1988Sjohnlev nodev, /* strategy */
110843e1988Sjohnlev nodev, /* print */
111843e1988Sjohnlev nodev, /* dump */
112843e1988Sjohnlev nodev, /* read */
113843e1988Sjohnlev nodev, /* write */
114843e1988Sjohnlev nodev, /* ioctl */
115843e1988Sjohnlev nodev, /* devmap */
116843e1988Sjohnlev nodev, /* mmap */
117843e1988Sjohnlev nodev, /* segmap */
118843e1988Sjohnlev nochpoll, /* poll */
119843e1988Sjohnlev ddi_prop_op, /* cb_prop_op */
120843e1988Sjohnlev 0, /* streamtab */
121843e1988Sjohnlev D_NEW | D_MP | D_64BIT /* Driver compatibility flag */
122843e1988Sjohnlev };
123843e1988Sjohnlev
124843e1988Sjohnlev static struct dev_ops ops = {
125843e1988Sjohnlev DEVO_REV, /* devo_rev */
126843e1988Sjohnlev 0, /* devo_refcnt */
127843e1988Sjohnlev nulldev, /* devo_getinfo */
128843e1988Sjohnlev nulldev, /* devo_identify */
129843e1988Sjohnlev nulldev, /* devo_probe */
130843e1988Sjohnlev xnbe_attach, /* devo_attach */
131843e1988Sjohnlev xnbe_detach, /* devo_detach */
132843e1988Sjohnlev nodev, /* devo_reset */
133843e1988Sjohnlev &cb_ops, /* devo_cb_ops */
134843e1988Sjohnlev (struct bus_ops *)0, /* devo_bus_ops */
135*19397407SSherry Moore NULL, /* devo_power */
136*19397407SSherry Moore ddi_quiesce_not_needed, /* devo_quiesce */
137843e1988Sjohnlev };
138843e1988Sjohnlev
139843e1988Sjohnlev static struct modldrv modldrv = {
140*19397407SSherry Moore &mod_driverops, "xnbe driver", &ops,
141843e1988Sjohnlev };
142843e1988Sjohnlev
143843e1988Sjohnlev static struct modlinkage modlinkage = {
144843e1988Sjohnlev MODREV_1, &modldrv, NULL
145843e1988Sjohnlev };
146843e1988Sjohnlev
147843e1988Sjohnlev int
_init(void)148843e1988Sjohnlev _init(void)
149843e1988Sjohnlev {
150843e1988Sjohnlev return (mod_install(&modlinkage));
151843e1988Sjohnlev }
152843e1988Sjohnlev
153843e1988Sjohnlev int
_info(struct modinfo * modinfop)154843e1988Sjohnlev _info(struct modinfo *modinfop)
155843e1988Sjohnlev {
156843e1988Sjohnlev return (mod_info(&modlinkage, modinfop));
157843e1988Sjohnlev }
158843e1988Sjohnlev
159843e1988Sjohnlev int
_fini(void)160843e1988Sjohnlev _fini(void)
161843e1988Sjohnlev {
162843e1988Sjohnlev return (mod_remove(&modlinkage));
163843e1988Sjohnlev }
164