ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c @ 13799:8132bf3ddbef

[LINUX] netfront: Don't call netif_carrier_off until the device is
fuly allocated.

netif_carrier_off() causes events to be queued on the device so if we
subsequently abort the allocation (e.g. due to lack of grant entries)
then we crash trying to access the now invalid device.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian Campbell <ian.campbell@xensource.com>
date Thu Feb 01 10:20:34 2007 +0000 (2007-02-01)
parents e19f9d6a2ff5
children 3f63c1825b0d
line source
1 /******************************************************************************
2 * Virtual network driver for conversing with remote driver backends.
3 *
4 * Copyright (c) 2002-2005, K A Fraser
5 * Copyright (c) 2005, XenSource Ltd
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation; or, when distributed
10 * separately from the Linux kernel or incorporated into other
11 * software packages, subject to the following license:
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a copy
14 * of this source file (the "Software"), to deal in the Software without
15 * restriction, including without limitation the rights to use, copy, modify,
16 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
17 * and to permit persons to whom the Software is furnished to do so, subject to
18 * the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 * IN THE SOFTWARE.
30 */
32 #include <linux/config.h>
33 #include <linux/module.h>
34 #include <linux/version.h>
35 #include <linux/kernel.h>
36 #include <linux/sched.h>
37 #include <linux/slab.h>
38 #include <linux/string.h>
39 #include <linux/errno.h>
40 #include <linux/netdevice.h>
41 #include <linux/inetdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/skbuff.h>
44 #include <linux/init.h>
45 #include <linux/bitops.h>
46 #include <linux/ethtool.h>
47 #include <linux/in.h>
48 #include <linux/if_ether.h>
49 #include <linux/io.h>
50 #include <linux/moduleparam.h>
51 #include <net/sock.h>
52 #include <net/pkt_sched.h>
53 #include <net/arp.h>
54 #include <net/route.h>
55 #include <asm/uaccess.h>
56 #include <xen/evtchn.h>
57 #include <xen/xenbus.h>
58 #include <xen/interface/io/netif.h>
59 #include <xen/interface/memory.h>
60 #include <xen/balloon.h>
61 #include <asm/page.h>
62 #include <asm/maddr.h>
63 #include <asm/uaccess.h>
64 #include <xen/interface/grant_table.h>
65 #include <xen/gnttab.h>
67 #ifdef HAVE_XEN_PLATFORM_COMPAT_H
68 #include <xen/platform-compat.h>
69 #endif
71 /*
72 * Mutually-exclusive module options to select receive data path:
73 * rx_copy : Packets are copied by network backend into local memory
74 * rx_flip : Page containing packet data is transferred to our ownership
75 * For fully-virtualised guests there is no option - copying must be used.
76 * For paravirtualised guests, flipping is the default.
77 */
78 #ifdef CONFIG_XEN
79 static int MODPARM_rx_copy = 0;
80 module_param_named(rx_copy, MODPARM_rx_copy, bool, 0);
81 MODULE_PARM_DESC(rx_copy, "Copy packets from network card (rather than flip)");
82 static int MODPARM_rx_flip = 0;
83 module_param_named(rx_flip, MODPARM_rx_flip, bool, 0);
84 MODULE_PARM_DESC(rx_flip, "Flip packets from network card (rather than copy)");
85 #else
86 static const int MODPARM_rx_copy = 1;
87 static const int MODPARM_rx_flip = 0;
88 #endif
90 #define RX_COPY_THRESHOLD 256
92 /* If we don't have GSO, fake things up so that we never try to use it. */
93 #if defined(NETIF_F_GSO)
94 #define HAVE_GSO 1
95 #define HAVE_TSO 1 /* TSO is a subset of GSO */
96 static inline void dev_disable_gso_features(struct net_device *dev)
97 {
98 /* Turn off all GSO bits except ROBUST. */
99 dev->features &= (1 << NETIF_F_GSO_SHIFT) - 1;
100 dev->features |= NETIF_F_GSO_ROBUST;
101 }
102 #elif defined(NETIF_F_TSO)
103 #define HAVE_TSO 1
105 /* Some older kernels cannot cope with incorrect checksums,
106 * particularly in netfilter. I'm not sure there is 100% correlation
107 * with the presence of NETIF_F_TSO but it appears to be a good first
108 * approximiation.
109 */
110 #define HAVE_NO_CSUM_OFFLOAD 1
112 #define gso_size tso_size
113 #define gso_segs tso_segs
114 static inline void dev_disable_gso_features(struct net_device *dev)
115 {
116 /* Turn off all TSO bits. */
117 dev->features &= ~NETIF_F_TSO;
118 }
119 static inline int skb_is_gso(const struct sk_buff *skb)
120 {
121 return skb_shinfo(skb)->tso_size;
122 }
123 static inline int skb_gso_ok(struct sk_buff *skb, int features)
124 {
125 return (features & NETIF_F_TSO);
126 }
128 static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb)
129 {
130 return skb_is_gso(skb) &&
131 (!skb_gso_ok(skb, dev->features) ||
132 unlikely(skb->ip_summed != CHECKSUM_HW));
133 }
134 #else
135 #define netif_needs_gso(dev, skb) 0
136 #define dev_disable_gso_features(dev) ((void)0)
137 #endif
139 #define GRANT_INVALID_REF 0
141 #define NET_TX_RING_SIZE __RING_SIZE((struct netif_tx_sring *)0, PAGE_SIZE)
142 #define NET_RX_RING_SIZE __RING_SIZE((struct netif_rx_sring *)0, PAGE_SIZE)
144 struct netfront_info {
145 struct list_head list;
146 struct net_device *netdev;
148 struct net_device_stats stats;
150 struct netif_tx_front_ring tx;
151 struct netif_rx_front_ring rx;
153 spinlock_t tx_lock;
154 spinlock_t rx_lock;
156 unsigned int irq;
157 unsigned int copying_receiver;
159 /* Receive-ring batched refills. */
160 #define RX_MIN_TARGET 8
161 #define RX_DFL_MIN_TARGET 64
162 #define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
163 unsigned rx_min_target, rx_max_target, rx_target;
164 struct sk_buff_head rx_batch;
166 struct timer_list rx_refill_timer;
168 /*
169 * {tx,rx}_skbs store outstanding skbuffs. The first entry in tx_skbs
170 * is an index into a chain of free entries.
171 */
172 struct sk_buff *tx_skbs[NET_TX_RING_SIZE+1];
173 struct sk_buff *rx_skbs[NET_RX_RING_SIZE];
175 #define TX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
176 grant_ref_t gref_tx_head;
177 grant_ref_t grant_tx_ref[NET_TX_RING_SIZE + 1];
178 grant_ref_t gref_rx_head;
179 grant_ref_t grant_rx_ref[NET_RX_RING_SIZE];
181 struct xenbus_device *xbdev;
182 int tx_ring_ref;
183 int rx_ring_ref;
184 u8 mac[ETH_ALEN];
186 unsigned long rx_pfn_array[NET_RX_RING_SIZE];
187 struct multicall_entry rx_mcl[NET_RX_RING_SIZE+1];
188 struct mmu_update rx_mmu[NET_RX_RING_SIZE];
189 };
191 struct netfront_rx_info {
192 struct netif_rx_response rx;
193 struct netif_extra_info extras[XEN_NETIF_EXTRA_TYPE_MAX - 1];
194 };
196 /*
197 * Access macros for acquiring freeing slots in tx_skbs[].
198 */
200 static inline void add_id_to_freelist(struct sk_buff **list, unsigned short id)
201 {
202 list[id] = list[0];
203 list[0] = (void *)(unsigned long)id;
204 }
206 static inline unsigned short get_id_from_freelist(struct sk_buff **list)
207 {
208 unsigned int id = (unsigned int)(unsigned long)list[0];
209 list[0] = list[id];
210 return id;
211 }
213 static inline int xennet_rxidx(RING_IDX idx)
214 {
215 return idx & (NET_RX_RING_SIZE - 1);
216 }
218 static inline struct sk_buff *xennet_get_rx_skb(struct netfront_info *np,
219 RING_IDX ri)
220 {
221 int i = xennet_rxidx(ri);
222 struct sk_buff *skb = np->rx_skbs[i];
223 np->rx_skbs[i] = NULL;
224 return skb;
225 }
227 static inline grant_ref_t xennet_get_rx_ref(struct netfront_info *np,
228 RING_IDX ri)
229 {
230 int i = xennet_rxidx(ri);
231 grant_ref_t ref = np->grant_rx_ref[i];
232 np->grant_rx_ref[i] = GRANT_INVALID_REF;
233 return ref;
234 }
236 #define DPRINTK(fmt, args...) \
237 pr_debug("netfront (%s:%d) " fmt, \
238 __FUNCTION__, __LINE__, ##args)
239 #define IPRINTK(fmt, args...) \
240 printk(KERN_INFO "netfront: " fmt, ##args)
241 #define WPRINTK(fmt, args...) \
242 printk(KERN_WARNING "netfront: " fmt, ##args)
244 static int setup_device(struct xenbus_device *, struct netfront_info *);
245 static struct net_device *create_netdev(struct xenbus_device *);
247 static void end_access(int, void *);
248 static void netif_disconnect_backend(struct netfront_info *);
250 static int network_connect(struct net_device *);
251 static void network_tx_buf_gc(struct net_device *);
252 static void network_alloc_rx_buffers(struct net_device *);
253 static int send_fake_arp(struct net_device *);
255 static irqreturn_t netif_int(int irq, void *dev_id, struct pt_regs *ptregs);
257 #ifdef CONFIG_SYSFS
258 static int xennet_sysfs_addif(struct net_device *netdev);
259 static void xennet_sysfs_delif(struct net_device *netdev);
260 #else /* !CONFIG_SYSFS */
261 #define xennet_sysfs_addif(dev) (0)
262 #define xennet_sysfs_delif(dev) do { } while(0)
263 #endif
265 static inline int xennet_can_sg(struct net_device *dev)
266 {
267 return dev->features & NETIF_F_SG;
268 }
270 /**
271 * Entry point to this code when a new device is created. Allocate the basic
272 * structures and the ring buffers for communication with the backend, and
273 * inform the backend of the appropriate details for those.
274 */
275 static int __devinit netfront_probe(struct xenbus_device *dev,
276 const struct xenbus_device_id *id)
277 {
278 int err;
279 struct net_device *netdev;
280 struct netfront_info *info;
282 netdev = create_netdev(dev);
283 if (IS_ERR(netdev)) {
284 err = PTR_ERR(netdev);
285 xenbus_dev_fatal(dev, err, "creating netdev");
286 return err;
287 }
289 info = netdev_priv(netdev);
290 dev->dev.driver_data = info;
292 err = register_netdev(info->netdev);
293 if (err) {
294 printk(KERN_WARNING "%s: register_netdev err=%d\n",
295 __FUNCTION__, err);
296 goto fail;
297 }
299 err = xennet_sysfs_addif(info->netdev);
300 if (err) {
301 unregister_netdev(info->netdev);
302 printk(KERN_WARNING "%s: add sysfs failed err=%d\n",
303 __FUNCTION__, err);
304 goto fail;
305 }
307 return 0;
309 fail:
310 free_netdev(netdev);
311 dev->dev.driver_data = NULL;
312 return err;
313 }
315 static int __devexit netfront_remove(struct xenbus_device *dev)
316 {
317 struct netfront_info *info = dev->dev.driver_data;
319 DPRINTK("%s\n", dev->nodename);
321 netif_disconnect_backend(info);
323 del_timer_sync(&info->rx_refill_timer);
325 xennet_sysfs_delif(info->netdev);
327 unregister_netdev(info->netdev);
329 free_netdev(info->netdev);
331 return 0;
332 }
334 /**
335 * We are reconnecting to the backend, due to a suspend/resume, or a backend
336 * driver restart. We tear down our netif structure and recreate it, but
337 * leave the device-layer structures intact so that this is transparent to the
338 * rest of the kernel.
339 */
340 static int netfront_resume(struct xenbus_device *dev)
341 {
342 struct netfront_info *info = dev->dev.driver_data;
344 DPRINTK("%s\n", dev->nodename);
346 netif_disconnect_backend(info);
347 return 0;
348 }
350 static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
351 {
352 char *s, *e, *macstr;
353 int i;
355 macstr = s = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL);
356 if (IS_ERR(macstr))
357 return PTR_ERR(macstr);
359 for (i = 0; i < ETH_ALEN; i++) {
360 mac[i] = simple_strtoul(s, &e, 16);
361 if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) {
362 kfree(macstr);
363 return -ENOENT;
364 }
365 s = e+1;
366 }
368 kfree(macstr);
369 return 0;
370 }
372 /* Common code used when first setting up, and when resuming. */
373 static int talk_to_backend(struct xenbus_device *dev,
374 struct netfront_info *info)
375 {
376 const char *message;
377 struct xenbus_transaction xbt;
378 int err;
380 err = xen_net_read_mac(dev, info->mac);
381 if (err) {
382 xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
383 goto out;
384 }
386 /* Create shared ring, alloc event channel. */
387 err = setup_device(dev, info);
388 if (err)
389 goto out;
391 again:
392 err = xenbus_transaction_start(&xbt);
393 if (err) {
394 xenbus_dev_fatal(dev, err, "starting transaction");
395 goto destroy_ring;
396 }
398 err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref","%u",
399 info->tx_ring_ref);
400 if (err) {
401 message = "writing tx ring-ref";
402 goto abort_transaction;
403 }
404 err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref","%u",
405 info->rx_ring_ref);
406 if (err) {
407 message = "writing rx ring-ref";
408 goto abort_transaction;
409 }
410 err = xenbus_printf(xbt, dev->nodename,
411 "event-channel", "%u",
412 irq_to_evtchn_port(info->irq));
413 if (err) {
414 message = "writing event-channel";
415 goto abort_transaction;
416 }
418 err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
419 info->copying_receiver);
420 if (err) {
421 message = "writing request-rx-copy";
422 goto abort_transaction;
423 }
425 err = xenbus_printf(xbt, dev->nodename, "feature-rx-notify", "%d", 1);
426 if (err) {
427 message = "writing feature-rx-notify";
428 goto abort_transaction;
429 }
431 #ifdef HAVE_NO_CSUM_OFFLOAD
432 err = xenbus_printf(xbt, dev->nodename, "feature-no-csum-offload", "%d", 1);
433 if (err) {
434 message = "writing feature-no-csum-offload";
435 goto abort_transaction;
436 }
437 #endif
439 err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", 1);
440 if (err) {
441 message = "writing feature-sg";
442 goto abort_transaction;
443 }
445 #ifdef HAVE_TSO
446 err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d", 1);
447 if (err) {
448 message = "writing feature-gso-tcpv4";
449 goto abort_transaction;
450 }
451 #endif
453 err = xenbus_transaction_end(xbt, 0);
454 if (err) {
455 if (err == -EAGAIN)
456 goto again;
457 xenbus_dev_fatal(dev, err, "completing transaction");
458 goto destroy_ring;
459 }
461 return 0;
463 abort_transaction:
464 xenbus_transaction_end(xbt, 1);
465 xenbus_dev_fatal(dev, err, "%s", message);
466 destroy_ring:
467 netif_disconnect_backend(info);
468 out:
469 return err;
470 }
472 static int setup_device(struct xenbus_device *dev, struct netfront_info *info)
473 {
474 struct netif_tx_sring *txs;
475 struct netif_rx_sring *rxs;
476 int err;
477 struct net_device *netdev = info->netdev;
479 info->tx_ring_ref = GRANT_INVALID_REF;
480 info->rx_ring_ref = GRANT_INVALID_REF;
481 info->rx.sring = NULL;
482 info->tx.sring = NULL;
483 info->irq = 0;
485 txs = (struct netif_tx_sring *)get_zeroed_page(GFP_KERNEL);
486 if (!txs) {
487 err = -ENOMEM;
488 xenbus_dev_fatal(dev, err, "allocating tx ring page");
489 goto fail;
490 }
491 SHARED_RING_INIT(txs);
492 FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
494 err = xenbus_grant_ring(dev, virt_to_mfn(txs));
495 if (err < 0) {
496 free_page((unsigned long)txs);
497 goto fail;
498 }
499 info->tx_ring_ref = err;
501 rxs = (struct netif_rx_sring *)get_zeroed_page(GFP_KERNEL);
502 if (!rxs) {
503 err = -ENOMEM;
504 xenbus_dev_fatal(dev, err, "allocating rx ring page");
505 goto fail;
506 }
507 SHARED_RING_INIT(rxs);
508 FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
510 err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
511 if (err < 0) {
512 free_page((unsigned long)rxs);
513 goto fail;
514 }
515 info->rx_ring_ref = err;
517 memcpy(netdev->dev_addr, info->mac, ETH_ALEN);
519 err = bind_listening_port_to_irqhandler(
520 dev->otherend_id, netif_int, SA_SAMPLE_RANDOM, netdev->name,
521 netdev);
522 if (err < 0)
523 goto fail;
524 info->irq = err;
526 return 0;
528 fail:
529 return err;
530 }
532 /**
533 * Callback received when the backend's state changes.
534 */
535 static void backend_changed(struct xenbus_device *dev,
536 enum xenbus_state backend_state)
537 {
538 struct netfront_info *np = dev->dev.driver_data;
539 struct net_device *netdev = np->netdev;
541 DPRINTK("%s\n", xenbus_strstate(backend_state));
543 switch (backend_state) {
544 case XenbusStateInitialising:
545 case XenbusStateInitialised:
546 case XenbusStateConnected:
547 case XenbusStateUnknown:
548 case XenbusStateClosed:
549 break;
551 case XenbusStateInitWait:
552 if (dev->state != XenbusStateInitialising)
553 break;
554 if (network_connect(netdev) != 0)
555 break;
556 xenbus_switch_state(dev, XenbusStateConnected);
557 (void)send_fake_arp(netdev);
558 break;
560 case XenbusStateClosing:
561 xenbus_frontend_closed(dev);
562 break;
563 }
564 }
566 /** Send a packet on a net device to encourage switches to learn the
567 * MAC. We send a fake ARP request.
568 *
569 * @param dev device
570 * @return 0 on success, error code otherwise
571 */
572 static int send_fake_arp(struct net_device *dev)
573 {
574 struct sk_buff *skb;
575 u32 src_ip, dst_ip;
577 dst_ip = INADDR_BROADCAST;
578 src_ip = inet_select_addr(dev, dst_ip, RT_SCOPE_LINK);
580 /* No IP? Then nothing to do. */
581 if (src_ip == 0)
582 return 0;
584 skb = arp_create(ARPOP_REPLY, ETH_P_ARP,
585 dst_ip, dev, src_ip,
586 /*dst_hw*/ NULL, /*src_hw*/ NULL,
587 /*target_hw*/ dev->dev_addr);
588 if (skb == NULL)
589 return -ENOMEM;
591 return dev_queue_xmit(skb);
592 }
594 static int network_open(struct net_device *dev)
595 {
596 struct netfront_info *np = netdev_priv(dev);
598 memset(&np->stats, 0, sizeof(np->stats));
600 spin_lock(&np->rx_lock);
601 if (netif_carrier_ok(dev)) {
602 network_alloc_rx_buffers(dev);
603 np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
604 if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
605 netif_rx_schedule(dev);
606 }
607 spin_unlock(&np->rx_lock);
609 netif_start_queue(dev);
611 return 0;
612 }
614 static inline int netfront_tx_slot_available(struct netfront_info *np)
615 {
616 return ((np->tx.req_prod_pvt - np->tx.rsp_cons) <
617 (TX_MAX_TARGET - MAX_SKB_FRAGS - 2));
618 }
620 static inline void network_maybe_wake_tx(struct net_device *dev)
621 {
622 struct netfront_info *np = netdev_priv(dev);
624 if (unlikely(netif_queue_stopped(dev)) &&
625 netfront_tx_slot_available(np) &&
626 likely(netif_running(dev)))
627 netif_wake_queue(dev);
628 }
630 static void network_tx_buf_gc(struct net_device *dev)
631 {
632 RING_IDX cons, prod;
633 unsigned short id;
634 struct netfront_info *np = netdev_priv(dev);
635 struct sk_buff *skb;
637 BUG_ON(!netif_carrier_ok(dev));
639 do {
640 prod = np->tx.sring->rsp_prod;
641 rmb(); /* Ensure we see responses up to 'rp'. */
643 for (cons = np->tx.rsp_cons; cons != prod; cons++) {
644 struct netif_tx_response *txrsp;
646 txrsp = RING_GET_RESPONSE(&np->tx, cons);
647 if (txrsp->status == NETIF_RSP_NULL)
648 continue;
650 id = txrsp->id;
651 skb = np->tx_skbs[id];
652 if (unlikely(gnttab_query_foreign_access(
653 np->grant_tx_ref[id]) != 0)) {
654 printk(KERN_ALERT "network_tx_buf_gc: warning "
655 "-- grant still in use by backend "
656 "domain.\n");
657 BUG();
658 }
659 gnttab_end_foreign_access_ref(
660 np->grant_tx_ref[id], GNTMAP_readonly);
661 gnttab_release_grant_reference(
662 &np->gref_tx_head, np->grant_tx_ref[id]);
663 np->grant_tx_ref[id] = GRANT_INVALID_REF;
664 add_id_to_freelist(np->tx_skbs, id);
665 dev_kfree_skb_irq(skb);
666 }
668 np->tx.rsp_cons = prod;
670 /*
671 * Set a new event, then check for race with update of tx_cons.
672 * Note that it is essential to schedule a callback, no matter
673 * how few buffers are pending. Even if there is space in the
674 * transmit ring, higher layers may be blocked because too much
675 * data is outstanding: in such cases notification from Xen is
676 * likely to be the only kick that we'll get.
677 */
678 np->tx.sring->rsp_event =
679 prod + ((np->tx.sring->req_prod - prod) >> 1) + 1;
680 mb();
681 } while ((cons == prod) && (prod != np->tx.sring->rsp_prod));
683 network_maybe_wake_tx(dev);
684 }
686 static void rx_refill_timeout(unsigned long data)
687 {
688 struct net_device *dev = (struct net_device *)data;
689 netif_rx_schedule(dev);
690 }
692 static void network_alloc_rx_buffers(struct net_device *dev)
693 {
694 unsigned short id;
695 struct netfront_info *np = netdev_priv(dev);
696 struct sk_buff *skb;
697 struct page *page;
698 int i, batch_target, notify;
699 RING_IDX req_prod = np->rx.req_prod_pvt;
700 struct xen_memory_reservation reservation;
701 grant_ref_t ref;
702 unsigned long pfn;
703 void *vaddr;
704 int nr_flips;
705 netif_rx_request_t *req;
707 if (unlikely(!netif_carrier_ok(dev)))
708 return;
710 /*
711 * Allocate skbuffs greedily, even though we batch updates to the
712 * receive ring. This creates a less bursty demand on the memory
713 * allocator, so should reduce the chance of failed allocation requests
714 * both for ourself and for other kernel subsystems.
715 */
716 batch_target = np->rx_target - (req_prod - np->rx.rsp_cons);
717 for (i = skb_queue_len(&np->rx_batch); i < batch_target; i++) {
718 /*
719 * Allocate an skb and a page. Do not use __dev_alloc_skb as
720 * that will allocate page-sized buffers which is not
721 * necessary here.
722 * 16 bytes added as necessary headroom for netif_receive_skb.
723 */
724 skb = alloc_skb(RX_COPY_THRESHOLD + 16 + NET_IP_ALIGN,
725 GFP_ATOMIC | __GFP_NOWARN);
726 if (unlikely(!skb))
727 goto no_skb;
729 page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
730 if (!page) {
731 kfree_skb(skb);
732 no_skb:
733 /* Any skbuffs queued for refill? Force them out. */
734 if (i != 0)
735 goto refill;
736 /* Could not allocate any skbuffs. Try again later. */
737 mod_timer(&np->rx_refill_timer,
738 jiffies + (HZ/10));
739 break;
740 }
742 skb_reserve(skb, 16 + NET_IP_ALIGN); /* mimic dev_alloc_skb() */
743 skb_shinfo(skb)->frags[0].page = page;
744 skb_shinfo(skb)->nr_frags = 1;
745 __skb_queue_tail(&np->rx_batch, skb);
746 }
748 /* Is the batch large enough to be worthwhile? */
749 if (i < (np->rx_target/2)) {
750 if (req_prod > np->rx.sring->req_prod)
751 goto push;
752 return;
753 }
755 /* Adjust our fill target if we risked running out of buffers. */
756 if (((req_prod - np->rx.sring->rsp_prod) < (np->rx_target / 4)) &&
757 ((np->rx_target *= 2) > np->rx_max_target))
758 np->rx_target = np->rx_max_target;
760 refill:
761 for (nr_flips = i = 0; ; i++) {
762 if ((skb = __skb_dequeue(&np->rx_batch)) == NULL)
763 break;
765 skb->dev = dev;
767 id = xennet_rxidx(req_prod + i);
769 BUG_ON(np->rx_skbs[id]);
770 np->rx_skbs[id] = skb;
772 ref = gnttab_claim_grant_reference(&np->gref_rx_head);
773 BUG_ON((signed short)ref < 0);
774 np->grant_rx_ref[id] = ref;
776 pfn = page_to_pfn(skb_shinfo(skb)->frags[0].page);
777 vaddr = page_address(skb_shinfo(skb)->frags[0].page);
779 req = RING_GET_REQUEST(&np->rx, req_prod + i);
780 if (!np->copying_receiver) {
781 gnttab_grant_foreign_transfer_ref(ref,
782 np->xbdev->otherend_id,
783 pfn);
784 np->rx_pfn_array[nr_flips] = pfn_to_mfn(pfn);
785 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
786 /* Remove this page before passing
787 * back to Xen. */
788 set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
789 MULTI_update_va_mapping(np->rx_mcl+i,
790 (unsigned long)vaddr,
791 __pte(0), 0);
792 }
793 nr_flips++;
794 } else {
795 gnttab_grant_foreign_access_ref(ref,
796 np->xbdev->otherend_id,
797 pfn_to_mfn(pfn),
798 0);
799 }
801 req->id = id;
802 req->gref = ref;
803 }
805 if ( nr_flips != 0 ) {
806 /* Tell the ballon driver what is going on. */
807 balloon_update_driver_allowance(i);
809 set_xen_guest_handle(reservation.extent_start,
810 np->rx_pfn_array);
811 reservation.nr_extents = nr_flips;
812 reservation.extent_order = 0;
813 reservation.address_bits = 0;
814 reservation.domid = DOMID_SELF;
816 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
817 /* After all PTEs have been zapped, flush the TLB. */
818 np->rx_mcl[i-1].args[MULTI_UVMFLAGS_INDEX] =
819 UVMF_TLB_FLUSH|UVMF_ALL;
821 /* Give away a batch of pages. */
822 np->rx_mcl[i].op = __HYPERVISOR_memory_op;
823 np->rx_mcl[i].args[0] = XENMEM_decrease_reservation;
824 np->rx_mcl[i].args[1] = (unsigned long)&reservation;
826 /* Zap PTEs and give away pages in one big
827 * multicall. */
828 (void)HYPERVISOR_multicall(np->rx_mcl, i+1);
830 /* Check return status of HYPERVISOR_memory_op(). */
831 if (unlikely(np->rx_mcl[i].result != i))
832 panic("Unable to reduce memory reservation\n");
833 } else {
834 if (HYPERVISOR_memory_op(XENMEM_decrease_reservation,
835 &reservation) != i)
836 panic("Unable to reduce memory reservation\n");
837 }
838 } else {
839 wmb();
840 }
842 /* Above is a suitable barrier to ensure backend will see requests. */
843 np->rx.req_prod_pvt = req_prod + i;
844 push:
845 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->rx, notify);
846 if (notify)
847 notify_remote_via_irq(np->irq);
848 }
850 static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
851 struct netif_tx_request *tx)
852 {
853 struct netfront_info *np = netdev_priv(dev);
854 char *data = skb->data;
855 unsigned long mfn;
856 RING_IDX prod = np->tx.req_prod_pvt;
857 int frags = skb_shinfo(skb)->nr_frags;
858 unsigned int offset = offset_in_page(data);
859 unsigned int len = skb_headlen(skb);
860 unsigned int id;
861 grant_ref_t ref;
862 int i;
864 while (len > PAGE_SIZE - offset) {
865 tx->size = PAGE_SIZE - offset;
866 tx->flags |= NETTXF_more_data;
867 len -= tx->size;
868 data += tx->size;
869 offset = 0;
871 id = get_id_from_freelist(np->tx_skbs);
872 np->tx_skbs[id] = skb_get(skb);
873 tx = RING_GET_REQUEST(&np->tx, prod++);
874 tx->id = id;
875 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
876 BUG_ON((signed short)ref < 0);
878 mfn = virt_to_mfn(data);
879 gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
880 mfn, GNTMAP_readonly);
882 tx->gref = np->grant_tx_ref[id] = ref;
883 tx->offset = offset;
884 tx->size = len;
885 tx->flags = 0;
886 }
888 for (i = 0; i < frags; i++) {
889 skb_frag_t *frag = skb_shinfo(skb)->frags + i;
891 tx->flags |= NETTXF_more_data;
893 id = get_id_from_freelist(np->tx_skbs);
894 np->tx_skbs[id] = skb_get(skb);
895 tx = RING_GET_REQUEST(&np->tx, prod++);
896 tx->id = id;
897 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
898 BUG_ON((signed short)ref < 0);
900 mfn = pfn_to_mfn(page_to_pfn(frag->page));
901 gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
902 mfn, GNTMAP_readonly);
904 tx->gref = np->grant_tx_ref[id] = ref;
905 tx->offset = frag->page_offset;
906 tx->size = frag->size;
907 tx->flags = 0;
908 }
910 np->tx.req_prod_pvt = prod;
911 }
913 static int network_start_xmit(struct sk_buff *skb, struct net_device *dev)
914 {
915 unsigned short id;
916 struct netfront_info *np = netdev_priv(dev);
917 struct netif_tx_request *tx;
918 struct netif_extra_info *extra;
919 char *data = skb->data;
920 RING_IDX i;
921 grant_ref_t ref;
922 unsigned long mfn;
923 int notify;
924 int frags = skb_shinfo(skb)->nr_frags;
925 unsigned int offset = offset_in_page(data);
926 unsigned int len = skb_headlen(skb);
928 frags += (offset + len + PAGE_SIZE - 1) / PAGE_SIZE;
929 if (unlikely(frags > MAX_SKB_FRAGS + 1)) {
930 printk(KERN_ALERT "xennet: skb rides the rocket: %d frags\n",
931 frags);
932 dump_stack();
933 goto drop;
934 }
936 spin_lock_irq(&np->tx_lock);
938 if (unlikely(!netif_carrier_ok(dev) ||
939 (frags > 1 && !xennet_can_sg(dev)) ||
940 netif_needs_gso(dev, skb))) {
941 spin_unlock_irq(&np->tx_lock);
942 goto drop;
943 }
945 i = np->tx.req_prod_pvt;
947 id = get_id_from_freelist(np->tx_skbs);
948 np->tx_skbs[id] = skb;
950 tx = RING_GET_REQUEST(&np->tx, i);
952 tx->id = id;
953 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
954 BUG_ON((signed short)ref < 0);
955 mfn = virt_to_mfn(data);
956 gnttab_grant_foreign_access_ref(
957 ref, np->xbdev->otherend_id, mfn, GNTMAP_readonly);
958 tx->gref = np->grant_tx_ref[id] = ref;
959 tx->offset = offset;
960 tx->size = len;
962 tx->flags = 0;
963 extra = NULL;
965 if (skb->ip_summed == CHECKSUM_HW) /* local packet? */
966 tx->flags |= NETTXF_csum_blank | NETTXF_data_validated;
967 #ifdef CONFIG_XEN
968 if (skb->proto_data_valid) /* remote but checksummed? */
969 tx->flags |= NETTXF_data_validated;
970 #endif
972 #ifdef HAVE_TSO
973 if (skb_shinfo(skb)->gso_size) {
974 struct netif_extra_info *gso = (struct netif_extra_info *)
975 RING_GET_REQUEST(&np->tx, ++i);
977 if (extra)
978 extra->flags |= XEN_NETIF_EXTRA_FLAG_MORE;
979 else
980 tx->flags |= NETTXF_extra_info;
982 gso->u.gso.size = skb_shinfo(skb)->gso_size;
983 gso->u.gso.type = XEN_NETIF_GSO_TYPE_TCPV4;
984 gso->u.gso.pad = 0;
985 gso->u.gso.features = 0;
987 gso->type = XEN_NETIF_EXTRA_TYPE_GSO;
988 gso->flags = 0;
989 extra = gso;
990 }
991 #endif
993 np->tx.req_prod_pvt = i + 1;
995 xennet_make_frags(skb, dev, tx);
996 tx->size = skb->len;
998 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->tx, notify);
999 if (notify)
1000 notify_remote_via_irq(np->irq);
1002 network_tx_buf_gc(dev);
1004 if (!netfront_tx_slot_available(np))
1005 netif_stop_queue(dev);
1007 spin_unlock_irq(&np->tx_lock);
1009 np->stats.tx_bytes += skb->len;
1010 np->stats.tx_packets++;
1012 return 0;
1014 drop:
1015 np->stats.tx_dropped++;
1016 dev_kfree_skb(skb);
1017 return 0;
1020 static irqreturn_t netif_int(int irq, void *dev_id, struct pt_regs *ptregs)
1022 struct net_device *dev = dev_id;
1023 struct netfront_info *np = netdev_priv(dev);
1024 unsigned long flags;
1026 spin_lock_irqsave(&np->tx_lock, flags);
1028 if (likely(netif_carrier_ok(dev))) {
1029 network_tx_buf_gc(dev);
1030 /* Under tx_lock: protects access to rx shared-ring indexes. */
1031 if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
1032 netif_rx_schedule(dev);
1035 spin_unlock_irqrestore(&np->tx_lock, flags);
1037 return IRQ_HANDLED;
1040 static void xennet_move_rx_slot(struct netfront_info *np, struct sk_buff *skb,
1041 grant_ref_t ref)
1043 int new = xennet_rxidx(np->rx.req_prod_pvt);
1045 BUG_ON(np->rx_skbs[new]);
1046 np->rx_skbs[new] = skb;
1047 np->grant_rx_ref[new] = ref;
1048 RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->id = new;
1049 RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->gref = ref;
1050 np->rx.req_prod_pvt++;
1053 int xennet_get_extras(struct netfront_info *np,
1054 struct netif_extra_info *extras, RING_IDX rp)
1057 struct netif_extra_info *extra;
1058 RING_IDX cons = np->rx.rsp_cons;
1059 int err = 0;
1061 do {
1062 struct sk_buff *skb;
1063 grant_ref_t ref;
1065 if (unlikely(cons + 1 == rp)) {
1066 if (net_ratelimit())
1067 WPRINTK("Missing extra info\n");
1068 err = -EBADR;
1069 break;
1072 extra = (struct netif_extra_info *)
1073 RING_GET_RESPONSE(&np->rx, ++cons);
1075 if (unlikely(!extra->type ||
1076 extra->type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
1077 if (net_ratelimit())
1078 WPRINTK("Invalid extra type: %d\n",
1079 extra->type);
1080 err = -EINVAL;
1081 } else {
1082 memcpy(&extras[extra->type - 1], extra,
1083 sizeof(*extra));
1086 skb = xennet_get_rx_skb(np, cons);
1087 ref = xennet_get_rx_ref(np, cons);
1088 xennet_move_rx_slot(np, skb, ref);
1089 } while (extra->flags & XEN_NETIF_EXTRA_FLAG_MORE);
1091 np->rx.rsp_cons = cons;
1092 return err;
1095 static int xennet_get_responses(struct netfront_info *np,
1096 struct netfront_rx_info *rinfo, RING_IDX rp,
1097 struct sk_buff_head *list,
1098 int *pages_flipped_p)
1100 int pages_flipped = *pages_flipped_p;
1101 struct mmu_update *mmu;
1102 struct multicall_entry *mcl;
1103 struct netif_rx_response *rx = &rinfo->rx;
1104 struct netif_extra_info *extras = rinfo->extras;
1105 RING_IDX cons = np->rx.rsp_cons;
1106 struct sk_buff *skb = xennet_get_rx_skb(np, cons);
1107 grant_ref_t ref = xennet_get_rx_ref(np, cons);
1108 int max = MAX_SKB_FRAGS + (rx->status <= RX_COPY_THRESHOLD);
1109 int frags = 1;
1110 int err = 0;
1111 unsigned long ret;
1113 if (rx->flags & NETRXF_extra_info) {
1114 err = xennet_get_extras(np, extras, rp);
1115 cons = np->rx.rsp_cons;
1118 for (;;) {
1119 unsigned long mfn;
1121 if (unlikely(rx->status < 0 ||
1122 rx->offset + rx->status > PAGE_SIZE)) {
1123 if (net_ratelimit())
1124 WPRINTK("rx->offset: %x, size: %u\n",
1125 rx->offset, rx->status);
1126 xennet_move_rx_slot(np, skb, ref);
1127 err = -EINVAL;
1128 goto next;
1131 /*
1132 * This definitely indicates a bug, either in this driver or in
1133 * the backend driver. In future this should flag the bad
1134 * situation to the system controller to reboot the backed.
1135 */
1136 if (ref == GRANT_INVALID_REF) {
1137 if (net_ratelimit())
1138 WPRINTK("Bad rx response id %d.\n", rx->id);
1139 err = -EINVAL;
1140 goto next;
1143 if (!np->copying_receiver) {
1144 /* Memory pressure, insufficient buffer
1145 * headroom, ... */
1146 if (!(mfn = gnttab_end_foreign_transfer_ref(ref))) {
1147 if (net_ratelimit())
1148 WPRINTK("Unfulfilled rx req "
1149 "(id=%d, st=%d).\n",
1150 rx->id, rx->status);
1151 xennet_move_rx_slot(np, skb, ref);
1152 err = -ENOMEM;
1153 goto next;
1156 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1157 /* Remap the page. */
1158 struct page *page =
1159 skb_shinfo(skb)->frags[0].page;
1160 unsigned long pfn = page_to_pfn(page);
1161 void *vaddr = page_address(page);
1163 mcl = np->rx_mcl + pages_flipped;
1164 mmu = np->rx_mmu + pages_flipped;
1166 MULTI_update_va_mapping(mcl,
1167 (unsigned long)vaddr,
1168 pfn_pte_ma(mfn,
1169 PAGE_KERNEL),
1170 0);
1171 mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
1172 | MMU_MACHPHYS_UPDATE;
1173 mmu->val = pfn;
1175 set_phys_to_machine(pfn, mfn);
1177 pages_flipped++;
1178 } else {
1179 ret = gnttab_end_foreign_access_ref(ref, 0);
1180 BUG_ON(!ret);
1183 gnttab_release_grant_reference(&np->gref_rx_head, ref);
1185 __skb_queue_tail(list, skb);
1187 next:
1188 if (!(rx->flags & NETRXF_more_data))
1189 break;
1191 if (cons + frags == rp) {
1192 if (net_ratelimit())
1193 WPRINTK("Need more frags\n");
1194 err = -ENOENT;
1195 break;
1198 rx = RING_GET_RESPONSE(&np->rx, cons + frags);
1199 skb = xennet_get_rx_skb(np, cons + frags);
1200 ref = xennet_get_rx_ref(np, cons + frags);
1201 frags++;
1204 if (unlikely(frags > max)) {
1205 if (net_ratelimit())
1206 WPRINTK("Too many frags\n");
1207 err = -E2BIG;
1210 if (unlikely(err))
1211 np->rx.rsp_cons = cons + frags;
1213 *pages_flipped_p = pages_flipped;
1215 return err;
1218 static RING_IDX xennet_fill_frags(struct netfront_info *np,
1219 struct sk_buff *skb,
1220 struct sk_buff_head *list)
1222 struct skb_shared_info *shinfo = skb_shinfo(skb);
1223 int nr_frags = shinfo->nr_frags;
1224 RING_IDX cons = np->rx.rsp_cons;
1225 skb_frag_t *frag = shinfo->frags + nr_frags;
1226 struct sk_buff *nskb;
1228 while ((nskb = __skb_dequeue(list))) {
1229 struct netif_rx_response *rx =
1230 RING_GET_RESPONSE(&np->rx, ++cons);
1232 frag->page = skb_shinfo(nskb)->frags[0].page;
1233 frag->page_offset = rx->offset;
1234 frag->size = rx->status;
1236 skb->data_len += rx->status;
1238 skb_shinfo(nskb)->nr_frags = 0;
1239 kfree_skb(nskb);
1241 frag++;
1242 nr_frags++;
1245 shinfo->nr_frags = nr_frags;
1246 return cons;
1249 static int xennet_set_skb_gso(struct sk_buff *skb,
1250 struct netif_extra_info *gso)
1252 if (!gso->u.gso.size) {
1253 if (net_ratelimit())
1254 WPRINTK("GSO size must not be zero.\n");
1255 return -EINVAL;
1258 /* Currently only TCPv4 S.O. is supported. */
1259 if (gso->u.gso.type != XEN_NETIF_GSO_TYPE_TCPV4) {
1260 if (net_ratelimit())
1261 WPRINTK("Bad GSO type %d.\n", gso->u.gso.type);
1262 return -EINVAL;
1265 #ifdef HAVE_TSO
1266 skb_shinfo(skb)->gso_size = gso->u.gso.size;
1267 #ifdef HAVE_GSO
1268 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1270 /* Header must be checked, and gso_segs computed. */
1271 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
1272 #endif
1273 skb_shinfo(skb)->gso_segs = 0;
1275 return 0;
1276 #else
1277 if (net_ratelimit())
1278 WPRINTK("GSO unsupported by this kernel.\n");
1279 return -EINVAL;
1280 #endif
1283 static int netif_poll(struct net_device *dev, int *pbudget)
1285 struct netfront_info *np = netdev_priv(dev);
1286 struct sk_buff *skb;
1287 struct netfront_rx_info rinfo;
1288 struct netif_rx_response *rx = &rinfo.rx;
1289 struct netif_extra_info *extras = rinfo.extras;
1290 RING_IDX i, rp;
1291 struct multicall_entry *mcl;
1292 int work_done, budget, more_to_do = 1;
1293 struct sk_buff_head rxq;
1294 struct sk_buff_head errq;
1295 struct sk_buff_head tmpq;
1296 unsigned long flags;
1297 unsigned int len;
1298 int pages_flipped = 0;
1299 int err;
1301 spin_lock(&np->rx_lock);
1303 if (unlikely(!netif_carrier_ok(dev))) {
1304 spin_unlock(&np->rx_lock);
1305 return 0;
1308 skb_queue_head_init(&rxq);
1309 skb_queue_head_init(&errq);
1310 skb_queue_head_init(&tmpq);
1312 if ((budget = *pbudget) > dev->quota)
1313 budget = dev->quota;
1314 rp = np->rx.sring->rsp_prod;
1315 rmb(); /* Ensure we see queued responses up to 'rp'. */
1317 i = np->rx.rsp_cons;
1318 work_done = 0;
1319 while ((i != rp) && (work_done < budget)) {
1320 memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx));
1321 memset(extras, 0, sizeof(extras));
1323 err = xennet_get_responses(np, &rinfo, rp, &tmpq,
1324 &pages_flipped);
1326 if (unlikely(err)) {
1327 err:
1328 while ((skb = __skb_dequeue(&tmpq)))
1329 __skb_queue_tail(&errq, skb);
1330 np->stats.rx_errors++;
1331 i = np->rx.rsp_cons;
1332 continue;
1335 skb = __skb_dequeue(&tmpq);
1337 if (extras[XEN_NETIF_EXTRA_TYPE_GSO - 1].type) {
1338 struct netif_extra_info *gso;
1339 gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO - 1];
1341 if (unlikely(xennet_set_skb_gso(skb, gso))) {
1342 __skb_queue_head(&tmpq, skb);
1343 np->rx.rsp_cons += skb_queue_len(&tmpq);
1344 goto err;
1348 skb->nh.raw = (void *)skb_shinfo(skb)->frags[0].page;
1349 skb->h.raw = skb->nh.raw + rx->offset;
1351 len = rx->status;
1352 if (len > RX_COPY_THRESHOLD)
1353 len = RX_COPY_THRESHOLD;
1354 skb_put(skb, len);
1356 if (rx->status > len) {
1357 skb_shinfo(skb)->frags[0].page_offset =
1358 rx->offset + len;
1359 skb_shinfo(skb)->frags[0].size = rx->status - len;
1360 skb->data_len = rx->status - len;
1361 } else {
1362 skb_shinfo(skb)->frags[0].page = NULL;
1363 skb_shinfo(skb)->nr_frags = 0;
1366 i = xennet_fill_frags(np, skb, &tmpq);
1368 /*
1369 * Truesize must approximates the size of true data plus
1370 * any supervisor overheads. Adding hypervisor overheads
1371 * has been shown to significantly reduce achievable
1372 * bandwidth with the default receive buffer size. It is
1373 * therefore not wise to account for it here.
1375 * After alloc_skb(RX_COPY_THRESHOLD), truesize is set to
1376 * RX_COPY_THRESHOLD + the supervisor overheads. Here, we
1377 * add the size of the data pulled in xennet_fill_frags().
1379 * We also adjust for any unused space in the main data
1380 * area by subtracting (RX_COPY_THRESHOLD - len). This is
1381 * especially important with drivers which split incoming
1382 * packets into header and data, using only 66 bytes of
1383 * the main data area (see the e1000 driver for example.)
1384 * On such systems, without this last adjustement, our
1385 * achievable receive throughout using the standard receive
1386 * buffer size was cut by 25%(!!!).
1387 */
1388 skb->truesize += skb->data_len - (RX_COPY_THRESHOLD - len);
1389 skb->len += skb->data_len;
1391 /*
1392 * Old backends do not assert data_validated but we
1393 * can infer it from csum_blank so test both flags.
1394 */
1395 if (rx->flags & (NETRXF_data_validated|NETRXF_csum_blank))
1396 skb->ip_summed = CHECKSUM_UNNECESSARY;
1397 else
1398 skb->ip_summed = CHECKSUM_NONE;
1399 #ifdef CONFIG_XEN
1400 skb->proto_data_valid = (skb->ip_summed != CHECKSUM_NONE);
1401 skb->proto_csum_blank = !!(rx->flags & NETRXF_csum_blank);
1402 #endif
1403 np->stats.rx_packets++;
1404 np->stats.rx_bytes += skb->len;
1406 __skb_queue_tail(&rxq, skb);
1408 np->rx.rsp_cons = ++i;
1409 work_done++;
1412 if (pages_flipped) {
1413 /* Some pages are no longer absent... */
1414 balloon_update_driver_allowance(-pages_flipped);
1416 /* Do all the remapping work and M2P updates. */
1417 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1418 mcl = np->rx_mcl + pages_flipped;
1419 mcl->op = __HYPERVISOR_mmu_update;
1420 mcl->args[0] = (unsigned long)np->rx_mmu;
1421 mcl->args[1] = pages_flipped;
1422 mcl->args[2] = 0;
1423 mcl->args[3] = DOMID_SELF;
1424 (void)HYPERVISOR_multicall(np->rx_mcl,
1425 pages_flipped + 1);
1429 while ((skb = __skb_dequeue(&errq)))
1430 kfree_skb(skb);
1432 while ((skb = __skb_dequeue(&rxq)) != NULL) {
1433 struct page *page = (struct page *)skb->nh.raw;
1434 void *vaddr = page_address(page);
1436 memcpy(skb->data, vaddr + (skb->h.raw - skb->nh.raw),
1437 skb_headlen(skb));
1439 if (page != skb_shinfo(skb)->frags[0].page)
1440 __free_page(page);
1442 /* Ethernet work: Delayed to here as it peeks the header. */
1443 skb->protocol = eth_type_trans(skb, dev);
1445 /* Pass it up. */
1446 netif_receive_skb(skb);
1447 dev->last_rx = jiffies;
1450 /* If we get a callback with very few responses, reduce fill target. */
1451 /* NB. Note exponential increase, linear decrease. */
1452 if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) >
1453 ((3*np->rx_target) / 4)) &&
1454 (--np->rx_target < np->rx_min_target))
1455 np->rx_target = np->rx_min_target;
1457 network_alloc_rx_buffers(dev);
1459 *pbudget -= work_done;
1460 dev->quota -= work_done;
1462 if (work_done < budget) {
1463 local_irq_save(flags);
1465 RING_FINAL_CHECK_FOR_RESPONSES(&np->rx, more_to_do);
1466 if (!more_to_do)
1467 __netif_rx_complete(dev);
1469 local_irq_restore(flags);
1472 spin_unlock(&np->rx_lock);
1474 return more_to_do;
1477 static void netif_release_tx_bufs(struct netfront_info *np)
1479 struct sk_buff *skb;
1480 int i;
1482 for (i = 1; i <= NET_TX_RING_SIZE; i++) {
1483 if ((unsigned long)np->tx_skbs[i] < PAGE_OFFSET)
1484 continue;
1486 skb = np->tx_skbs[i];
1487 gnttab_end_foreign_access_ref(
1488 np->grant_tx_ref[i], GNTMAP_readonly);
1489 gnttab_release_grant_reference(
1490 &np->gref_tx_head, np->grant_tx_ref[i]);
1491 np->grant_tx_ref[i] = GRANT_INVALID_REF;
1492 add_id_to_freelist(np->tx_skbs, i);
1493 dev_kfree_skb_irq(skb);
1497 static void netif_release_rx_bufs(struct netfront_info *np)
1499 struct mmu_update *mmu = np->rx_mmu;
1500 struct multicall_entry *mcl = np->rx_mcl;
1501 struct sk_buff_head free_list;
1502 struct sk_buff *skb;
1503 unsigned long mfn;
1504 int xfer = 0, noxfer = 0, unused = 0;
1505 int id, ref;
1507 if (np->copying_receiver) {
1508 printk("%s: fix me for copying receiver.\n", __FUNCTION__);
1509 return;
1512 skb_queue_head_init(&free_list);
1514 spin_lock(&np->rx_lock);
1516 for (id = 0; id < NET_RX_RING_SIZE; id++) {
1517 if ((ref = np->grant_rx_ref[id]) == GRANT_INVALID_REF) {
1518 unused++;
1519 continue;
1522 skb = np->rx_skbs[id];
1523 mfn = gnttab_end_foreign_transfer_ref(ref);
1524 gnttab_release_grant_reference(&np->gref_rx_head, ref);
1525 np->grant_rx_ref[id] = GRANT_INVALID_REF;
1526 add_id_to_freelist(np->rx_skbs, id);
1528 if (0 == mfn) {
1529 struct page *page = skb_shinfo(skb)->frags[0].page;
1530 balloon_release_driver_page(page);
1531 skb_shinfo(skb)->nr_frags = 0;
1532 dev_kfree_skb(skb);
1533 noxfer++;
1534 continue;
1537 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1538 /* Remap the page. */
1539 struct page *page = skb_shinfo(skb)->frags[0].page;
1540 unsigned long pfn = page_to_pfn(page);
1541 void *vaddr = page_address(page);
1543 MULTI_update_va_mapping(mcl, (unsigned long)vaddr,
1544 pfn_pte_ma(mfn, PAGE_KERNEL),
1545 0);
1546 mcl++;
1547 mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
1548 | MMU_MACHPHYS_UPDATE;
1549 mmu->val = pfn;
1550 mmu++;
1552 set_phys_to_machine(pfn, mfn);
1554 __skb_queue_tail(&free_list, skb);
1555 xfer++;
1558 printk("%s: %d xfer, %d noxfer, %d unused\n",
1559 __FUNCTION__, xfer, noxfer, unused);
1561 if (xfer) {
1562 /* Some pages are no longer absent... */
1563 balloon_update_driver_allowance(-xfer);
1565 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1566 /* Do all the remapping work and M2P updates. */
1567 mcl->op = __HYPERVISOR_mmu_update;
1568 mcl->args[0] = (unsigned long)np->rx_mmu;
1569 mcl->args[1] = mmu - np->rx_mmu;
1570 mcl->args[2] = 0;
1571 mcl->args[3] = DOMID_SELF;
1572 mcl++;
1573 HYPERVISOR_multicall(np->rx_mcl, mcl - np->rx_mcl);
1577 while ((skb = __skb_dequeue(&free_list)) != NULL)
1578 dev_kfree_skb(skb);
1580 spin_unlock(&np->rx_lock);
1583 static int network_close(struct net_device *dev)
1585 struct netfront_info *np = netdev_priv(dev);
1586 netif_stop_queue(np->netdev);
1587 return 0;
1591 static struct net_device_stats *network_get_stats(struct net_device *dev)
1593 struct netfront_info *np = netdev_priv(dev);
1594 return &np->stats;
1597 static int xennet_change_mtu(struct net_device *dev, int mtu)
1599 int max = xennet_can_sg(dev) ? 65535 - ETH_HLEN : ETH_DATA_LEN;
1601 if (mtu > max)
1602 return -EINVAL;
1603 dev->mtu = mtu;
1604 return 0;
1607 static int xennet_set_sg(struct net_device *dev, u32 data)
1609 if (data) {
1610 struct netfront_info *np = netdev_priv(dev);
1611 int val;
1613 if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, "feature-sg",
1614 "%d", &val) < 0)
1615 val = 0;
1616 if (!val)
1617 return -ENOSYS;
1618 } else if (dev->mtu > ETH_DATA_LEN)
1619 dev->mtu = ETH_DATA_LEN;
1621 return ethtool_op_set_sg(dev, data);
1624 static int xennet_set_tso(struct net_device *dev, u32 data)
1626 #ifdef HAVE_TSO
1627 if (data) {
1628 struct netfront_info *np = netdev_priv(dev);
1629 int val;
1631 if (xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1632 "feature-gso-tcpv4", "%d", &val) < 0)
1633 val = 0;
1634 if (!val)
1635 return -ENOSYS;
1638 return ethtool_op_set_tso(dev, data);
1639 #else
1640 return -ENOSYS;
1641 #endif
1644 static void xennet_set_features(struct net_device *dev)
1646 dev_disable_gso_features(dev);
1647 xennet_set_sg(dev, 0);
1649 /* We need checksum offload to enable scatter/gather and TSO. */
1650 if (!(dev->features & NETIF_F_IP_CSUM))
1651 return;
1653 if (xennet_set_sg(dev, 1))
1654 return;
1656 /* Before 2.6.9 TSO seems to be unreliable so do not enable it
1657 * on older kernels.
1658 */
1659 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
1660 xennet_set_tso(dev, 1);
1661 #endif
1665 static int network_connect(struct net_device *dev)
1667 struct netfront_info *np = netdev_priv(dev);
1668 int i, requeue_idx, err;
1669 struct sk_buff *skb;
1670 grant_ref_t ref;
1671 netif_rx_request_t *req;
1672 unsigned int feature_rx_copy, feature_rx_flip;
1674 err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1675 "feature-rx-copy", "%u", &feature_rx_copy);
1676 if (err != 1)
1677 feature_rx_copy = 0;
1678 err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1679 "feature-rx-flip", "%u", &feature_rx_flip);
1680 if (err != 1)
1681 feature_rx_flip = 1;
1683 /*
1684 * Copy packets on receive path if:
1685 * (a) This was requested by user, and the backend supports it; or
1686 * (b) Flipping was requested, but this is unsupported by the backend.
1687 */
1688 np->copying_receiver = ((MODPARM_rx_copy && feature_rx_copy) ||
1689 (MODPARM_rx_flip && !feature_rx_flip));
1691 err = talk_to_backend(np->xbdev, np);
1692 if (err)
1693 return err;
1695 xennet_set_features(dev);
1697 IPRINTK("device %s has %sing receive path.\n",
1698 dev->name, np->copying_receiver ? "copy" : "flipp");
1700 spin_lock_irq(&np->tx_lock);
1701 spin_lock(&np->rx_lock);
1703 /*
1704 * Recovery procedure:
1705 * NB. Freelist index entries are always going to be less than
1706 * PAGE_OFFSET, whereas pointers to skbs will always be equal or
1707 * greater than PAGE_OFFSET: we use this property to distinguish
1708 * them.
1709 */
1711 /* Step 1: Discard all pending TX packet fragments. */
1712 netif_release_tx_bufs(np);
1714 /* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
1715 for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
1716 if (!np->rx_skbs[i])
1717 continue;
1719 skb = np->rx_skbs[requeue_idx] = xennet_get_rx_skb(np, i);
1720 ref = np->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(np, i);
1721 req = RING_GET_REQUEST(&np->rx, requeue_idx);
1723 if (!np->copying_receiver) {
1724 gnttab_grant_foreign_transfer_ref(
1725 ref, np->xbdev->otherend_id,
1726 page_to_pfn(skb_shinfo(skb)->frags->page));
1727 } else {
1728 gnttab_grant_foreign_access_ref(
1729 ref, np->xbdev->otherend_id,
1730 pfn_to_mfn(page_to_pfn(skb_shinfo(skb)->
1731 frags->page)),
1732 0);
1734 req->gref = ref;
1735 req->id = requeue_idx;
1737 requeue_idx++;
1740 np->rx.req_prod_pvt = requeue_idx;
1742 /*
1743 * Step 3: All public and private state should now be sane. Get
1744 * ready to start sending and receiving packets and give the driver
1745 * domain a kick because we've probably just requeued some
1746 * packets.
1747 */
1748 netif_carrier_on(dev);
1749 notify_remote_via_irq(np->irq);
1750 network_tx_buf_gc(dev);
1751 network_alloc_rx_buffers(dev);
1753 spin_unlock(&np->rx_lock);
1754 spin_unlock_irq(&np->tx_lock);
1756 return 0;
1759 static void netif_uninit(struct net_device *dev)
1761 struct netfront_info *np = netdev_priv(dev);
1762 netif_release_tx_bufs(np);
1763 netif_release_rx_bufs(np);
1764 gnttab_free_grant_references(np->gref_tx_head);
1765 gnttab_free_grant_references(np->gref_rx_head);
1768 static struct ethtool_ops network_ethtool_ops =
1770 .get_tx_csum = ethtool_op_get_tx_csum,
1771 .set_tx_csum = ethtool_op_set_tx_csum,
1772 .get_sg = ethtool_op_get_sg,
1773 .set_sg = xennet_set_sg,
1774 .get_tso = ethtool_op_get_tso,
1775 .set_tso = xennet_set_tso,
1776 .get_link = ethtool_op_get_link,
1777 };
1779 #ifdef CONFIG_SYSFS
1780 static ssize_t show_rxbuf_min(struct class_device *cd, char *buf)
1782 struct net_device *netdev = container_of(cd, struct net_device,
1783 class_dev);
1784 struct netfront_info *info = netdev_priv(netdev);
1786 return sprintf(buf, "%u\n", info->rx_min_target);
1789 static ssize_t store_rxbuf_min(struct class_device *cd,
1790 const char *buf, size_t len)
1792 struct net_device *netdev = container_of(cd, struct net_device,
1793 class_dev);
1794 struct netfront_info *np = netdev_priv(netdev);
1795 char *endp;
1796 unsigned long target;
1798 if (!capable(CAP_NET_ADMIN))
1799 return -EPERM;
1801 target = simple_strtoul(buf, &endp, 0);
1802 if (endp == buf)
1803 return -EBADMSG;
1805 if (target < RX_MIN_TARGET)
1806 target = RX_MIN_TARGET;
1807 if (target > RX_MAX_TARGET)
1808 target = RX_MAX_TARGET;
1810 spin_lock(&np->rx_lock);
1811 if (target > np->rx_max_target)
1812 np->rx_max_target = target;
1813 np->rx_min_target = target;
1814 if (target > np->rx_target)
1815 np->rx_target = target;
1817 network_alloc_rx_buffers(netdev);
1819 spin_unlock(&np->rx_lock);
1820 return len;
1823 static ssize_t show_rxbuf_max(struct class_device *cd, char *buf)
1825 struct net_device *netdev = container_of(cd, struct net_device,
1826 class_dev);
1827 struct netfront_info *info = netdev_priv(netdev);
1829 return sprintf(buf, "%u\n", info->rx_max_target);
1832 static ssize_t store_rxbuf_max(struct class_device *cd,
1833 const char *buf, size_t len)
1835 struct net_device *netdev = container_of(cd, struct net_device,
1836 class_dev);
1837 struct netfront_info *np = netdev_priv(netdev);
1838 char *endp;
1839 unsigned long target;
1841 if (!capable(CAP_NET_ADMIN))
1842 return -EPERM;
1844 target = simple_strtoul(buf, &endp, 0);
1845 if (endp == buf)
1846 return -EBADMSG;
1848 if (target < RX_MIN_TARGET)
1849 target = RX_MIN_TARGET;
1850 if (target > RX_MAX_TARGET)
1851 target = RX_MAX_TARGET;
1853 spin_lock(&np->rx_lock);
1854 if (target < np->rx_min_target)
1855 np->rx_min_target = target;
1856 np->rx_max_target = target;
1857 if (target < np->rx_target)
1858 np->rx_target = target;
1860 network_alloc_rx_buffers(netdev);
1862 spin_unlock(&np->rx_lock);
1863 return len;
1866 static ssize_t show_rxbuf_cur(struct class_device *cd, char *buf)
1868 struct net_device *netdev = container_of(cd, struct net_device,
1869 class_dev);
1870 struct netfront_info *info = netdev_priv(netdev);
1872 return sprintf(buf, "%u\n", info->rx_target);
1875 static const struct class_device_attribute xennet_attrs[] = {
1876 __ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf_min, store_rxbuf_min),
1877 __ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf_max, store_rxbuf_max),
1878 __ATTR(rxbuf_cur, S_IRUGO, show_rxbuf_cur, NULL),
1879 };
1881 static int xennet_sysfs_addif(struct net_device *netdev)
1883 int i;
1884 int error = 0;
1886 for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
1887 error = class_device_create_file(&netdev->class_dev,
1888 &xennet_attrs[i]);
1889 if (error)
1890 goto fail;
1892 return 0;
1894 fail:
1895 while (--i >= 0)
1896 class_device_remove_file(&netdev->class_dev,
1897 &xennet_attrs[i]);
1898 return error;
1901 static void xennet_sysfs_delif(struct net_device *netdev)
1903 int i;
1905 for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
1906 class_device_remove_file(&netdev->class_dev,
1907 &xennet_attrs[i]);
1911 #endif /* CONFIG_SYSFS */
1914 /*
1915 * Nothing to do here. Virtual interface is point-to-point and the
1916 * physical interface is probably promiscuous anyway.
1917 */
1918 static void network_set_multicast_list(struct net_device *dev)
1922 static struct net_device * __devinit create_netdev(struct xenbus_device *dev)
1924 int i, err = 0;
1925 struct net_device *netdev = NULL;
1926 struct netfront_info *np = NULL;
1928 netdev = alloc_etherdev(sizeof(struct netfront_info));
1929 if (!netdev) {
1930 printk(KERN_WARNING "%s> alloc_etherdev failed.\n",
1931 __FUNCTION__);
1932 return ERR_PTR(-ENOMEM);
1935 np = netdev_priv(netdev);
1936 np->xbdev = dev;
1938 spin_lock_init(&np->tx_lock);
1939 spin_lock_init(&np->rx_lock);
1941 skb_queue_head_init(&np->rx_batch);
1942 np->rx_target = RX_DFL_MIN_TARGET;
1943 np->rx_min_target = RX_DFL_MIN_TARGET;
1944 np->rx_max_target = RX_MAX_TARGET;
1946 init_timer(&np->rx_refill_timer);
1947 np->rx_refill_timer.data = (unsigned long)netdev;
1948 np->rx_refill_timer.function = rx_refill_timeout;
1950 /* Initialise {tx,rx}_skbs as a free chain containing every entry. */
1951 for (i = 0; i <= NET_TX_RING_SIZE; i++) {
1952 np->tx_skbs[i] = (void *)((unsigned long) i+1);
1953 np->grant_tx_ref[i] = GRANT_INVALID_REF;
1956 for (i = 0; i < NET_RX_RING_SIZE; i++) {
1957 np->rx_skbs[i] = NULL;
1958 np->grant_rx_ref[i] = GRANT_INVALID_REF;
1961 /* A grant for every tx ring slot */
1962 if (gnttab_alloc_grant_references(TX_MAX_TARGET,
1963 &np->gref_tx_head) < 0) {
1964 printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n");
1965 err = -ENOMEM;
1966 goto exit;
1968 /* A grant for every rx ring slot */
1969 if (gnttab_alloc_grant_references(RX_MAX_TARGET,
1970 &np->gref_rx_head) < 0) {
1971 printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
1972 err = -ENOMEM;
1973 goto exit_free_tx;
1976 netdev->open = network_open;
1977 netdev->hard_start_xmit = network_start_xmit;
1978 netdev->stop = network_close;
1979 netdev->get_stats = network_get_stats;
1980 netdev->poll = netif_poll;
1981 netdev->set_multicast_list = network_set_multicast_list;
1982 netdev->uninit = netif_uninit;
1983 netdev->change_mtu = xennet_change_mtu;
1984 netdev->weight = 64;
1985 netdev->features = NETIF_F_IP_CSUM;
1987 SET_ETHTOOL_OPS(netdev, &network_ethtool_ops);
1988 SET_MODULE_OWNER(netdev);
1989 SET_NETDEV_DEV(netdev, &dev->dev);
1991 np->netdev = netdev;
1993 netif_carrier_off(netdev);
1995 return netdev;
1997 exit_free_tx:
1998 gnttab_free_grant_references(np->gref_tx_head);
1999 exit:
2000 free_netdev(netdev);
2001 return ERR_PTR(err);
2004 /*
2005 * We use this notifier to send out a fake ARP reply to reset switches and
2006 * router ARP caches when an IP interface is brought up on a VIF.
2007 */
2008 static int
2009 inetdev_notify(struct notifier_block *this, unsigned long event, void *ptr)
2011 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2012 struct net_device *dev = ifa->ifa_dev->dev;
2014 /* UP event and is it one of our devices? */
2015 if (event == NETDEV_UP && dev->open == network_open)
2016 (void)send_fake_arp(dev);
2018 return NOTIFY_DONE;
2022 static void netif_disconnect_backend(struct netfront_info *info)
2024 /* Stop old i/f to prevent errors whilst we rebuild the state. */
2025 spin_lock_irq(&info->tx_lock);
2026 spin_lock(&info->rx_lock);
2027 netif_carrier_off(info->netdev);
2028 spin_unlock(&info->rx_lock);
2029 spin_unlock_irq(&info->tx_lock);
2031 if (info->irq)
2032 unbind_from_irqhandler(info->irq, info->netdev);
2033 info->irq = 0;
2035 end_access(info->tx_ring_ref, info->tx.sring);
2036 end_access(info->rx_ring_ref, info->rx.sring);
2037 info->tx_ring_ref = GRANT_INVALID_REF;
2038 info->rx_ring_ref = GRANT_INVALID_REF;
2039 info->tx.sring = NULL;
2040 info->rx.sring = NULL;
2044 static void end_access(int ref, void *page)
2046 if (ref != GRANT_INVALID_REF)
2047 gnttab_end_foreign_access(ref, 0, (unsigned long)page);
2051 /* ** Driver registration ** */
2054 static struct xenbus_device_id netfront_ids[] = {
2055 { "vif" },
2056 { "" }
2057 };
2060 static struct xenbus_driver netfront = {
2061 .name = "vif",
2062 .owner = THIS_MODULE,
2063 .ids = netfront_ids,
2064 .probe = netfront_probe,
2065 .remove = __devexit_p(netfront_remove),
2066 .resume = netfront_resume,
2067 .otherend_changed = backend_changed,
2068 };
2071 static struct notifier_block notifier_inetdev = {
2072 .notifier_call = inetdev_notify,
2073 .next = NULL,
2074 .priority = 0
2075 };
2077 static int __init netif_init(void)
2079 if (!is_running_on_xen())
2080 return -ENODEV;
2082 #ifdef CONFIG_XEN
2083 if (MODPARM_rx_flip && MODPARM_rx_copy) {
2084 WPRINTK("Cannot specify both rx_copy and rx_flip.\n");
2085 return -EINVAL;
2088 if (!MODPARM_rx_flip && !MODPARM_rx_copy)
2089 MODPARM_rx_flip = 1; /* Default is to flip. */
2090 #endif
2092 if (is_initial_xendomain())
2093 return 0;
2095 IPRINTK("Initialising virtual ethernet driver.\n");
2097 (void)register_inetaddr_notifier(&notifier_inetdev);
2099 return xenbus_register_frontend(&netfront);
2101 module_init(netif_init);
2104 static void __exit netif_exit(void)
2106 if (is_initial_xendomain())
2107 return;
2109 unregister_inetaddr_notifier(&notifier_inetdev);
2111 return xenbus_unregister_driver(&netfront);
2113 module_exit(netif_exit);
2115 MODULE_LICENSE("Dual BSD/GPL");