ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c @ 6423:f4bc62ee03b4

g/c unused code.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 14:16:23 2005 +0000 (2005-08-25)
parents b402e77aac46
children 488bdf86c686
line source
1 /* Xenbus code for netif backend
2 Copyright (C) 2005 Rusty Russell <rusty@rustcorp.com.au>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <stdarg.h>
19 #include <linux/module.h>
20 #include <asm-xen/xenbus.h>
21 #include "common.h"
23 struct backend_info
24 {
25 struct xenbus_device *dev;
27 /* our communications channel */
28 netif_t *netif;
30 long int frontend_id;
31 #if 0
32 long int pdev;
33 long int readonly;
34 #endif
36 /* watch back end for changes */
37 struct xenbus_watch backend_watch;
39 /* watch front end for changes */
40 struct xenbus_watch watch;
41 char *frontpath;
42 };
44 static int netback_remove(struct xenbus_device *dev)
45 {
46 struct backend_info *be = dev->data;
48 if (be->watch.node)
49 unregister_xenbus_watch(&be->watch);
50 unregister_xenbus_watch(&be->backend_watch);
51 #if 0
52 if (be->blkif)
53 blkif_put(be->blkif);
54 #endif
55 if (be->frontpath)
56 kfree(be->frontpath);
57 kfree(be);
58 return 0;
59 }
61 /* Front end tells us frame. */
62 static void frontend_changed(struct xenbus_watch *watch, const char *node)
63 {
64 unsigned long tx_ring_ref, rx_ring_ref;
65 unsigned int evtchn;
66 int err;
67 struct backend_info *be
68 = container_of(watch, struct backend_info, watch);
69 char *mac, *e, *s;
70 int i;
72 /* If other end is gone, delete ourself. */
73 if (node && !xenbus_exists(be->frontpath, "")) {
74 xenbus_rm(be->dev->nodename, "");
75 device_unregister(&be->dev->dev);
76 return;
77 }
78 if (be->netif == NULL || be->netif->status == CONNECTED)
79 return;
81 mac = xenbus_read(be->frontpath, "mac", NULL);
82 if (IS_ERR(mac)) {
83 err = PTR_ERR(mac);
84 xenbus_dev_error(be->dev, err, "reading %s/mac",
85 be->dev->nodename);
86 return;
87 }
88 s = mac;
89 for (i = 0; i < ETH_ALEN; i++) {
90 be->netif->fe_dev_addr[i] = simple_strtoul(s, &e, 16);
91 if (s == e || (e[0] != ':' && e[0] != 0)) {
92 kfree(mac);
93 err = -ENOENT;
94 xenbus_dev_error(be->dev, err, "parsing %s/mac",
95 be->dev->nodename);
96 return;
97 }
98 s = &e[1];
99 }
100 kfree(mac);
102 err = xenbus_gather(be->frontpath, "tx-ring-ref", "%lu", &tx_ring_ref,
103 "rx-ring-ref", "%lu", &rx_ring_ref,
104 "event-channel", "%u", &evtchn, NULL);
105 if (err) {
106 xenbus_dev_error(be->dev, err,
107 "reading %s/ring-ref and event-channel",
108 be->frontpath);
109 return;
110 }
112 #if 0
113 /* Supply the information about the device the frontend needs */
114 err = xenbus_transaction_start(be->dev->nodename);
115 if (err) {
116 xenbus_dev_error(be->dev, err, "starting transaction");
117 return;
118 }
120 err = xenbus_printf(be->dev->nodename, "sectors", "%lu",
121 vbd_size(&be->blkif->vbd));
122 if (err) {
123 xenbus_dev_error(be->dev, err, "writing %s/sectors",
124 be->dev->nodename);
125 goto abort;
126 }
128 /* FIXME: use a typename instead */
129 err = xenbus_printf(be->dev->nodename, "info", "%u",
130 vbd_info(&be->blkif->vbd));
131 if (err) {
132 xenbus_dev_error(be->dev, err, "writing %s/info",
133 be->dev->nodename);
134 goto abort;
135 }
136 err = xenbus_printf(be->dev->nodename, "sector-size", "%lu",
137 vbd_secsize(&be->blkif->vbd));
138 if (err) {
139 xenbus_dev_error(be->dev, err, "writing %s/sector-size",
140 be->dev->nodename);
141 goto abort;
142 }
143 #endif
145 /* Map the shared frame, irq etc. */
146 err = netif_map(be->netif, tx_ring_ref, rx_ring_ref, evtchn);
147 if (err) {
148 xenbus_dev_error(be->dev, err,
149 "mapping shared-frames %lu/%lu port %u",
150 tx_ring_ref, rx_ring_ref, evtchn);
151 goto abort;
152 }
154 #if 0
155 xenbus_transaction_end(0);
156 #endif
157 xenbus_dev_ok(be->dev);
159 return;
161 abort:
162 // xenbus_transaction_end(1);
163 ;
164 }
166 /*
167 Setup supplies physical device.
168 We provide event channel and device details to front end.
169 Frontend supplies shared frame and event channel.
170 */
171 static void backend_changed(struct xenbus_watch *watch, const char *node)
172 {
173 int err;
174 long int handle;
175 struct backend_info *be
176 = container_of(watch, struct backend_info, backend_watch);
177 struct xenbus_device *dev = be->dev;
178 u8 be_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
180 err = xenbus_scanf(dev->nodename, "handle", "%li", &handle);
181 if (XENBUS_EXIST_ERR(err))
182 return;
183 if (err < 0) {
184 xenbus_dev_error(dev, err, "reading handle");
185 return;
186 }
188 if (be->netif == NULL) {
189 be->netif = alloc_netif(be->frontend_id, handle, be_mac);
190 if (IS_ERR(be->netif)) {
191 err = PTR_ERR(be->netif);
192 be->netif = NULL;
193 xenbus_dev_error(dev, err, "creating interface");
194 return;
195 }
197 #if 0
198 err = vbd_create(be->netif, handle, be->pdev, be->readonly);
199 if (err) {
200 xenbus_dev_error(dev, err, "creating vbd structure");
201 return;
202 }
203 #endif
205 /* Pass in NULL node to skip exist test. */
206 frontend_changed(&be->watch, NULL);
207 }
208 }
210 static int netback_probe(struct xenbus_device *dev,
211 const struct xenbus_device_id *id)
212 {
213 struct backend_info *be;
214 char *frontend;
215 int err;
217 be = kmalloc(sizeof(*be), GFP_KERNEL);
218 if (!be) {
219 xenbus_dev_error(dev, -ENOMEM, "allocating backend structure");
220 return -ENOMEM;
221 }
222 memset(be, 0, sizeof(*be));
224 frontend = NULL;
225 err = xenbus_gather(dev->nodename,
226 "frontend-id", "%li", &be->frontend_id,
227 "frontend", NULL, &frontend,
228 NULL);
229 if (XENBUS_EXIST_ERR(err))
230 goto free_be;
231 if (err < 0) {
232 xenbus_dev_error(dev, err,
233 "reading %s/frontend or frontend-id",
234 dev->nodename);
235 goto free_be;
236 }
237 if (strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
238 /* If we can't get a frontend path and a frontend-id,
239 * then our bus-id is no longer valid and we need to
240 * destroy the backend device.
241 */
242 err = -ENOENT;
243 goto free_be;
244 }
246 be->dev = dev;
247 be->backend_watch.node = dev->nodename;
248 be->backend_watch.callback = backend_changed;
249 err = register_xenbus_watch(&be->backend_watch);
250 if (err) {
251 be->backend_watch.node = NULL;
252 xenbus_dev_error(dev, err, "adding backend watch on %s",
253 dev->nodename);
254 goto free_be;
255 }
257 be->frontpath = frontend;
258 be->watch.node = be->frontpath;
259 be->watch.callback = frontend_changed;
260 err = register_xenbus_watch(&be->watch);
261 if (err) {
262 be->watch.node = NULL;
263 xenbus_dev_error(dev, err,
264 "adding frontend watch on %s",
265 be->frontpath);
266 goto free_be;
267 }
269 dev->data = be;
271 backend_changed(&be->backend_watch, dev->nodename);
272 return 0;
274 free_be:
275 if (be->backend_watch.node)
276 unregister_xenbus_watch(&be->backend_watch);
277 if (frontend)
278 kfree(frontend);
279 kfree(be);
280 return err;
281 }
283 static struct xenbus_device_id netback_ids[] = {
284 { "vif" },
285 { "" }
286 };
288 static struct xenbus_driver netback = {
289 .name = "vif",
290 .owner = THIS_MODULE,
291 .ids = netback_ids,
292 .probe = netback_probe,
293 .remove = netback_remove,
294 };
296 void netif_xenbus_init(void)
297 {
298 xenbus_register_backend(&netback);
299 }