ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c @ 11800:d2f13c8b0819

[NET] front: No need to read handle field from xenstore. It's not used.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Oct 13 17:07:39 2006 +0100 (2006-10-13)
parents fe54ba10e9ef
children 7da100019e00
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 /*
68 * Mutually-exclusive module options to select receive data path:
69 * rx_copy : Packets are copied by network backend into local memory
70 * rx_flip : Page containing packet data is transferred to our ownership
71 * For fully-virtualised guests there is no option - copying must be used.
72 * For paravirtualised guests, flipping is the default.
73 */
74 #ifdef CONFIG_XEN
75 static int MODPARM_rx_copy = 0;
76 module_param_named(rx_copy, MODPARM_rx_copy, bool, 0);
77 MODULE_PARM_DESC(rx_copy, "Copy packets from network card (rather than flip)");
78 static int MODPARM_rx_flip = 0;
79 module_param_named(rx_flip, MODPARM_rx_flip, bool, 0);
80 MODULE_PARM_DESC(rx_flip, "Flip packets from network card (rather than copy)");
81 #else
82 static const int MODPARM_rx_copy = 1;
83 static const int MODPARM_rx_flip = 0;
84 #endif
86 #define RX_COPY_THRESHOLD 256
88 /* If we don't have GSO, fake things up so that we never try to use it. */
89 #if defined(NETIF_F_GSO)
90 #define HAVE_GSO 1
91 #define HAVE_TSO 1 /* TSO is a subset of GSO */
92 static inline void dev_disable_gso_features(struct net_device *dev)
93 {
94 /* Turn off all GSO bits except ROBUST. */
95 dev->features &= (1 << NETIF_F_GSO_SHIFT) - 1;
96 dev->features |= NETIF_F_GSO_ROBUST;
97 }
98 #elif defined(NETIF_F_TSO)
99 #define HAVE_TSO 1
100 #define gso_size tso_size
101 #define gso_segs tso_segs
102 static inline void dev_disable_gso_features(struct net_device *dev)
103 {
104 /* Turn off all TSO bits. */
105 dev->features &= ~NETIF_F_TSO;
106 }
107 static inline int skb_is_gso(const struct sk_buff *skb)
108 {
109 return skb_shinfo(skb)->tso_size;
110 }
111 static inline int skb_gso_ok(struct sk_buff *skb, int features)
112 {
113 return (features & NETIF_F_TSO);
114 }
116 static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb)
117 {
118 return skb_is_gso(skb) &&
119 (!skb_gso_ok(skb, dev->features) ||
120 unlikely(skb->ip_summed != CHECKSUM_HW));
121 }
122 #else
123 #define netif_needs_gso(dev, skb) 0
124 #define dev_disable_gso_features(dev) ((void)0)
125 #endif
127 #define GRANT_INVALID_REF 0
129 #define NET_TX_RING_SIZE __RING_SIZE((struct netif_tx_sring *)0, PAGE_SIZE)
130 #define NET_RX_RING_SIZE __RING_SIZE((struct netif_rx_sring *)0, PAGE_SIZE)
132 struct netfront_info {
133 struct list_head list;
134 struct net_device *netdev;
136 struct net_device_stats stats;
138 struct netif_tx_front_ring tx;
139 struct netif_rx_front_ring rx;
141 spinlock_t tx_lock;
142 spinlock_t rx_lock;
144 unsigned int evtchn, irq;
145 unsigned int copying_receiver;
147 /* Receive-ring batched refills. */
148 #define RX_MIN_TARGET 8
149 #define RX_DFL_MIN_TARGET 64
150 #define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
151 unsigned rx_min_target, rx_max_target, rx_target;
152 struct sk_buff_head rx_batch;
154 struct timer_list rx_refill_timer;
156 /*
157 * {tx,rx}_skbs store outstanding skbuffs. The first entry in tx_skbs
158 * is an index into a chain of free entries.
159 */
160 struct sk_buff *tx_skbs[NET_TX_RING_SIZE+1];
161 struct sk_buff *rx_skbs[NET_RX_RING_SIZE];
163 #define TX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
164 grant_ref_t gref_tx_head;
165 grant_ref_t grant_tx_ref[NET_TX_RING_SIZE + 1];
166 grant_ref_t gref_rx_head;
167 grant_ref_t grant_rx_ref[NET_RX_RING_SIZE];
169 struct xenbus_device *xbdev;
170 int tx_ring_ref;
171 int rx_ring_ref;
172 u8 mac[ETH_ALEN];
174 unsigned long rx_pfn_array[NET_RX_RING_SIZE];
175 struct multicall_entry rx_mcl[NET_RX_RING_SIZE+1];
176 struct mmu_update rx_mmu[NET_RX_RING_SIZE];
177 };
179 struct netfront_rx_info {
180 struct netif_rx_response rx;
181 struct netif_extra_info extras[XEN_NETIF_EXTRA_TYPE_MAX - 1];
182 };
184 /*
185 * Access macros for acquiring freeing slots in tx_skbs[].
186 */
188 static inline void add_id_to_freelist(struct sk_buff **list, unsigned short id)
189 {
190 list[id] = list[0];
191 list[0] = (void *)(unsigned long)id;
192 }
194 static inline unsigned short get_id_from_freelist(struct sk_buff **list)
195 {
196 unsigned int id = (unsigned int)(unsigned long)list[0];
197 list[0] = list[id];
198 return id;
199 }
201 static inline int xennet_rxidx(RING_IDX idx)
202 {
203 return idx & (NET_RX_RING_SIZE - 1);
204 }
206 static inline struct sk_buff *xennet_get_rx_skb(struct netfront_info *np,
207 RING_IDX ri)
208 {
209 int i = xennet_rxidx(ri);
210 struct sk_buff *skb = np->rx_skbs[i];
211 np->rx_skbs[i] = NULL;
212 return skb;
213 }
215 static inline grant_ref_t xennet_get_rx_ref(struct netfront_info *np,
216 RING_IDX ri)
217 {
218 int i = xennet_rxidx(ri);
219 grant_ref_t ref = np->grant_rx_ref[i];
220 np->grant_rx_ref[i] = GRANT_INVALID_REF;
221 return ref;
222 }
224 #define DPRINTK(fmt, args...) \
225 pr_debug("netfront (%s:%d) " fmt, \
226 __FUNCTION__, __LINE__, ##args)
227 #define IPRINTK(fmt, args...) \
228 printk(KERN_INFO "netfront: " fmt, ##args)
229 #define WPRINTK(fmt, args...) \
230 printk(KERN_WARNING "netfront: " fmt, ##args)
232 static int talk_to_backend(struct xenbus_device *, struct netfront_info *);
233 static int setup_device(struct xenbus_device *, struct netfront_info *);
234 static struct net_device *create_netdev(int, struct xenbus_device *);
236 static void netfront_closing(struct xenbus_device *);
238 static void end_access(int, void *);
239 static void netif_disconnect_backend(struct netfront_info *);
240 static int open_netdev(struct netfront_info *);
241 static void close_netdev(struct netfront_info *);
242 static void netif_free(struct netfront_info *);
244 static void network_connect(struct net_device *);
245 static void network_tx_buf_gc(struct net_device *);
246 static void network_alloc_rx_buffers(struct net_device *);
247 static int send_fake_arp(struct net_device *);
249 static irqreturn_t netif_int(int irq, void *dev_id, struct pt_regs *ptregs);
251 #ifdef CONFIG_SYSFS
252 static int xennet_sysfs_addif(struct net_device *netdev);
253 static void xennet_sysfs_delif(struct net_device *netdev);
254 #else /* !CONFIG_SYSFS */
255 #define xennet_sysfs_addif(dev) (0)
256 #define xennet_sysfs_delif(dev) do { } while(0)
257 #endif
259 static inline int xennet_can_sg(struct net_device *dev)
260 {
261 return dev->features & NETIF_F_SG;
262 }
264 /**
265 * Entry point to this code when a new device is created. Allocate the basic
266 * structures and the ring buffers for communication with the backend, and
267 * inform the backend of the appropriate details for those. Switch to
268 * Connected state.
269 */
270 static int __devinit netfront_probe(struct xenbus_device *dev,
271 const struct xenbus_device_id *id)
272 {
273 int err;
274 struct net_device *netdev;
275 struct netfront_info *info;
276 unsigned int feature_rx_copy, feature_rx_flip, use_copy;
278 err = xenbus_scanf(XBT_NIL, dev->otherend, "feature-rx-copy", "%u",
279 &feature_rx_copy);
280 if (err != 1)
281 feature_rx_copy = 0;
282 err = xenbus_scanf(XBT_NIL, dev->otherend, "feature-rx-flip", "%u",
283 &feature_rx_flip);
284 if (err != 1)
285 feature_rx_flip = 1;
287 /*
288 * Copy packets on receive path if:
289 * (a) This was requested by user, and the backend supports it; or
290 * (b) Flipping was requested, but this is unsupported by the backend.
291 */
292 use_copy = (MODPARM_rx_copy && feature_rx_copy) ||
293 (MODPARM_rx_flip && !feature_rx_flip);
295 netdev = create_netdev(use_copy, dev);
296 if (IS_ERR(netdev)) {
297 err = PTR_ERR(netdev);
298 xenbus_dev_fatal(dev, err, "creating netdev");
299 return err;
300 }
302 info = netdev_priv(netdev);
303 dev->dev.driver_data = info;
305 err = talk_to_backend(dev, info);
306 if (err)
307 goto fail_backend;
309 err = open_netdev(info);
310 if (err)
311 goto fail_open;
313 IPRINTK("Created netdev %s with %sing receive path.\n",
314 netdev->name, info->copying_receiver ? "copy" : "flipp");
316 return 0;
318 fail_open:
319 xennet_sysfs_delif(info->netdev);
320 unregister_netdev(netdev);
321 fail_backend:
322 free_netdev(netdev);
323 dev->dev.driver_data = NULL;
324 return err;
325 }
328 /**
329 * We are reconnecting to the backend, due to a suspend/resume, or a backend
330 * driver restart. We tear down our netif structure and recreate it, but
331 * leave the device-layer structures intact so that this is transparent to the
332 * rest of the kernel.
333 */
334 static int netfront_resume(struct xenbus_device *dev)
335 {
336 struct netfront_info *info = dev->dev.driver_data;
338 DPRINTK("%s\n", dev->nodename);
340 netif_disconnect_backend(info);
341 return talk_to_backend(dev, info);
342 }
344 static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
345 {
346 char *s, *e, *macstr;
347 int i;
349 macstr = s = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL);
350 if (IS_ERR(macstr))
351 return PTR_ERR(macstr);
353 for (i = 0; i < ETH_ALEN; i++) {
354 mac[i] = simple_strtoul(s, &e, 16);
355 if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) {
356 kfree(macstr);
357 return -ENOENT;
358 }
359 s = e+1;
360 }
362 kfree(macstr);
363 return 0;
364 }
366 /* Common code used when first setting up, and when resuming. */
367 static int talk_to_backend(struct xenbus_device *dev,
368 struct netfront_info *info)
369 {
370 const char *message;
371 struct xenbus_transaction xbt;
372 int err;
374 err = xen_net_read_mac(dev, info->mac);
375 if (err) {
376 xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
377 goto out;
378 }
380 /* Create shared ring, alloc event channel. */
381 err = setup_device(dev, info);
382 if (err)
383 goto out;
385 again:
386 err = xenbus_transaction_start(&xbt);
387 if (err) {
388 xenbus_dev_fatal(dev, err, "starting transaction");
389 goto destroy_ring;
390 }
392 err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref","%u",
393 info->tx_ring_ref);
394 if (err) {
395 message = "writing tx ring-ref";
396 goto abort_transaction;
397 }
398 err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref","%u",
399 info->rx_ring_ref);
400 if (err) {
401 message = "writing rx ring-ref";
402 goto abort_transaction;
403 }
404 err = xenbus_printf(xbt, dev->nodename,
405 "event-channel", "%u", info->evtchn);
406 if (err) {
407 message = "writing event-channel";
408 goto abort_transaction;
409 }
411 err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
412 info->copying_receiver);
413 if (err) {
414 message = "writing request-rx-copy";
415 goto abort_transaction;
416 }
418 err = xenbus_printf(xbt, dev->nodename, "feature-rx-notify", "%d", 1);
419 if (err) {
420 message = "writing feature-rx-notify";
421 goto abort_transaction;
422 }
424 err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", 1);
425 if (err) {
426 message = "writing feature-sg";
427 goto abort_transaction;
428 }
430 #ifdef HAVE_TSO
431 err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d", 1);
432 if (err) {
433 message = "writing feature-gso-tcpv4";
434 goto abort_transaction;
435 }
436 #endif
438 err = xenbus_transaction_end(xbt, 0);
439 if (err) {
440 if (err == -EAGAIN)
441 goto again;
442 xenbus_dev_fatal(dev, err, "completing transaction");
443 goto destroy_ring;
444 }
446 return 0;
448 abort_transaction:
449 xenbus_transaction_end(xbt, 1);
450 xenbus_dev_fatal(dev, err, "%s", message);
451 destroy_ring:
452 netif_free(info);
453 out:
454 return err;
455 }
458 static int setup_device(struct xenbus_device *dev, struct netfront_info *info)
459 {
460 struct netif_tx_sring *txs;
461 struct netif_rx_sring *rxs;
462 int err;
463 struct net_device *netdev = info->netdev;
465 info->tx_ring_ref = GRANT_INVALID_REF;
466 info->rx_ring_ref = GRANT_INVALID_REF;
467 info->rx.sring = NULL;
468 info->tx.sring = NULL;
469 info->irq = 0;
471 txs = (struct netif_tx_sring *)get_zeroed_page(GFP_KERNEL);
472 if (!txs) {
473 err = -ENOMEM;
474 xenbus_dev_fatal(dev, err, "allocating tx ring page");
475 goto fail;
476 }
477 SHARED_RING_INIT(txs);
478 FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
480 err = xenbus_grant_ring(dev, virt_to_mfn(txs));
481 if (err < 0) {
482 free_page((unsigned long)txs);
483 goto fail;
484 }
485 info->tx_ring_ref = err;
487 rxs = (struct netif_rx_sring *)get_zeroed_page(GFP_KERNEL);
488 if (!rxs) {
489 err = -ENOMEM;
490 xenbus_dev_fatal(dev, err, "allocating rx ring page");
491 goto fail;
492 }
493 SHARED_RING_INIT(rxs);
494 FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
496 err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
497 if (err < 0) {
498 free_page((unsigned long)rxs);
499 goto fail;
500 }
501 info->rx_ring_ref = err;
503 err = xenbus_alloc_evtchn(dev, &info->evtchn);
504 if (err)
505 goto fail;
507 memcpy(netdev->dev_addr, info->mac, ETH_ALEN);
508 err = bind_evtchn_to_irqhandler(info->evtchn, netif_int,
509 SA_SAMPLE_RANDOM, netdev->name,
510 netdev);
511 if (err < 0)
512 goto fail;
513 info->irq = err;
514 return 0;
516 fail:
517 netif_free(info);
518 return err;
519 }
522 /**
523 * Callback received when the backend's state changes.
524 */
525 static void backend_changed(struct xenbus_device *dev,
526 enum xenbus_state backend_state)
527 {
528 struct netfront_info *np = dev->dev.driver_data;
529 struct net_device *netdev = np->netdev;
531 DPRINTK("%s\n", xenbus_strstate(backend_state));
533 switch (backend_state) {
534 case XenbusStateInitialising:
535 case XenbusStateInitialised:
536 case XenbusStateConnected:
537 case XenbusStateUnknown:
538 case XenbusStateClosed:
539 break;
541 case XenbusStateInitWait:
542 network_connect(netdev);
543 xenbus_switch_state(dev, XenbusStateConnected);
544 (void)send_fake_arp(netdev);
545 break;
547 case XenbusStateClosing:
548 netfront_closing(dev);
549 break;
550 }
551 }
554 /** Send a packet on a net device to encourage switches to learn the
555 * MAC. We send a fake ARP request.
556 *
557 * @param dev device
558 * @return 0 on success, error code otherwise
559 */
560 static int send_fake_arp(struct net_device *dev)
561 {
562 struct sk_buff *skb;
563 u32 src_ip, dst_ip;
565 dst_ip = INADDR_BROADCAST;
566 src_ip = inet_select_addr(dev, dst_ip, RT_SCOPE_LINK);
568 /* No IP? Then nothing to do. */
569 if (src_ip == 0)
570 return 0;
572 skb = arp_create(ARPOP_REPLY, ETH_P_ARP,
573 dst_ip, dev, src_ip,
574 /*dst_hw*/ NULL, /*src_hw*/ NULL,
575 /*target_hw*/ dev->dev_addr);
576 if (skb == NULL)
577 return -ENOMEM;
579 return dev_queue_xmit(skb);
580 }
583 static int network_open(struct net_device *dev)
584 {
585 struct netfront_info *np = netdev_priv(dev);
587 memset(&np->stats, 0, sizeof(np->stats));
589 spin_lock(&np->rx_lock);
590 if (netif_carrier_ok(dev)) {
591 network_alloc_rx_buffers(dev);
592 np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
593 if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
594 netif_rx_schedule(dev);
595 }
596 spin_unlock(&np->rx_lock);
598 netif_start_queue(dev);
600 return 0;
601 }
603 static inline int netfront_tx_slot_available(struct netfront_info *np)
604 {
605 return RING_FREE_REQUESTS(&np->tx) >= MAX_SKB_FRAGS + 2;
606 }
608 static inline void network_maybe_wake_tx(struct net_device *dev)
609 {
610 struct netfront_info *np = netdev_priv(dev);
612 if (unlikely(netif_queue_stopped(dev)) &&
613 netfront_tx_slot_available(np) &&
614 likely(netif_running(dev)))
615 netif_wake_queue(dev);
616 }
618 static void network_tx_buf_gc(struct net_device *dev)
619 {
620 RING_IDX cons, prod;
621 unsigned short id;
622 struct netfront_info *np = netdev_priv(dev);
623 struct sk_buff *skb;
625 BUG_ON(!netif_carrier_ok(dev));
627 do {
628 prod = np->tx.sring->rsp_prod;
629 rmb(); /* Ensure we see responses up to 'rp'. */
631 for (cons = np->tx.rsp_cons; cons != prod; cons++) {
632 struct netif_tx_response *txrsp;
634 txrsp = RING_GET_RESPONSE(&np->tx, cons);
635 if (txrsp->status == NETIF_RSP_NULL)
636 continue;
638 id = txrsp->id;
639 skb = np->tx_skbs[id];
640 if (unlikely(gnttab_query_foreign_access(
641 np->grant_tx_ref[id]) != 0)) {
642 printk(KERN_ALERT "network_tx_buf_gc: warning "
643 "-- grant still in use by backend "
644 "domain.\n");
645 BUG();
646 }
647 gnttab_end_foreign_access_ref(
648 np->grant_tx_ref[id], GNTMAP_readonly);
649 gnttab_release_grant_reference(
650 &np->gref_tx_head, np->grant_tx_ref[id]);
651 np->grant_tx_ref[id] = GRANT_INVALID_REF;
652 add_id_to_freelist(np->tx_skbs, id);
653 dev_kfree_skb_irq(skb);
654 }
656 np->tx.rsp_cons = prod;
658 /*
659 * Set a new event, then check for race with update of tx_cons.
660 * Note that it is essential to schedule a callback, no matter
661 * how few buffers are pending. Even if there is space in the
662 * transmit ring, higher layers may be blocked because too much
663 * data is outstanding: in such cases notification from Xen is
664 * likely to be the only kick that we'll get.
665 */
666 np->tx.sring->rsp_event =
667 prod + ((np->tx.sring->req_prod - prod) >> 1) + 1;
668 mb();
669 } while ((cons == prod) && (prod != np->tx.sring->rsp_prod));
671 network_maybe_wake_tx(dev);
672 }
675 static void rx_refill_timeout(unsigned long data)
676 {
677 struct net_device *dev = (struct net_device *)data;
678 netif_rx_schedule(dev);
679 }
682 static void network_alloc_rx_buffers(struct net_device *dev)
683 {
684 unsigned short id;
685 struct netfront_info *np = netdev_priv(dev);
686 struct sk_buff *skb;
687 struct page *page;
688 int i, batch_target, notify;
689 RING_IDX req_prod = np->rx.req_prod_pvt;
690 struct xen_memory_reservation reservation;
691 grant_ref_t ref;
692 unsigned long pfn;
693 void *vaddr;
694 int nr_flips;
695 netif_rx_request_t *req;
697 if (unlikely(!netif_carrier_ok(dev)))
698 return;
700 /*
701 * Allocate skbuffs greedily, even though we batch updates to the
702 * receive ring. This creates a less bursty demand on the memory
703 * allocator, so should reduce the chance of failed allocation requests
704 * both for ourself and for other kernel subsystems.
705 */
706 batch_target = np->rx_target - (req_prod - np->rx.rsp_cons);
707 for (i = skb_queue_len(&np->rx_batch); i < batch_target; i++) {
708 /*
709 * Allocate an skb and a page. Do not use __dev_alloc_skb as
710 * that will allocate page-sized buffers which is not
711 * necessary here.
712 * 16 bytes added as necessary headroom for netif_receive_skb.
713 */
714 skb = alloc_skb(RX_COPY_THRESHOLD + 16,
715 GFP_ATOMIC | __GFP_NOWARN);
716 if (unlikely(!skb))
717 goto no_skb;
719 page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
720 if (!page) {
721 kfree_skb(skb);
722 no_skb:
723 /* Any skbuffs queued for refill? Force them out. */
724 if (i != 0)
725 goto refill;
726 /* Could not allocate any skbuffs. Try again later. */
727 mod_timer(&np->rx_refill_timer,
728 jiffies + (HZ/10));
729 break;
730 }
732 skb_reserve(skb, 16); /* mimic dev_alloc_skb() */
733 skb_shinfo(skb)->frags[0].page = page;
734 skb_shinfo(skb)->nr_frags = 1;
735 __skb_queue_tail(&np->rx_batch, skb);
736 }
738 /* Is the batch large enough to be worthwhile? */
739 if (i < (np->rx_target/2)) {
740 if (req_prod > np->rx.sring->req_prod)
741 goto push;
742 return;
743 }
745 /* Adjust our fill target if we risked running out of buffers. */
746 if (((req_prod - np->rx.sring->rsp_prod) < (np->rx_target / 4)) &&
747 ((np->rx_target *= 2) > np->rx_max_target))
748 np->rx_target = np->rx_max_target;
750 refill:
751 for (nr_flips = i = 0; ; i++) {
752 if ((skb = __skb_dequeue(&np->rx_batch)) == NULL)
753 break;
755 skb->dev = dev;
757 id = xennet_rxidx(req_prod + i);
759 BUG_ON(np->rx_skbs[id]);
760 np->rx_skbs[id] = skb;
762 ref = gnttab_claim_grant_reference(&np->gref_rx_head);
763 BUG_ON((signed short)ref < 0);
764 np->grant_rx_ref[id] = ref;
766 pfn = page_to_pfn(skb_shinfo(skb)->frags[0].page);
767 vaddr = page_address(skb_shinfo(skb)->frags[0].page);
769 req = RING_GET_REQUEST(&np->rx, req_prod + i);
770 if (!np->copying_receiver) {
771 gnttab_grant_foreign_transfer_ref(ref,
772 np->xbdev->otherend_id,
773 pfn);
774 np->rx_pfn_array[nr_flips] = pfn_to_mfn(pfn);
775 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
776 /* Remove this page before passing
777 * back to Xen. */
778 set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
779 MULTI_update_va_mapping(np->rx_mcl+i,
780 (unsigned long)vaddr,
781 __pte(0), 0);
782 }
783 nr_flips++;
784 } else {
785 gnttab_grant_foreign_access_ref(ref,
786 np->xbdev->otherend_id,
787 pfn_to_mfn(pfn),
788 0);
789 }
791 req->id = id;
792 req->gref = ref;
793 }
795 if ( nr_flips != 0 ) {
796 /* Tell the ballon driver what is going on. */
797 balloon_update_driver_allowance(i);
799 set_xen_guest_handle(reservation.extent_start,
800 np->rx_pfn_array);
801 reservation.nr_extents = nr_flips;
802 reservation.extent_order = 0;
803 reservation.address_bits = 0;
804 reservation.domid = DOMID_SELF;
806 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
807 /* After all PTEs have been zapped, flush the TLB. */
808 np->rx_mcl[i-1].args[MULTI_UVMFLAGS_INDEX] =
809 UVMF_TLB_FLUSH|UVMF_ALL;
811 /* Give away a batch of pages. */
812 np->rx_mcl[i].op = __HYPERVISOR_memory_op;
813 np->rx_mcl[i].args[0] = XENMEM_decrease_reservation;
814 np->rx_mcl[i].args[1] = (unsigned long)&reservation;
816 /* Zap PTEs and give away pages in one big
817 * multicall. */
818 (void)HYPERVISOR_multicall(np->rx_mcl, i+1);
820 /* Check return status of HYPERVISOR_memory_op(). */
821 if (unlikely(np->rx_mcl[i].result != i))
822 panic("Unable to reduce memory reservation\n");
823 } else {
824 if (HYPERVISOR_memory_op(XENMEM_decrease_reservation,
825 &reservation) != i)
826 panic("Unable to reduce memory reservation\n");
827 }
828 } else {
829 wmb();
830 }
832 /* Above is a suitable barrier to ensure backend will see requests. */
833 np->rx.req_prod_pvt = req_prod + i;
834 push:
835 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->rx, notify);
836 if (notify)
837 notify_remote_via_irq(np->irq);
838 }
840 static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
841 struct netif_tx_request *tx)
842 {
843 struct netfront_info *np = netdev_priv(dev);
844 char *data = skb->data;
845 unsigned long mfn;
846 RING_IDX prod = np->tx.req_prod_pvt;
847 int frags = skb_shinfo(skb)->nr_frags;
848 unsigned int offset = offset_in_page(data);
849 unsigned int len = skb_headlen(skb);
850 unsigned int id;
851 grant_ref_t ref;
852 int i;
854 while (len > PAGE_SIZE - offset) {
855 tx->size = PAGE_SIZE - offset;
856 tx->flags |= NETTXF_more_data;
857 len -= tx->size;
858 data += tx->size;
859 offset = 0;
861 id = get_id_from_freelist(np->tx_skbs);
862 np->tx_skbs[id] = skb_get(skb);
863 tx = RING_GET_REQUEST(&np->tx, prod++);
864 tx->id = id;
865 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
866 BUG_ON((signed short)ref < 0);
868 mfn = virt_to_mfn(data);
869 gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
870 mfn, GNTMAP_readonly);
872 tx->gref = np->grant_tx_ref[id] = ref;
873 tx->offset = offset;
874 tx->size = len;
875 tx->flags = 0;
876 }
878 for (i = 0; i < frags; i++) {
879 skb_frag_t *frag = skb_shinfo(skb)->frags + i;
881 tx->flags |= NETTXF_more_data;
883 id = get_id_from_freelist(np->tx_skbs);
884 np->tx_skbs[id] = skb_get(skb);
885 tx = RING_GET_REQUEST(&np->tx, prod++);
886 tx->id = id;
887 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
888 BUG_ON((signed short)ref < 0);
890 mfn = pfn_to_mfn(page_to_pfn(frag->page));
891 gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
892 mfn, GNTMAP_readonly);
894 tx->gref = np->grant_tx_ref[id] = ref;
895 tx->offset = frag->page_offset;
896 tx->size = frag->size;
897 tx->flags = 0;
898 }
900 np->tx.req_prod_pvt = prod;
901 }
903 static int network_start_xmit(struct sk_buff *skb, struct net_device *dev)
904 {
905 unsigned short id;
906 struct netfront_info *np = netdev_priv(dev);
907 struct netif_tx_request *tx;
908 struct netif_extra_info *extra;
909 char *data = skb->data;
910 RING_IDX i;
911 grant_ref_t ref;
912 unsigned long mfn;
913 int notify;
914 int frags = skb_shinfo(skb)->nr_frags;
915 unsigned int offset = offset_in_page(data);
916 unsigned int len = skb_headlen(skb);
918 frags += (offset + len + PAGE_SIZE - 1) / PAGE_SIZE;
919 if (unlikely(frags > MAX_SKB_FRAGS + 1)) {
920 printk(KERN_ALERT "xennet: skb rides the rocket: %d frags\n",
921 frags);
922 dump_stack();
923 goto drop;
924 }
926 spin_lock_irq(&np->tx_lock);
928 if (unlikely(!netif_carrier_ok(dev) ||
929 (frags > 1 && !xennet_can_sg(dev)) ||
930 netif_needs_gso(dev, skb))) {
931 spin_unlock_irq(&np->tx_lock);
932 goto drop;
933 }
935 i = np->tx.req_prod_pvt;
937 id = get_id_from_freelist(np->tx_skbs);
938 np->tx_skbs[id] = skb;
940 tx = RING_GET_REQUEST(&np->tx, i);
942 tx->id = id;
943 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
944 BUG_ON((signed short)ref < 0);
945 mfn = virt_to_mfn(data);
946 gnttab_grant_foreign_access_ref(
947 ref, np->xbdev->otherend_id, mfn, GNTMAP_readonly);
948 tx->gref = np->grant_tx_ref[id] = ref;
949 tx->offset = offset;
950 tx->size = len;
952 tx->flags = 0;
953 extra = NULL;
955 if (skb->ip_summed == CHECKSUM_HW) /* local packet? */
956 tx->flags |= NETTXF_csum_blank | NETTXF_data_validated;
957 #ifdef CONFIG_XEN
958 if (skb->proto_data_valid) /* remote but checksummed? */
959 tx->flags |= NETTXF_data_validated;
960 #endif
962 #ifdef HAVE_TSO
963 if (skb_shinfo(skb)->gso_size) {
964 struct netif_extra_info *gso = (struct netif_extra_info *)
965 RING_GET_REQUEST(&np->tx, ++i);
967 if (extra)
968 extra->flags |= XEN_NETIF_EXTRA_FLAG_MORE;
969 else
970 tx->flags |= NETTXF_extra_info;
972 gso->u.gso.size = skb_shinfo(skb)->gso_size;
973 gso->u.gso.type = XEN_NETIF_GSO_TYPE_TCPV4;
974 gso->u.gso.pad = 0;
975 gso->u.gso.features = 0;
977 gso->type = XEN_NETIF_EXTRA_TYPE_GSO;
978 gso->flags = 0;
979 extra = gso;
980 }
981 #endif
983 np->tx.req_prod_pvt = i + 1;
985 xennet_make_frags(skb, dev, tx);
986 tx->size = skb->len;
988 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->tx, notify);
989 if (notify)
990 notify_remote_via_irq(np->irq);
992 network_tx_buf_gc(dev);
994 if (!netfront_tx_slot_available(np))
995 netif_stop_queue(dev);
997 spin_unlock_irq(&np->tx_lock);
999 np->stats.tx_bytes += skb->len;
1000 np->stats.tx_packets++;
1002 return 0;
1004 drop:
1005 np->stats.tx_dropped++;
1006 dev_kfree_skb(skb);
1007 return 0;
1010 static irqreturn_t netif_int(int irq, void *dev_id, struct pt_regs *ptregs)
1012 struct net_device *dev = dev_id;
1013 struct netfront_info *np = netdev_priv(dev);
1014 unsigned long flags;
1016 spin_lock_irqsave(&np->tx_lock, flags);
1018 if (likely(netif_carrier_ok(dev))) {
1019 network_tx_buf_gc(dev);
1020 /* Under tx_lock: protects access to rx shared-ring indexes. */
1021 if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
1022 netif_rx_schedule(dev);
1025 spin_unlock_irqrestore(&np->tx_lock, flags);
1027 return IRQ_HANDLED;
1030 static void xennet_move_rx_slot(struct netfront_info *np, struct sk_buff *skb,
1031 grant_ref_t ref)
1033 int new = xennet_rxidx(np->rx.req_prod_pvt);
1035 BUG_ON(np->rx_skbs[new]);
1036 np->rx_skbs[new] = skb;
1037 np->grant_rx_ref[new] = ref;
1038 RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->id = new;
1039 RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->gref = ref;
1040 np->rx.req_prod_pvt++;
1043 int xennet_get_extras(struct netfront_info *np,
1044 struct netif_extra_info *extras, RING_IDX rp)
1047 struct netif_extra_info *extra;
1048 RING_IDX cons = np->rx.rsp_cons;
1049 int err = 0;
1051 do {
1052 struct sk_buff *skb;
1053 grant_ref_t ref;
1055 if (unlikely(cons + 1 == rp)) {
1056 if (net_ratelimit())
1057 WPRINTK("Missing extra info\n");
1058 err = -EBADR;
1059 break;
1062 extra = (struct netif_extra_info *)
1063 RING_GET_RESPONSE(&np->rx, ++cons);
1065 if (unlikely(!extra->type ||
1066 extra->type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
1067 if (net_ratelimit())
1068 WPRINTK("Invalid extra type: %d\n",
1069 extra->type);
1070 err = -EINVAL;
1071 } else {
1072 memcpy(&extras[extra->type - 1], extra,
1073 sizeof(*extra));
1076 skb = xennet_get_rx_skb(np, cons);
1077 ref = xennet_get_rx_ref(np, cons);
1078 xennet_move_rx_slot(np, skb, ref);
1079 } while (extra->flags & XEN_NETIF_EXTRA_FLAG_MORE);
1081 np->rx.rsp_cons = cons;
1082 return err;
1085 static int xennet_get_responses(struct netfront_info *np,
1086 struct netfront_rx_info *rinfo, RING_IDX rp,
1087 struct sk_buff_head *list,
1088 int *pages_flipped_p)
1090 int pages_flipped = *pages_flipped_p;
1091 struct mmu_update *mmu;
1092 struct multicall_entry *mcl;
1093 struct netif_rx_response *rx = &rinfo->rx;
1094 struct netif_extra_info *extras = rinfo->extras;
1095 RING_IDX cons = np->rx.rsp_cons;
1096 struct sk_buff *skb = xennet_get_rx_skb(np, cons);
1097 grant_ref_t ref = xennet_get_rx_ref(np, cons);
1098 int max = MAX_SKB_FRAGS + (rx->status <= RX_COPY_THRESHOLD);
1099 int frags = 1;
1100 int err = 0;
1101 unsigned long ret;
1103 if (rx->flags & NETRXF_extra_info) {
1104 err = xennet_get_extras(np, extras, rp);
1105 cons = np->rx.rsp_cons;
1108 for (;;) {
1109 unsigned long mfn;
1111 if (unlikely(rx->status < 0 ||
1112 rx->offset + rx->status > PAGE_SIZE)) {
1113 if (net_ratelimit())
1114 WPRINTK("rx->offset: %x, size: %u\n",
1115 rx->offset, rx->status);
1116 xennet_move_rx_slot(np, skb, ref);
1117 err = -EINVAL;
1118 goto next;
1121 /*
1122 * This definitely indicates a bug, either in this driver or in
1123 * the backend driver. In future this should flag the bad
1124 * situation to the system controller to reboot the backed.
1125 */
1126 if (ref == GRANT_INVALID_REF) {
1127 if (net_ratelimit())
1128 WPRINTK("Bad rx response id %d.\n", rx->id);
1129 err = -EINVAL;
1130 goto next;
1133 if (!np->copying_receiver) {
1134 /* Memory pressure, insufficient buffer
1135 * headroom, ... */
1136 if (!(mfn = gnttab_end_foreign_transfer_ref(ref))) {
1137 if (net_ratelimit())
1138 WPRINTK("Unfulfilled rx req "
1139 "(id=%d, st=%d).\n",
1140 rx->id, rx->status);
1141 xennet_move_rx_slot(np, skb, ref);
1142 err = -ENOMEM;
1143 goto next;
1146 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1147 /* Remap the page. */
1148 struct page *page =
1149 skb_shinfo(skb)->frags[0].page;
1150 unsigned long pfn = page_to_pfn(page);
1151 void *vaddr = page_address(page);
1153 mcl = np->rx_mcl + pages_flipped;
1154 mmu = np->rx_mmu + pages_flipped;
1156 MULTI_update_va_mapping(mcl,
1157 (unsigned long)vaddr,
1158 pfn_pte_ma(mfn,
1159 PAGE_KERNEL),
1160 0);
1161 mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
1162 | MMU_MACHPHYS_UPDATE;
1163 mmu->val = pfn;
1165 set_phys_to_machine(pfn, mfn);
1167 pages_flipped++;
1168 } else {
1169 ret = gnttab_end_foreign_access_ref(ref, 0);
1170 BUG_ON(!ret);
1173 gnttab_release_grant_reference(&np->gref_rx_head, ref);
1175 __skb_queue_tail(list, skb);
1177 next:
1178 if (!(rx->flags & NETRXF_more_data))
1179 break;
1181 if (cons + frags == rp) {
1182 if (net_ratelimit())
1183 WPRINTK("Need more frags\n");
1184 err = -ENOENT;
1185 break;
1188 rx = RING_GET_RESPONSE(&np->rx, cons + frags);
1189 skb = xennet_get_rx_skb(np, cons + frags);
1190 ref = xennet_get_rx_ref(np, cons + frags);
1191 frags++;
1194 if (unlikely(frags > max)) {
1195 if (net_ratelimit())
1196 WPRINTK("Too many frags\n");
1197 err = -E2BIG;
1200 if (unlikely(err))
1201 np->rx.rsp_cons = cons + frags;
1203 *pages_flipped_p = pages_flipped;
1205 return err;
1208 static RING_IDX xennet_fill_frags(struct netfront_info *np,
1209 struct sk_buff *skb,
1210 struct sk_buff_head *list)
1212 struct skb_shared_info *shinfo = skb_shinfo(skb);
1213 int nr_frags = shinfo->nr_frags;
1214 RING_IDX cons = np->rx.rsp_cons;
1215 skb_frag_t *frag = shinfo->frags + nr_frags;
1216 struct sk_buff *nskb;
1218 while ((nskb = __skb_dequeue(list))) {
1219 struct netif_rx_response *rx =
1220 RING_GET_RESPONSE(&np->rx, ++cons);
1222 frag->page = skb_shinfo(nskb)->frags[0].page;
1223 frag->page_offset = rx->offset;
1224 frag->size = rx->status;
1226 skb->data_len += rx->status;
1228 skb_shinfo(nskb)->nr_frags = 0;
1229 kfree_skb(nskb);
1231 frag++;
1232 nr_frags++;
1235 shinfo->nr_frags = nr_frags;
1236 return cons;
1239 static int xennet_set_skb_gso(struct sk_buff *skb,
1240 struct netif_extra_info *gso)
1242 if (!gso->u.gso.size) {
1243 if (net_ratelimit())
1244 WPRINTK("GSO size must not be zero.\n");
1245 return -EINVAL;
1248 /* Currently only TCPv4 S.O. is supported. */
1249 if (gso->u.gso.type != XEN_NETIF_GSO_TYPE_TCPV4) {
1250 if (net_ratelimit())
1251 WPRINTK("Bad GSO type %d.\n", gso->u.gso.type);
1252 return -EINVAL;
1255 #ifdef HAVE_TSO
1256 skb_shinfo(skb)->gso_size = gso->u.gso.size;
1257 #ifdef HAVE_GSO
1258 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1260 /* Header must be checked, and gso_segs computed. */
1261 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
1262 #endif
1263 skb_shinfo(skb)->gso_segs = 0;
1265 return 0;
1266 #else
1267 if (net_ratelimit())
1268 WPRINTK("GSO unsupported by this kernel.\n");
1269 return -EINVAL;
1270 #endif
1273 static int netif_poll(struct net_device *dev, int *pbudget)
1275 struct netfront_info *np = netdev_priv(dev);
1276 struct sk_buff *skb;
1277 struct netfront_rx_info rinfo;
1278 struct netif_rx_response *rx = &rinfo.rx;
1279 struct netif_extra_info *extras = rinfo.extras;
1280 RING_IDX i, rp;
1281 struct multicall_entry *mcl;
1282 int work_done, budget, more_to_do = 1;
1283 struct sk_buff_head rxq;
1284 struct sk_buff_head errq;
1285 struct sk_buff_head tmpq;
1286 unsigned long flags;
1287 unsigned int len;
1288 int pages_flipped = 0;
1289 int err;
1291 spin_lock(&np->rx_lock);
1293 if (unlikely(!netif_carrier_ok(dev))) {
1294 spin_unlock(&np->rx_lock);
1295 return 0;
1298 skb_queue_head_init(&rxq);
1299 skb_queue_head_init(&errq);
1300 skb_queue_head_init(&tmpq);
1302 if ((budget = *pbudget) > dev->quota)
1303 budget = dev->quota;
1304 rp = np->rx.sring->rsp_prod;
1305 rmb(); /* Ensure we see queued responses up to 'rp'. */
1307 i = np->rx.rsp_cons;
1308 work_done = 0;
1309 while ((i != rp) && (work_done < budget)) {
1310 memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx));
1311 memset(extras, 0, sizeof(extras));
1313 err = xennet_get_responses(np, &rinfo, rp, &tmpq,
1314 &pages_flipped);
1316 if (unlikely(err)) {
1317 err:
1318 while ((skb = __skb_dequeue(&tmpq)))
1319 __skb_queue_tail(&errq, skb);
1320 np->stats.rx_errors++;
1321 i = np->rx.rsp_cons;
1322 continue;
1325 skb = __skb_dequeue(&tmpq);
1327 if (extras[XEN_NETIF_EXTRA_TYPE_GSO - 1].type) {
1328 struct netif_extra_info *gso;
1329 gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO - 1];
1331 if (unlikely(xennet_set_skb_gso(skb, gso))) {
1332 __skb_queue_head(&tmpq, skb);
1333 np->rx.rsp_cons += skb_queue_len(&tmpq);
1334 goto err;
1338 skb->nh.raw = (void *)skb_shinfo(skb)->frags[0].page;
1339 skb->h.raw = skb->nh.raw + rx->offset;
1341 len = rx->status;
1342 if (len > RX_COPY_THRESHOLD)
1343 len = RX_COPY_THRESHOLD;
1344 skb_put(skb, len);
1346 if (rx->status > len) {
1347 skb_shinfo(skb)->frags[0].page_offset =
1348 rx->offset + len;
1349 skb_shinfo(skb)->frags[0].size = rx->status - len;
1350 skb->data_len = rx->status - len;
1351 } else {
1352 skb_shinfo(skb)->frags[0].page = NULL;
1353 skb_shinfo(skb)->nr_frags = 0;
1356 i = xennet_fill_frags(np, skb, &tmpq);
1358 /*
1359 * Truesize must approximates the size of true data plus
1360 * any supervisor overheads. Adding hypervisor overheads
1361 * has been shown to significantly reduce achievable
1362 * bandwidth with the default receive buffer size. It is
1363 * therefore not wise to account for it here.
1365 * After alloc_skb(RX_COPY_THRESHOLD), truesize is set to
1366 * RX_COPY_THRESHOLD + the supervisor overheads. Here, we
1367 * add the size of the data pulled in xennet_fill_frags().
1369 * We also adjust for any unused space in the main data
1370 * area by subtracting (RX_COPY_THRESHOLD - len). This is
1371 * especially important with drivers which split incoming
1372 * packets into header and data, using only 66 bytes of
1373 * the main data area (see the e1000 driver for example.)
1374 * On such systems, without this last adjustement, our
1375 * achievable receive throughout using the standard receive
1376 * buffer size was cut by 25%(!!!).
1377 */
1378 skb->truesize += skb->data_len - (RX_COPY_THRESHOLD - len);
1379 skb->len += skb->data_len;
1381 /*
1382 * Old backends do not assert data_validated but we
1383 * can infer it from csum_blank so test both flags.
1384 */
1385 if (rx->flags & (NETRXF_data_validated|NETRXF_csum_blank))
1386 skb->ip_summed = CHECKSUM_UNNECESSARY;
1387 else
1388 skb->ip_summed = CHECKSUM_NONE;
1389 #ifdef CONFIG_XEN
1390 skb->proto_data_valid = (skb->ip_summed != CHECKSUM_NONE);
1391 skb->proto_csum_blank = !!(rx->flags & NETRXF_csum_blank);
1392 #endif
1393 np->stats.rx_packets++;
1394 np->stats.rx_bytes += skb->len;
1396 __skb_queue_tail(&rxq, skb);
1398 np->rx.rsp_cons = ++i;
1399 work_done++;
1402 if (pages_flipped) {
1403 /* Some pages are no longer absent... */
1404 balloon_update_driver_allowance(-pages_flipped);
1406 /* Do all the remapping work and M2P updates. */
1407 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1408 mcl = np->rx_mcl + pages_flipped;
1409 mcl->op = __HYPERVISOR_mmu_update;
1410 mcl->args[0] = (unsigned long)np->rx_mmu;
1411 mcl->args[1] = pages_flipped;
1412 mcl->args[2] = 0;
1413 mcl->args[3] = DOMID_SELF;
1414 (void)HYPERVISOR_multicall(np->rx_mcl,
1415 pages_flipped + 1);
1419 while ((skb = __skb_dequeue(&errq)))
1420 kfree_skb(skb);
1422 while ((skb = __skb_dequeue(&rxq)) != NULL) {
1423 struct page *page = (struct page *)skb->nh.raw;
1424 void *vaddr = page_address(page);
1426 memcpy(skb->data, vaddr + (skb->h.raw - skb->nh.raw),
1427 skb_headlen(skb));
1429 if (page != skb_shinfo(skb)->frags[0].page)
1430 __free_page(page);
1432 /* Ethernet work: Delayed to here as it peeks the header. */
1433 skb->protocol = eth_type_trans(skb, dev);
1435 /* Pass it up. */
1436 netif_receive_skb(skb);
1437 dev->last_rx = jiffies;
1440 /* If we get a callback with very few responses, reduce fill target. */
1441 /* NB. Note exponential increase, linear decrease. */
1442 if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) >
1443 ((3*np->rx_target) / 4)) &&
1444 (--np->rx_target < np->rx_min_target))
1445 np->rx_target = np->rx_min_target;
1447 network_alloc_rx_buffers(dev);
1449 *pbudget -= work_done;
1450 dev->quota -= work_done;
1452 if (work_done < budget) {
1453 local_irq_save(flags);
1455 RING_FINAL_CHECK_FOR_RESPONSES(&np->rx, more_to_do);
1456 if (!more_to_do)
1457 __netif_rx_complete(dev);
1459 local_irq_restore(flags);
1462 spin_unlock(&np->rx_lock);
1464 return more_to_do;
1467 static void netif_release_tx_bufs(struct netfront_info *np)
1469 struct sk_buff *skb;
1470 int i;
1472 for (i = 1; i <= NET_TX_RING_SIZE; i++) {
1473 if ((unsigned long)np->tx_skbs[i] < PAGE_OFFSET)
1474 continue;
1476 skb = np->tx_skbs[i];
1477 gnttab_end_foreign_access_ref(
1478 np->grant_tx_ref[i], GNTMAP_readonly);
1479 gnttab_release_grant_reference(
1480 &np->gref_tx_head, np->grant_tx_ref[i]);
1481 np->grant_tx_ref[i] = GRANT_INVALID_REF;
1482 add_id_to_freelist(np->tx_skbs, i);
1483 dev_kfree_skb_irq(skb);
1487 static void netif_release_rx_bufs(struct netfront_info *np)
1489 struct mmu_update *mmu = np->rx_mmu;
1490 struct multicall_entry *mcl = np->rx_mcl;
1491 struct sk_buff_head free_list;
1492 struct sk_buff *skb;
1493 unsigned long mfn;
1494 int xfer = 0, noxfer = 0, unused = 0;
1495 int id, ref;
1497 if (np->copying_receiver) {
1498 printk("%s: fix me for copying receiver.\n", __FUNCTION__);
1499 return;
1502 skb_queue_head_init(&free_list);
1504 spin_lock(&np->rx_lock);
1506 for (id = 0; id < NET_RX_RING_SIZE; id++) {
1507 if ((ref = np->grant_rx_ref[id]) == GRANT_INVALID_REF) {
1508 unused++;
1509 continue;
1512 skb = np->rx_skbs[id];
1513 mfn = gnttab_end_foreign_transfer_ref(ref);
1514 gnttab_release_grant_reference(&np->gref_rx_head, ref);
1515 np->grant_rx_ref[id] = GRANT_INVALID_REF;
1516 add_id_to_freelist(np->rx_skbs, id);
1518 if (0 == mfn) {
1519 struct page *page = skb_shinfo(skb)->frags[0].page;
1520 balloon_release_driver_page(page);
1521 skb_shinfo(skb)->nr_frags = 0;
1522 dev_kfree_skb(skb);
1523 noxfer++;
1524 continue;
1527 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1528 /* Remap the page. */
1529 struct page *page = skb_shinfo(skb)->frags[0].page;
1530 unsigned long pfn = page_to_pfn(page);
1531 void *vaddr = page_address(page);
1533 MULTI_update_va_mapping(mcl, (unsigned long)vaddr,
1534 pfn_pte_ma(mfn, PAGE_KERNEL),
1535 0);
1536 mcl++;
1537 mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
1538 | MMU_MACHPHYS_UPDATE;
1539 mmu->val = pfn;
1540 mmu++;
1542 set_phys_to_machine(pfn, mfn);
1544 __skb_queue_tail(&free_list, skb);
1545 xfer++;
1548 printk("%s: %d xfer, %d noxfer, %d unused\n",
1549 __FUNCTION__, xfer, noxfer, unused);
1551 if (xfer) {
1552 /* Some pages are no longer absent... */
1553 balloon_update_driver_allowance(-xfer);
1555 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1556 /* Do all the remapping work and M2P updates. */
1557 mcl->op = __HYPERVISOR_mmu_update;
1558 mcl->args[0] = (unsigned long)np->rx_mmu;
1559 mcl->args[1] = mmu - np->rx_mmu;
1560 mcl->args[2] = 0;
1561 mcl->args[3] = DOMID_SELF;
1562 mcl++;
1563 HYPERVISOR_multicall(np->rx_mcl, mcl - np->rx_mcl);
1567 while ((skb = __skb_dequeue(&free_list)) != NULL)
1568 dev_kfree_skb(skb);
1570 spin_unlock(&np->rx_lock);
1573 static int network_close(struct net_device *dev)
1575 struct netfront_info *np = netdev_priv(dev);
1576 netif_stop_queue(np->netdev);
1577 return 0;
1581 static struct net_device_stats *network_get_stats(struct net_device *dev)
1583 struct netfront_info *np = netdev_priv(dev);
1584 return &np->stats;
1587 static int xennet_change_mtu(struct net_device *dev, int mtu)
1589 int max = xennet_can_sg(dev) ? 65535 - ETH_HLEN : ETH_DATA_LEN;
1591 if (mtu > max)
1592 return -EINVAL;
1593 dev->mtu = mtu;
1594 return 0;
1597 static int xennet_set_sg(struct net_device *dev, u32 data)
1599 if (data) {
1600 struct netfront_info *np = netdev_priv(dev);
1601 int val;
1603 if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, "feature-sg",
1604 "%d", &val) < 0)
1605 val = 0;
1606 if (!val)
1607 return -ENOSYS;
1608 } else if (dev->mtu > ETH_DATA_LEN)
1609 dev->mtu = ETH_DATA_LEN;
1611 return ethtool_op_set_sg(dev, data);
1614 static int xennet_set_tso(struct net_device *dev, u32 data)
1616 #ifdef HAVE_TSO
1617 if (data) {
1618 struct netfront_info *np = netdev_priv(dev);
1619 int val;
1621 if (xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1622 "feature-gso-tcpv4", "%d", &val) < 0)
1623 val = 0;
1624 if (!val)
1625 return -ENOSYS;
1628 return ethtool_op_set_tso(dev, data);
1629 #else
1630 return -ENOSYS;
1631 #endif
1634 static void xennet_set_features(struct net_device *dev)
1636 dev_disable_gso_features(dev);
1637 xennet_set_sg(dev, 0);
1639 /* We need checksum offload to enable scatter/gather and TSO. */
1640 if (!(dev->features & NETIF_F_IP_CSUM))
1641 return;
1643 if (!xennet_set_sg(dev, 1))
1644 xennet_set_tso(dev, 1);
1647 static void network_connect(struct net_device *dev)
1649 struct netfront_info *np = netdev_priv(dev);
1650 int i, requeue_idx;
1651 struct sk_buff *skb;
1652 grant_ref_t ref;
1653 netif_rx_request_t *req;
1655 xennet_set_features(dev);
1657 spin_lock_irq(&np->tx_lock);
1658 spin_lock(&np->rx_lock);
1660 /*
1661 * Recovery procedure:
1662 * NB. Freelist index entries are always going to be less than
1663 * PAGE_OFFSET, whereas pointers to skbs will always be equal or
1664 * greater than PAGE_OFFSET: we use this property to distinguish
1665 * them.
1666 */
1668 /* Step 1: Discard all pending TX packet fragments. */
1669 netif_release_tx_bufs(np);
1671 /* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
1672 for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
1673 if (!np->rx_skbs[i])
1674 continue;
1676 skb = np->rx_skbs[requeue_idx] = xennet_get_rx_skb(np, i);
1677 ref = np->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(np, i);
1678 req = RING_GET_REQUEST(&np->rx, requeue_idx);
1680 if (!np->copying_receiver) {
1681 gnttab_grant_foreign_transfer_ref(
1682 ref, np->xbdev->otherend_id,
1683 page_to_pfn(skb_shinfo(skb)->frags->page));
1684 } else {
1685 gnttab_grant_foreign_access_ref(
1686 ref, np->xbdev->otherend_id,
1687 pfn_to_mfn(page_to_pfn(skb_shinfo(skb)->
1688 frags->page)),
1689 0);
1691 req->gref = ref;
1692 req->id = requeue_idx;
1694 requeue_idx++;
1697 np->rx.req_prod_pvt = requeue_idx;
1699 /*
1700 * Step 3: All public and private state should now be sane. Get
1701 * ready to start sending and receiving packets and give the driver
1702 * domain a kick because we've probably just requeued some
1703 * packets.
1704 */
1705 netif_carrier_on(dev);
1706 notify_remote_via_irq(np->irq);
1707 network_tx_buf_gc(dev);
1708 network_alloc_rx_buffers(dev);
1710 spin_unlock(&np->rx_lock);
1711 spin_unlock_irq(&np->tx_lock);
1714 static void netif_uninit(struct net_device *dev)
1716 struct netfront_info *np = netdev_priv(dev);
1717 netif_release_tx_bufs(np);
1718 netif_release_rx_bufs(np);
1719 gnttab_free_grant_references(np->gref_tx_head);
1720 gnttab_free_grant_references(np->gref_rx_head);
1723 static struct ethtool_ops network_ethtool_ops =
1725 .get_tx_csum = ethtool_op_get_tx_csum,
1726 .set_tx_csum = ethtool_op_set_tx_csum,
1727 .get_sg = ethtool_op_get_sg,
1728 .set_sg = xennet_set_sg,
1729 .get_tso = ethtool_op_get_tso,
1730 .set_tso = xennet_set_tso,
1731 .get_link = ethtool_op_get_link,
1732 };
1734 #ifdef CONFIG_SYSFS
1735 static ssize_t show_rxbuf_min(struct class_device *cd, char *buf)
1737 struct net_device *netdev = container_of(cd, struct net_device,
1738 class_dev);
1739 struct netfront_info *info = netdev_priv(netdev);
1741 return sprintf(buf, "%u\n", info->rx_min_target);
1744 static ssize_t store_rxbuf_min(struct class_device *cd,
1745 const char *buf, size_t len)
1747 struct net_device *netdev = container_of(cd, struct net_device,
1748 class_dev);
1749 struct netfront_info *np = netdev_priv(netdev);
1750 char *endp;
1751 unsigned long target;
1753 if (!capable(CAP_NET_ADMIN))
1754 return -EPERM;
1756 target = simple_strtoul(buf, &endp, 0);
1757 if (endp == buf)
1758 return -EBADMSG;
1760 if (target < RX_MIN_TARGET)
1761 target = RX_MIN_TARGET;
1762 if (target > RX_MAX_TARGET)
1763 target = RX_MAX_TARGET;
1765 spin_lock(&np->rx_lock);
1766 if (target > np->rx_max_target)
1767 np->rx_max_target = target;
1768 np->rx_min_target = target;
1769 if (target > np->rx_target)
1770 np->rx_target = target;
1772 network_alloc_rx_buffers(netdev);
1774 spin_unlock(&np->rx_lock);
1775 return len;
1778 static ssize_t show_rxbuf_max(struct class_device *cd, char *buf)
1780 struct net_device *netdev = container_of(cd, struct net_device,
1781 class_dev);
1782 struct netfront_info *info = netdev_priv(netdev);
1784 return sprintf(buf, "%u\n", info->rx_max_target);
1787 static ssize_t store_rxbuf_max(struct class_device *cd,
1788 const char *buf, size_t len)
1790 struct net_device *netdev = container_of(cd, struct net_device,
1791 class_dev);
1792 struct netfront_info *np = netdev_priv(netdev);
1793 char *endp;
1794 unsigned long target;
1796 if (!capable(CAP_NET_ADMIN))
1797 return -EPERM;
1799 target = simple_strtoul(buf, &endp, 0);
1800 if (endp == buf)
1801 return -EBADMSG;
1803 if (target < RX_MIN_TARGET)
1804 target = RX_MIN_TARGET;
1805 if (target > RX_MAX_TARGET)
1806 target = RX_MAX_TARGET;
1808 spin_lock(&np->rx_lock);
1809 if (target < np->rx_min_target)
1810 np->rx_min_target = target;
1811 np->rx_max_target = target;
1812 if (target < np->rx_target)
1813 np->rx_target = target;
1815 network_alloc_rx_buffers(netdev);
1817 spin_unlock(&np->rx_lock);
1818 return len;
1821 static ssize_t show_rxbuf_cur(struct class_device *cd, char *buf)
1823 struct net_device *netdev = container_of(cd, struct net_device,
1824 class_dev);
1825 struct netfront_info *info = netdev_priv(netdev);
1827 return sprintf(buf, "%u\n", info->rx_target);
1830 static const struct class_device_attribute xennet_attrs[] = {
1831 __ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf_min, store_rxbuf_min),
1832 __ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf_max, store_rxbuf_max),
1833 __ATTR(rxbuf_cur, S_IRUGO, show_rxbuf_cur, NULL),
1834 };
1836 static int xennet_sysfs_addif(struct net_device *netdev)
1838 int i;
1839 int error = 0;
1841 for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
1842 error = class_device_create_file(&netdev->class_dev,
1843 &xennet_attrs[i]);
1844 if (error)
1845 goto fail;
1847 return 0;
1849 fail:
1850 while (--i >= 0)
1851 class_device_remove_file(&netdev->class_dev,
1852 &xennet_attrs[i]);
1853 return error;
1856 static void xennet_sysfs_delif(struct net_device *netdev)
1858 int i;
1860 for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
1861 class_device_remove_file(&netdev->class_dev,
1862 &xennet_attrs[i]);
1866 #endif /* CONFIG_SYSFS */
1869 /*
1870 * Nothing to do here. Virtual interface is point-to-point and the
1871 * physical interface is probably promiscuous anyway.
1872 */
1873 static void network_set_multicast_list(struct net_device *dev)
1877 static struct net_device * __devinit
1878 create_netdev(int copying_receiver, struct xenbus_device *dev)
1880 int i, err = 0;
1881 struct net_device *netdev = NULL;
1882 struct netfront_info *np = NULL;
1884 netdev = alloc_etherdev(sizeof(struct netfront_info));
1885 if (!netdev) {
1886 printk(KERN_WARNING "%s> alloc_etherdev failed.\n",
1887 __FUNCTION__);
1888 return ERR_PTR(-ENOMEM);
1891 np = netdev_priv(netdev);
1892 np->xbdev = dev;
1893 np->copying_receiver = copying_receiver;
1895 netif_carrier_off(netdev);
1897 spin_lock_init(&np->tx_lock);
1898 spin_lock_init(&np->rx_lock);
1900 skb_queue_head_init(&np->rx_batch);
1901 np->rx_target = RX_DFL_MIN_TARGET;
1902 np->rx_min_target = RX_DFL_MIN_TARGET;
1903 np->rx_max_target = RX_MAX_TARGET;
1905 init_timer(&np->rx_refill_timer);
1906 np->rx_refill_timer.data = (unsigned long)netdev;
1907 np->rx_refill_timer.function = rx_refill_timeout;
1909 /* Initialise {tx,rx}_skbs as a free chain containing every entry. */
1910 for (i = 0; i <= NET_TX_RING_SIZE; i++) {
1911 np->tx_skbs[i] = (void *)((unsigned long) i+1);
1912 np->grant_tx_ref[i] = GRANT_INVALID_REF;
1915 for (i = 0; i < NET_RX_RING_SIZE; i++) {
1916 np->rx_skbs[i] = NULL;
1917 np->grant_rx_ref[i] = GRANT_INVALID_REF;
1920 /* A grant for every tx ring slot */
1921 if (gnttab_alloc_grant_references(TX_MAX_TARGET,
1922 &np->gref_tx_head) < 0) {
1923 printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n");
1924 err = -ENOMEM;
1925 goto exit;
1927 /* A grant for every rx ring slot */
1928 if (gnttab_alloc_grant_references(RX_MAX_TARGET,
1929 &np->gref_rx_head) < 0) {
1930 printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
1931 err = -ENOMEM;
1932 goto exit_free_tx;
1935 netdev->open = network_open;
1936 netdev->hard_start_xmit = network_start_xmit;
1937 netdev->stop = network_close;
1938 netdev->get_stats = network_get_stats;
1939 netdev->poll = netif_poll;
1940 netdev->set_multicast_list = network_set_multicast_list;
1941 netdev->uninit = netif_uninit;
1942 netdev->change_mtu = xennet_change_mtu;
1943 netdev->weight = 64;
1944 netdev->features = NETIF_F_IP_CSUM;
1946 SET_ETHTOOL_OPS(netdev, &network_ethtool_ops);
1947 SET_MODULE_OWNER(netdev);
1948 SET_NETDEV_DEV(netdev, &dev->dev);
1950 np->netdev = netdev;
1951 return netdev;
1953 exit_free_tx:
1954 gnttab_free_grant_references(np->gref_tx_head);
1955 exit:
1956 free_netdev(netdev);
1957 return ERR_PTR(err);
1960 /*
1961 * We use this notifier to send out a fake ARP reply to reset switches and
1962 * router ARP caches when an IP interface is brought up on a VIF.
1963 */
1964 static int
1965 inetdev_notify(struct notifier_block *this, unsigned long event, void *ptr)
1967 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
1968 struct net_device *dev = ifa->ifa_dev->dev;
1970 /* UP event and is it one of our devices? */
1971 if (event == NETDEV_UP && dev->open == network_open)
1972 (void)send_fake_arp(dev);
1974 return NOTIFY_DONE;
1978 /* ** Close down ** */
1981 /**
1982 * Handle the change of state of the backend to Closing. We must delete our
1983 * device-layer structures now, to ensure that writes are flushed through to
1984 * the backend. Once is this done, we can switch to Closed in
1985 * acknowledgement.
1986 */
1987 static void netfront_closing(struct xenbus_device *dev)
1989 struct netfront_info *info = dev->dev.driver_data;
1991 DPRINTK("%s\n", dev->nodename);
1993 close_netdev(info);
1994 xenbus_frontend_closed(dev);
1998 static int __devexit netfront_remove(struct xenbus_device *dev)
2000 struct netfront_info *info = dev->dev.driver_data;
2002 DPRINTK("%s\n", dev->nodename);
2004 netif_disconnect_backend(info);
2005 free_netdev(info->netdev);
2007 return 0;
2011 static int open_netdev(struct netfront_info *info)
2013 int err;
2015 err = register_netdev(info->netdev);
2016 if (err) {
2017 printk(KERN_WARNING "%s: register_netdev err=%d\n",
2018 __FUNCTION__, err);
2019 return err;
2022 err = xennet_sysfs_addif(info->netdev);
2023 if (err) {
2024 /* This can be non-fatal: it only means no tuning parameters */
2025 printk(KERN_WARNING "%s: add sysfs failed err=%d\n",
2026 __FUNCTION__, err);
2028 return 0;
2031 static void close_netdev(struct netfront_info *info)
2033 del_timer_sync(&info->rx_refill_timer);
2035 xennet_sysfs_delif(info->netdev);
2036 unregister_netdev(info->netdev);
2040 static void netif_disconnect_backend(struct netfront_info *info)
2042 /* Stop old i/f to prevent errors whilst we rebuild the state. */
2043 spin_lock_irq(&info->tx_lock);
2044 spin_lock(&info->rx_lock);
2045 netif_carrier_off(info->netdev);
2046 spin_unlock(&info->rx_lock);
2047 spin_unlock_irq(&info->tx_lock);
2049 if (info->irq)
2050 unbind_from_irqhandler(info->irq, info->netdev);
2051 info->evtchn = info->irq = 0;
2053 end_access(info->tx_ring_ref, info->tx.sring);
2054 end_access(info->rx_ring_ref, info->rx.sring);
2055 info->tx_ring_ref = GRANT_INVALID_REF;
2056 info->rx_ring_ref = GRANT_INVALID_REF;
2057 info->tx.sring = NULL;
2058 info->rx.sring = NULL;
2062 static void netif_free(struct netfront_info *info)
2064 close_netdev(info);
2065 netif_disconnect_backend(info);
2066 free_netdev(info->netdev);
2070 static void end_access(int ref, void *page)
2072 if (ref != GRANT_INVALID_REF)
2073 gnttab_end_foreign_access(ref, 0, (unsigned long)page);
2077 /* ** Driver registration ** */
2080 static struct xenbus_device_id netfront_ids[] = {
2081 { "vif" },
2082 { "" }
2083 };
2086 static struct xenbus_driver netfront = {
2087 .name = "vif",
2088 .owner = THIS_MODULE,
2089 .ids = netfront_ids,
2090 .probe = netfront_probe,
2091 .remove = __devexit_p(netfront_remove),
2092 .resume = netfront_resume,
2093 .otherend_changed = backend_changed,
2094 };
2097 static struct notifier_block notifier_inetdev = {
2098 .notifier_call = inetdev_notify,
2099 .next = NULL,
2100 .priority = 0
2101 };
2103 static int __init netif_init(void)
2105 if (!is_running_on_xen())
2106 return -ENODEV;
2108 #ifdef CONFIG_XEN
2109 if (MODPARM_rx_flip && MODPARM_rx_copy) {
2110 WPRINTK("Cannot specify both rx_copy and rx_flip.\n");
2111 return -EINVAL;
2114 if (!MODPARM_rx_flip && !MODPARM_rx_copy)
2115 MODPARM_rx_flip = 1; /* Default is to flip. */
2116 #endif
2118 if (is_initial_xendomain())
2119 return 0;
2121 IPRINTK("Initialising virtual ethernet driver.\n");
2123 (void)register_inetaddr_notifier(&notifier_inetdev);
2125 return xenbus_register_frontend(&netfront);
2127 module_init(netif_init);
2130 static void __exit netif_exit(void)
2132 unregister_inetaddr_notifier(&notifier_inetdev);
2134 return xenbus_unregister_driver(&netfront);
2136 module_exit(netif_exit);
2138 MODULE_LICENSE("Dual BSD/GPL");