blob: 358602f55afa5c5566754e6adc44bddcf6555173 [file] [log] [blame]
Ian Campbellf942dc22011-03-15 00:06:18 +00001/*
2 * Xenbus code for netif backend
3 *
4 * Copyright (C) 2005 Rusty Russell <rusty@rustcorp.com.au>
5 * Copyright (C) 2005 XenSource Ltd
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
Jeff Kirsheradf8d3f2013-12-06 06:28:47 -080018 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Ian Campbellf942dc22011-03-15 00:06:18 +000019*/
20
21#include "common.h"
Wei Liue9ce7cb2014-06-04 10:30:42 +010022#include <linux/vmalloc.h>
23#include <linux/rtnetlink.h>
Ian Campbellf942dc22011-03-15 00:06:18 +000024
25struct backend_info {
26 struct xenbus_device *dev;
27 struct xenvif *vif;
Paul Durrantea732df2013-09-26 12:09:52 +010028
29 /* This is the state that will be reflected in xenstore when any
30 * active hotplug script completes.
31 */
32 enum xenbus_state state;
33
Ian Campbellf942dc22011-03-15 00:06:18 +000034 enum xenbus_state frontend_state;
35 struct xenbus_watch hotplug_status_watch;
Ian Campbell17938a62011-04-03 22:26:24 +000036 u8 have_hotplug_status_watch:1;
Ian Campbellf942dc22011-03-15 00:06:18 +000037};
38
Wei Liue9ce7cb2014-06-04 10:30:42 +010039static int connect_rings(struct backend_info *be, struct xenvif_queue *queue);
40static void connect(struct backend_info *be);
41static int read_xenbus_vif_flags(struct backend_info *be);
Ian Campbellf942dc22011-03-15 00:06:18 +000042static void backend_create_xenvif(struct backend_info *be);
43static void unregister_hotplug_status_watch(struct backend_info *be);
David Vrabeldc62cca2013-10-07 13:55:19 +010044static void set_backend_state(struct backend_info *be,
45 enum xenbus_state state);
Ian Campbellf942dc22011-03-15 00:06:18 +000046
47static int netback_remove(struct xenbus_device *dev)
48{
49 struct backend_info *be = dev_get_drvdata(&dev->dev);
50
David Vrabeldc62cca2013-10-07 13:55:19 +010051 set_backend_state(be, XenbusStateClosed);
52
Ian Campbellf942dc22011-03-15 00:06:18 +000053 unregister_hotplug_status_watch(be);
54 if (be->vif) {
55 kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
56 xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
Paul Durrant279f4382013-09-17 17:46:08 +010057 xenvif_free(be->vif);
Ian Campbellf942dc22011-03-15 00:06:18 +000058 be->vif = NULL;
59 }
60 kfree(be);
61 dev_set_drvdata(&dev->dev, NULL);
62 return 0;
63}
64
65
66/**
67 * Entry point to this code when a new device is created. Allocate the basic
68 * structures and switch to InitWait.
69 */
70static int netback_probe(struct xenbus_device *dev,
71 const struct xenbus_device_id *id)
72{
73 const char *message;
74 struct xenbus_transaction xbt;
75 int err;
76 int sg;
77 struct backend_info *be = kzalloc(sizeof(struct backend_info),
78 GFP_KERNEL);
79 if (!be) {
80 xenbus_dev_fatal(dev, -ENOMEM,
81 "allocating backend structure");
82 return -ENOMEM;
83 }
84
85 be->dev = dev;
86 dev_set_drvdata(&dev->dev, be);
87
88 sg = 1;
89
90 do {
91 err = xenbus_transaction_start(&xbt);
92 if (err) {
93 xenbus_dev_fatal(dev, err, "starting transaction");
94 goto fail;
95 }
96
97 err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", sg);
98 if (err) {
99 message = "writing feature-sg";
100 goto abort_transaction;
101 }
102
103 err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4",
104 "%d", sg);
105 if (err) {
106 message = "writing feature-gso-tcpv4";
107 goto abort_transaction;
108 }
109
Paul Durranta9468582013-10-16 17:50:31 +0100110 err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6",
111 "%d", sg);
112 if (err) {
113 message = "writing feature-gso-tcpv6";
114 goto abort_transaction;
115 }
116
Paul Durrant2eba61d2013-10-16 17:50:29 +0100117 /* We support partial checksum setup for IPv6 packets */
118 err = xenbus_printf(xbt, dev->nodename,
119 "feature-ipv6-csum-offload",
120 "%d", 1);
121 if (err) {
122 message = "writing feature-ipv6-csum-offload";
123 goto abort_transaction;
124 }
125
Ian Campbellf942dc22011-03-15 00:06:18 +0000126 /* We support rx-copy path. */
127 err = xenbus_printf(xbt, dev->nodename,
128 "feature-rx-copy", "%d", 1);
129 if (err) {
130 message = "writing feature-rx-copy";
131 goto abort_transaction;
132 }
133
134 /*
135 * We don't support rx-flip path (except old guests who don't
136 * grok this feature flag).
137 */
138 err = xenbus_printf(xbt, dev->nodename,
139 "feature-rx-flip", "%d", 0);
140 if (err) {
141 message = "writing feature-rx-flip";
142 goto abort_transaction;
143 }
144
145 err = xenbus_transaction_end(xbt, 0);
146 } while (err == -EAGAIN);
147
148 if (err) {
149 xenbus_dev_fatal(dev, err, "completing transaction");
150 goto fail;
151 }
152
Wei Liue1f00a692013-05-22 06:34:45 +0000153 /*
154 * Split event channels support, this is optional so it is not
155 * put inside the above loop.
156 */
157 err = xenbus_printf(XBT_NIL, dev->nodename,
158 "feature-split-event-channels",
159 "%u", separate_tx_rx_irq);
160 if (err)
Wei Liu8ef2c3b2013-07-02 00:08:54 +0100161 pr_debug("Error writing feature-split-event-channels\n");
Wei Liue1f00a692013-05-22 06:34:45 +0000162
Ian Campbellf942dc22011-03-15 00:06:18 +0000163 err = xenbus_switch_state(dev, XenbusStateInitWait);
164 if (err)
165 goto fail;
166
Paul Durrantea732df2013-09-26 12:09:52 +0100167 be->state = XenbusStateInitWait;
168
Ian Campbellf942dc22011-03-15 00:06:18 +0000169 /* This kicks hotplug scripts, so do it immediately. */
170 backend_create_xenvif(be);
171
172 return 0;
173
174abort_transaction:
175 xenbus_transaction_end(xbt, 1);
176 xenbus_dev_fatal(dev, err, "%s", message);
177fail:
Wei Liu8ef2c3b2013-07-02 00:08:54 +0100178 pr_debug("failed\n");
Ian Campbellf942dc22011-03-15 00:06:18 +0000179 netback_remove(dev);
180 return err;
181}
182
183
184/*
185 * Handle the creation of the hotplug script environment. We add the script
186 * and vif variables to the environment, for the benefit of the vif-* hotplug
187 * scripts.
188 */
189static int netback_uevent(struct xenbus_device *xdev,
190 struct kobj_uevent_env *env)
191{
192 struct backend_info *be = dev_get_drvdata(&xdev->dev);
193 char *val;
194
195 val = xenbus_read(XBT_NIL, xdev->nodename, "script", NULL);
196 if (IS_ERR(val)) {
197 int err = PTR_ERR(val);
198 xenbus_dev_fatal(xdev, err, "reading script");
199 return err;
200 } else {
201 if (add_uevent_var(env, "script=%s", val)) {
202 kfree(val);
203 return -ENOMEM;
204 }
205 kfree(val);
206 }
207
208 if (!be || !be->vif)
209 return 0;
210
211 return add_uevent_var(env, "vif=%s", be->vif->dev->name);
212}
213
214
215static void backend_create_xenvif(struct backend_info *be)
216{
217 int err;
218 long handle;
219 struct xenbus_device *dev = be->dev;
220
221 if (be->vif != NULL)
222 return;
223
224 err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%li", &handle);
225 if (err != 1) {
226 xenbus_dev_fatal(dev, err, "reading handle");
227 return;
228 }
229
230 be->vif = xenvif_alloc(&dev->dev, dev->otherend_id, handle);
231 if (IS_ERR(be->vif)) {
232 err = PTR_ERR(be->vif);
233 be->vif = NULL;
234 xenbus_dev_fatal(dev, err, "creating interface");
235 return;
236 }
237
238 kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
239}
240
Paul Durrantea732df2013-09-26 12:09:52 +0100241static void backend_disconnect(struct backend_info *be)
Ian Campbellf942dc22011-03-15 00:06:18 +0000242{
Paul Durrant279f4382013-09-17 17:46:08 +0100243 if (be->vif)
Ian Campbellf942dc22011-03-15 00:06:18 +0000244 xenvif_disconnect(be->vif);
Paul Durrant279f4382013-09-17 17:46:08 +0100245}
246
Paul Durrantea732df2013-09-26 12:09:52 +0100247static void backend_connect(struct backend_info *be)
Paul Durrant279f4382013-09-17 17:46:08 +0100248{
Paul Durrantea732df2013-09-26 12:09:52 +0100249 if (be->vif)
250 connect(be);
251}
Paul Durrant279f4382013-09-17 17:46:08 +0100252
Paul Durrantea732df2013-09-26 12:09:52 +0100253static inline void backend_switch_state(struct backend_info *be,
254 enum xenbus_state state)
255{
256 struct xenbus_device *dev = be->dev;
257
258 pr_debug("%s -> %s\n", dev->nodename, xenbus_strstate(state));
259 be->state = state;
260
261 /* If we are waiting for a hotplug script then defer the
262 * actual xenbus state change.
263 */
264 if (!be->have_hotplug_status_watch)
265 xenbus_switch_state(dev, state);
266}
267
268/* Handle backend state transitions:
269 *
270 * The backend state starts in InitWait and the following transitions are
271 * allowed.
272 *
273 * InitWait -> Connected
274 *
275 * ^ \ |
276 * | \ |
277 * | \ |
278 * | \ |
279 * | \ |
280 * | \ |
281 * | V V
282 *
283 * Closed <-> Closing
284 *
285 * The state argument specifies the eventual state of the backend and the
286 * function transitions to that state via the shortest path.
287 */
288static void set_backend_state(struct backend_info *be,
289 enum xenbus_state state)
290{
291 while (be->state != state) {
292 switch (be->state) {
293 case XenbusStateClosed:
294 switch (state) {
295 case XenbusStateInitWait:
296 case XenbusStateConnected:
297 pr_info("%s: prepare for reconnect\n",
298 be->dev->nodename);
299 backend_switch_state(be, XenbusStateInitWait);
300 break;
301 case XenbusStateClosing:
302 backend_switch_state(be, XenbusStateClosing);
303 break;
304 default:
305 BUG();
306 }
307 break;
308 case XenbusStateInitWait:
309 switch (state) {
310 case XenbusStateConnected:
311 backend_connect(be);
312 backend_switch_state(be, XenbusStateConnected);
313 break;
314 case XenbusStateClosing:
315 case XenbusStateClosed:
316 backend_switch_state(be, XenbusStateClosing);
317 break;
318 default:
319 BUG();
320 }
321 break;
322 case XenbusStateConnected:
323 switch (state) {
324 case XenbusStateInitWait:
325 case XenbusStateClosing:
326 case XenbusStateClosed:
327 backend_disconnect(be);
328 backend_switch_state(be, XenbusStateClosing);
329 break;
330 default:
331 BUG();
332 }
333 break;
334 case XenbusStateClosing:
335 switch (state) {
336 case XenbusStateInitWait:
337 case XenbusStateConnected:
338 case XenbusStateClosed:
339 backend_switch_state(be, XenbusStateClosed);
340 break;
341 default:
342 BUG();
343 }
344 break;
345 default:
346 BUG();
347 }
Ian Campbellf942dc22011-03-15 00:06:18 +0000348 }
349}
350
351/**
352 * Callback received when the frontend's state changes.
353 */
354static void frontend_changed(struct xenbus_device *dev,
355 enum xenbus_state frontend_state)
356{
357 struct backend_info *be = dev_get_drvdata(&dev->dev);
358
Paul Durrantea732df2013-09-26 12:09:52 +0100359 pr_debug("%s -> %s\n", dev->otherend, xenbus_strstate(frontend_state));
Ian Campbellf942dc22011-03-15 00:06:18 +0000360
361 be->frontend_state = frontend_state;
362
363 switch (frontend_state) {
364 case XenbusStateInitialising:
Paul Durrantea732df2013-09-26 12:09:52 +0100365 set_backend_state(be, XenbusStateInitWait);
Ian Campbellf942dc22011-03-15 00:06:18 +0000366 break;
367
368 case XenbusStateInitialised:
369 break;
370
371 case XenbusStateConnected:
Paul Durrantea732df2013-09-26 12:09:52 +0100372 set_backend_state(be, XenbusStateConnected);
Ian Campbellf942dc22011-03-15 00:06:18 +0000373 break;
374
375 case XenbusStateClosing:
Paul Durrantea732df2013-09-26 12:09:52 +0100376 set_backend_state(be, XenbusStateClosing);
Ian Campbellf942dc22011-03-15 00:06:18 +0000377 break;
378
379 case XenbusStateClosed:
Paul Durrantea732df2013-09-26 12:09:52 +0100380 set_backend_state(be, XenbusStateClosed);
Ian Campbellf942dc22011-03-15 00:06:18 +0000381 if (xenbus_dev_is_online(dev))
382 break;
383 /* fall through if not online */
384 case XenbusStateUnknown:
Paul Durrantea732df2013-09-26 12:09:52 +0100385 set_backend_state(be, XenbusStateClosed);
Ian Campbellf942dc22011-03-15 00:06:18 +0000386 device_unregister(&dev->dev);
387 break;
388
389 default:
390 xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
391 frontend_state);
392 break;
393 }
394}
395
396
397static void xen_net_read_rate(struct xenbus_device *dev,
398 unsigned long *bytes, unsigned long *usec)
399{
400 char *s, *e;
401 unsigned long b, u;
402 char *ratestr;
403
404 /* Default to unlimited bandwidth. */
405 *bytes = ~0UL;
406 *usec = 0;
407
408 ratestr = xenbus_read(XBT_NIL, dev->nodename, "rate", NULL);
409 if (IS_ERR(ratestr))
410 return;
411
412 s = ratestr;
413 b = simple_strtoul(s, &e, 10);
414 if ((s == e) || (*e != ','))
415 goto fail;
416
417 s = e + 1;
418 u = simple_strtoul(s, &e, 10);
419 if ((s == e) || (*e != '\0'))
420 goto fail;
421
422 *bytes = b;
423 *usec = u;
424
425 kfree(ratestr);
426 return;
427
428 fail:
429 pr_warn("Failed to parse network rate limit. Traffic unlimited.\n");
430 kfree(ratestr);
431}
432
433static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
434{
435 char *s, *e, *macstr;
436 int i;
437
438 macstr = s = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL);
439 if (IS_ERR(macstr))
440 return PTR_ERR(macstr);
441
442 for (i = 0; i < ETH_ALEN; i++) {
443 mac[i] = simple_strtoul(s, &e, 16);
444 if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) {
445 kfree(macstr);
446 return -ENOENT;
447 }
448 s = e+1;
449 }
450
451 kfree(macstr);
452 return 0;
453}
454
455static void unregister_hotplug_status_watch(struct backend_info *be)
456{
457 if (be->have_hotplug_status_watch) {
458 unregister_xenbus_watch(&be->hotplug_status_watch);
459 kfree(be->hotplug_status_watch.node);
460 }
461 be->have_hotplug_status_watch = 0;
462}
463
464static void hotplug_status_changed(struct xenbus_watch *watch,
465 const char **vec,
466 unsigned int vec_size)
467{
468 struct backend_info *be = container_of(watch,
469 struct backend_info,
470 hotplug_status_watch);
471 char *str;
472 unsigned int len;
473
474 str = xenbus_read(XBT_NIL, be->dev->nodename, "hotplug-status", &len);
475 if (IS_ERR(str))
476 return;
477 if (len == sizeof("connected")-1 && !memcmp(str, "connected", len)) {
Paul Durrantea732df2013-09-26 12:09:52 +0100478 /* Complete any pending state change */
479 xenbus_switch_state(be->dev, be->state);
480
Ian Campbellf942dc22011-03-15 00:06:18 +0000481 /* Not interested in this watch anymore. */
482 unregister_hotplug_status_watch(be);
483 }
484 kfree(str);
485}
486
487static void connect(struct backend_info *be)
488{
489 int err;
490 struct xenbus_device *dev = be->dev;
Wei Liue9ce7cb2014-06-04 10:30:42 +0100491 unsigned long credit_bytes, credit_usec;
492 unsigned int queue_index;
493 unsigned int requested_num_queues = 1;
494 struct xenvif_queue *queue;
Ian Campbellf942dc22011-03-15 00:06:18 +0000495
496 err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
497 if (err) {
498 xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
499 return;
500 }
501
Wei Liue9ce7cb2014-06-04 10:30:42 +0100502 xen_net_read_rate(dev, &credit_bytes, &credit_usec);
503 read_xenbus_vif_flags(be);
504
505 be->vif->queues = vzalloc(requested_num_queues *
506 sizeof(struct xenvif_queue));
507 rtnl_lock();
508 netif_set_real_num_tx_queues(be->vif->dev, requested_num_queues);
509 rtnl_unlock();
510
511 for (queue_index = 0; queue_index < requested_num_queues; ++queue_index) {
512 queue = &be->vif->queues[queue_index];
513 queue->vif = be->vif;
514 queue->id = queue_index;
515 snprintf(queue->name, sizeof(queue->name), "%s-q%u",
516 be->vif->dev->name, queue->id);
517
518 err = xenvif_init_queue(queue);
519 if (err)
520 goto err;
521
522 queue->remaining_credit = credit_bytes;
523
524 err = connect_rings(be, queue);
525 if (err)
526 goto err;
527 }
528
529 xenvif_carrier_on(be->vif);
Ian Campbellf942dc22011-03-15 00:06:18 +0000530
531 unregister_hotplug_status_watch(be);
532 err = xenbus_watch_pathfmt(dev, &be->hotplug_status_watch,
533 hotplug_status_changed,
534 "%s/%s", dev->nodename, "hotplug-status");
Paul Durrantea732df2013-09-26 12:09:52 +0100535 if (!err)
Ian Campbellf942dc22011-03-15 00:06:18 +0000536 be->have_hotplug_status_watch = 1;
Ian Campbellf942dc22011-03-15 00:06:18 +0000537
Wei Liue9ce7cb2014-06-04 10:30:42 +0100538 netif_tx_wake_all_queues(be->vif->dev);
539
540 return;
541
542err:
543 vfree(be->vif->queues);
544 be->vif->queues = NULL;
545 rtnl_lock();
546 netif_set_real_num_tx_queues(be->vif->dev, 0);
547 rtnl_unlock();
548 return;
Ian Campbellf942dc22011-03-15 00:06:18 +0000549}
550
551
Wei Liue9ce7cb2014-06-04 10:30:42 +0100552static int connect_rings(struct backend_info *be, struct xenvif_queue *queue)
Ian Campbellf942dc22011-03-15 00:06:18 +0000553{
Ian Campbellf942dc22011-03-15 00:06:18 +0000554 struct xenbus_device *dev = be->dev;
555 unsigned long tx_ring_ref, rx_ring_ref;
Wei Liue9ce7cb2014-06-04 10:30:42 +0100556 unsigned int tx_evtchn, rx_evtchn;
Ian Campbellf942dc22011-03-15 00:06:18 +0000557 int err;
Ian Campbellf942dc22011-03-15 00:06:18 +0000558
559 err = xenbus_gather(XBT_NIL, dev->otherend,
560 "tx-ring-ref", "%lu", &tx_ring_ref,
Wei Liue1f00a692013-05-22 06:34:45 +0000561 "rx-ring-ref", "%lu", &rx_ring_ref, NULL);
Ian Campbellf942dc22011-03-15 00:06:18 +0000562 if (err) {
563 xenbus_dev_fatal(dev, err,
Wei Liue1f00a692013-05-22 06:34:45 +0000564 "reading %s/ring-ref",
Ian Campbellf942dc22011-03-15 00:06:18 +0000565 dev->otherend);
566 return err;
567 }
568
Wei Liue1f00a692013-05-22 06:34:45 +0000569 /* Try split event channels first, then single event channel. */
570 err = xenbus_gather(XBT_NIL, dev->otherend,
571 "event-channel-tx", "%u", &tx_evtchn,
572 "event-channel-rx", "%u", &rx_evtchn, NULL);
573 if (err < 0) {
574 err = xenbus_scanf(XBT_NIL, dev->otherend,
575 "event-channel", "%u", &tx_evtchn);
576 if (err < 0) {
577 xenbus_dev_fatal(dev, err,
578 "reading %s/event-channel(-tx/rx)",
579 dev->otherend);
580 return err;
581 }
582 rx_evtchn = tx_evtchn;
583 }
584
Wei Liue9ce7cb2014-06-04 10:30:42 +0100585 /* Map the shared frame, irq etc. */
586 err = xenvif_connect(queue, tx_ring_ref, rx_ring_ref,
587 tx_evtchn, rx_evtchn);
588 if (err) {
589 xenbus_dev_fatal(dev, err,
590 "mapping shared-frames %lu/%lu port tx %u rx %u",
591 tx_ring_ref, rx_ring_ref,
592 tx_evtchn, rx_evtchn);
593 return err;
594 }
595
596 return 0;
597}
598
599static int read_xenbus_vif_flags(struct backend_info *be)
600{
601 struct xenvif *vif = be->vif;
602 struct xenbus_device *dev = be->dev;
603 unsigned int rx_copy;
604 int err, val;
605
Ian Campbellf942dc22011-03-15 00:06:18 +0000606 err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u",
607 &rx_copy);
608 if (err == -ENOENT) {
609 err = 0;
610 rx_copy = 0;
611 }
612 if (err < 0) {
613 xenbus_dev_fatal(dev, err, "reading %s/request-rx-copy",
614 dev->otherend);
615 return err;
616 }
617 if (!rx_copy)
618 return -EOPNOTSUPP;
619
620 if (vif->dev->tx_queue_len != 0) {
621 if (xenbus_scanf(XBT_NIL, dev->otherend,
622 "feature-rx-notify", "%d", &val) < 0)
623 val = 0;
624 if (val)
625 vif->can_queue = 1;
626 else
627 /* Must be non-zero for pfifo_fast to work. */
628 vif->dev->tx_queue_len = 1;
629 }
630
631 if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg",
632 "%d", &val) < 0)
633 val = 0;
634 vif->can_sg = !!val;
635
Paul Durrant82cada22013-10-16 17:50:32 +0100636 vif->gso_mask = 0;
637 vif->gso_prefix_mask = 0;
638
Ian Campbellf942dc22011-03-15 00:06:18 +0000639 if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv4",
640 "%d", &val) < 0)
641 val = 0;
Paul Durrant82cada22013-10-16 17:50:32 +0100642 if (val)
643 vif->gso_mask |= GSO_BIT(TCPV4);
Ian Campbellf942dc22011-03-15 00:06:18 +0000644
645 if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv4-prefix",
646 "%d", &val) < 0)
647 val = 0;
Paul Durrant82cada22013-10-16 17:50:32 +0100648 if (val)
649 vif->gso_prefix_mask |= GSO_BIT(TCPV4);
650
651 if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv6",
652 "%d", &val) < 0)
653 val = 0;
654 if (val)
655 vif->gso_mask |= GSO_BIT(TCPV6);
656
657 if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv6-prefix",
658 "%d", &val) < 0)
659 val = 0;
660 if (val)
661 vif->gso_prefix_mask |= GSO_BIT(TCPV6);
662
663 if (vif->gso_mask & vif->gso_prefix_mask) {
664 xenbus_dev_fatal(dev, err,
665 "%s: gso and gso prefix flags are not "
666 "mutually exclusive",
667 dev->otherend);
668 return -EOPNOTSUPP;
669 }
Ian Campbellf942dc22011-03-15 00:06:18 +0000670
671 if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-no-csum-offload",
672 "%d", &val) < 0)
673 val = 0;
Paul Durrant146c8a72013-10-16 17:50:28 +0100674 vif->ip_csum = !val;
675
676 if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-ipv6-csum-offload",
677 "%d", &val) < 0)
678 val = 0;
679 vif->ipv6_csum = !!val;
Ian Campbellf942dc22011-03-15 00:06:18 +0000680
Ian Campbellf942dc22011-03-15 00:06:18 +0000681 return 0;
682}
683
684
685/* ** Driver Registration ** */
686
687
688static const struct xenbus_device_id netback_ids[] = {
689 { "vif" },
690 { "" }
691};
692
693
Jan Beulich73db1442011-12-22 09:08:13 +0000694static DEFINE_XENBUS_DRIVER(netback, ,
Ian Campbellf942dc22011-03-15 00:06:18 +0000695 .probe = netback_probe,
696 .remove = netback_remove,
697 .uevent = netback_uevent,
698 .otherend_changed = frontend_changed,
Jan Beulich73db1442011-12-22 09:08:13 +0000699);
Ian Campbellf942dc22011-03-15 00:06:18 +0000700
701int xenvif_xenbus_init(void)
702{
Jan Beulich73db1442011-12-22 09:08:13 +0000703 return xenbus_register_backend(&netback_driver);
Ian Campbellf942dc22011-03-15 00:06:18 +0000704}
Wei Liub103f352013-05-16 23:26:11 +0000705
706void xenvif_xenbus_fini(void)
707{
708 return xenbus_unregister_driver(&netback_driver);
709}