ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c @ 13617:42aaf08dd20e

netfront: Check availability of grant references in start_xmit().
Signed-off-by: Tomonari Horikoshi <t.horikoshi@jp.fujitsu.com>
author kfraser@localhost.localdomain
date Thu Jan 25 12:24:43 2007 +0000 (2007-01-25)
parents d275951acf10
children e19f9d6a2ff5
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 /* XXX Need to check we have enough grants for worst-case fragments. */
617 if (gnttab_empty_grant_references(&np->gref_tx_head))
618 return 0;
620 return RING_FREE_REQUESTS(&np->tx) >= MAX_SKB_FRAGS + 2;
621 }
623 static inline void network_maybe_wake_tx(struct net_device *dev)
624 {
625 struct netfront_info *np = netdev_priv(dev);
627 if (unlikely(netif_queue_stopped(dev)) &&
628 netfront_tx_slot_available(np) &&
629 likely(netif_running(dev)))
630 netif_wake_queue(dev);
631 }
633 static void network_tx_buf_gc(struct net_device *dev)
634 {
635 RING_IDX cons, prod;
636 unsigned short id;
637 struct netfront_info *np = netdev_priv(dev);
638 struct sk_buff *skb;
640 BUG_ON(!netif_carrier_ok(dev));
642 do {
643 prod = np->tx.sring->rsp_prod;
644 rmb(); /* Ensure we see responses up to 'rp'. */
646 for (cons = np->tx.rsp_cons; cons != prod; cons++) {
647 struct netif_tx_response *txrsp;
649 txrsp = RING_GET_RESPONSE(&np->tx, cons);
650 if (txrsp->status == NETIF_RSP_NULL)
651 continue;
653 id = txrsp->id;
654 skb = np->tx_skbs[id];
655 if (unlikely(gnttab_query_foreign_access(
656 np->grant_tx_ref[id]) != 0)) {
657 printk(KERN_ALERT "network_tx_buf_gc: warning "
658 "-- grant still in use by backend "
659 "domain.\n");
660 BUG();
661 }
662 gnttab_end_foreign_access_ref(
663 np->grant_tx_ref[id], GNTMAP_readonly);
664 gnttab_release_grant_reference(
665 &np->gref_tx_head, np->grant_tx_ref[id]);
666 np->grant_tx_ref[id] = GRANT_INVALID_REF;
667 add_id_to_freelist(np->tx_skbs, id);
668 dev_kfree_skb_irq(skb);
669 }
671 np->tx.rsp_cons = prod;
673 /*
674 * Set a new event, then check for race with update of tx_cons.
675 * Note that it is essential to schedule a callback, no matter
676 * how few buffers are pending. Even if there is space in the
677 * transmit ring, higher layers may be blocked because too much
678 * data is outstanding: in such cases notification from Xen is
679 * likely to be the only kick that we'll get.
680 */
681 np->tx.sring->rsp_event =
682 prod + ((np->tx.sring->req_prod - prod) >> 1) + 1;
683 mb();
684 } while ((cons == prod) && (prod != np->tx.sring->rsp_prod));
686 network_maybe_wake_tx(dev);
687 }
689 static void rx_refill_timeout(unsigned long data)
690 {
691 struct net_device *dev = (struct net_device *)data;
692 netif_rx_schedule(dev);
693 }
695 static void network_alloc_rx_buffers(struct net_device *dev)
696 {
697 unsigned short id;
698 struct netfront_info *np = netdev_priv(dev);
699 struct sk_buff *skb;
700 struct page *page;
701 int i, batch_target, notify;
702 RING_IDX req_prod = np->rx.req_prod_pvt;
703 struct xen_memory_reservation reservation;
704 grant_ref_t ref;
705 unsigned long pfn;
706 void *vaddr;
707 int nr_flips;
708 netif_rx_request_t *req;
710 if (unlikely(!netif_carrier_ok(dev)))
711 return;
713 /*
714 * Allocate skbuffs greedily, even though we batch updates to the
715 * receive ring. This creates a less bursty demand on the memory
716 * allocator, so should reduce the chance of failed allocation requests
717 * both for ourself and for other kernel subsystems.
718 */
719 batch_target = np->rx_target - (req_prod - np->rx.rsp_cons);
720 for (i = skb_queue_len(&np->rx_batch); i < batch_target; i++) {
721 /*
722 * Allocate an skb and a page. Do not use __dev_alloc_skb as
723 * that will allocate page-sized buffers which is not
724 * necessary here.
725 * 16 bytes added as necessary headroom for netif_receive_skb.
726 */
727 skb = alloc_skb(RX_COPY_THRESHOLD + 16 + NET_IP_ALIGN,
728 GFP_ATOMIC | __GFP_NOWARN);
729 if (unlikely(!skb))
730 goto no_skb;
732 page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
733 if (!page) {
734 kfree_skb(skb);
735 no_skb:
736 /* Any skbuffs queued for refill? Force them out. */
737 if (i != 0)
738 goto refill;
739 /* Could not allocate any skbuffs. Try again later. */
740 mod_timer(&np->rx_refill_timer,
741 jiffies + (HZ/10));
742 break;
743 }
745 skb_reserve(skb, 16 + NET_IP_ALIGN); /* mimic dev_alloc_skb() */
746 skb_shinfo(skb)->frags[0].page = page;
747 skb_shinfo(skb)->nr_frags = 1;
748 __skb_queue_tail(&np->rx_batch, skb);
749 }
751 /* Is the batch large enough to be worthwhile? */
752 if (i < (np->rx_target/2)) {
753 if (req_prod > np->rx.sring->req_prod)
754 goto push;
755 return;
756 }
758 /* Adjust our fill target if we risked running out of buffers. */
759 if (((req_prod - np->rx.sring->rsp_prod) < (np->rx_target / 4)) &&
760 ((np->rx_target *= 2) > np->rx_max_target))
761 np->rx_target = np->rx_max_target;
763 refill:
764 for (nr_flips = i = 0; ; i++) {
765 if ((skb = __skb_dequeue(&np->rx_batch)) == NULL)
766 break;
768 skb->dev = dev;
770 id = xennet_rxidx(req_prod + i);
772 BUG_ON(np->rx_skbs[id]);
773 np->rx_skbs[id] = skb;
775 ref = gnttab_claim_grant_reference(&np->gref_rx_head);
776 BUG_ON((signed short)ref < 0);
777 np->grant_rx_ref[id] = ref;
779 pfn = page_to_pfn(skb_shinfo(skb)->frags[0].page);
780 vaddr = page_address(skb_shinfo(skb)->frags[0].page);
782 req = RING_GET_REQUEST(&np->rx, req_prod + i);
783 if (!np->copying_receiver) {
784 gnttab_grant_foreign_transfer_ref(ref,
785 np->xbdev->otherend_id,
786 pfn);
787 np->rx_pfn_array[nr_flips] = pfn_to_mfn(pfn);
788 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
789 /* Remove this page before passing
790 * back to Xen. */
791 set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
792 MULTI_update_va_mapping(np->rx_mcl+i,
793 (unsigned long)vaddr,
794 __pte(0), 0);
795 }
796 nr_flips++;
797 } else {
798 gnttab_grant_foreign_access_ref(ref,
799 np->xbdev->otherend_id,
800 pfn_to_mfn(pfn),
801 0);
802 }
804 req->id = id;
805 req->gref = ref;
806 }
808 if ( nr_flips != 0 ) {
809 /* Tell the ballon driver what is going on. */
810 balloon_update_driver_allowance(i);
812 set_xen_guest_handle(reservation.extent_start,
813 np->rx_pfn_array);
814 reservation.nr_extents = nr_flips;
815 reservation.extent_order = 0;
816 reservation.address_bits = 0;
817 reservation.domid = DOMID_SELF;
819 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
820 /* After all PTEs have been zapped, flush the TLB. */
821 np->rx_mcl[i-1].args[MULTI_UVMFLAGS_INDEX] =
822 UVMF_TLB_FLUSH|UVMF_ALL;
824 /* Give away a batch of pages. */
825 np->rx_mcl[i].op = __HYPERVISOR_memory_op;
826 np->rx_mcl[i].args[0] = XENMEM_decrease_reservation;
827 np->rx_mcl[i].args[1] = (unsigned long)&reservation;
829 /* Zap PTEs and give away pages in one big
830 * multicall. */
831 (void)HYPERVISOR_multicall(np->rx_mcl, i+1);
833 /* Check return status of HYPERVISOR_memory_op(). */
834 if (unlikely(np->rx_mcl[i].result != i))
835 panic("Unable to reduce memory reservation\n");
836 } else {
837 if (HYPERVISOR_memory_op(XENMEM_decrease_reservation,
838 &reservation) != i)
839 panic("Unable to reduce memory reservation\n");
840 }
841 } else {
842 wmb();
843 }
845 /* Above is a suitable barrier to ensure backend will see requests. */
846 np->rx.req_prod_pvt = req_prod + i;
847 push:
848 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->rx, notify);
849 if (notify)
850 notify_remote_via_irq(np->irq);
851 }
853 static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
854 struct netif_tx_request *tx)
855 {
856 struct netfront_info *np = netdev_priv(dev);
857 char *data = skb->data;
858 unsigned long mfn;
859 RING_IDX prod = np->tx.req_prod_pvt;
860 int frags = skb_shinfo(skb)->nr_frags;
861 unsigned int offset = offset_in_page(data);
862 unsigned int len = skb_headlen(skb);
863 unsigned int id;
864 grant_ref_t ref;
865 int i;
867 while (len > PAGE_SIZE - offset) {
868 tx->size = PAGE_SIZE - offset;
869 tx->flags |= NETTXF_more_data;
870 len -= tx->size;
871 data += tx->size;
872 offset = 0;
874 id = get_id_from_freelist(np->tx_skbs);
875 np->tx_skbs[id] = skb_get(skb);
876 tx = RING_GET_REQUEST(&np->tx, prod++);
877 tx->id = id;
878 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
879 BUG_ON((signed short)ref < 0);
881 mfn = virt_to_mfn(data);
882 gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
883 mfn, GNTMAP_readonly);
885 tx->gref = np->grant_tx_ref[id] = ref;
886 tx->offset = offset;
887 tx->size = len;
888 tx->flags = 0;
889 }
891 for (i = 0; i < frags; i++) {
892 skb_frag_t *frag = skb_shinfo(skb)->frags + i;
894 tx->flags |= NETTXF_more_data;
896 id = get_id_from_freelist(np->tx_skbs);
897 np->tx_skbs[id] = skb_get(skb);
898 tx = RING_GET_REQUEST(&np->tx, prod++);
899 tx->id = id;
900 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
901 BUG_ON((signed short)ref < 0);
903 mfn = pfn_to_mfn(page_to_pfn(frag->page));
904 gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
905 mfn, GNTMAP_readonly);
907 tx->gref = np->grant_tx_ref[id] = ref;
908 tx->offset = frag->page_offset;
909 tx->size = frag->size;
910 tx->flags = 0;
911 }
913 np->tx.req_prod_pvt = prod;
914 }
916 static int network_start_xmit(struct sk_buff *skb, struct net_device *dev)
917 {
918 unsigned short id;
919 struct netfront_info *np = netdev_priv(dev);
920 struct netif_tx_request *tx;
921 struct netif_extra_info *extra;
922 char *data = skb->data;
923 RING_IDX i;
924 grant_ref_t ref;
925 unsigned long mfn;
926 int notify;
927 int frags = skb_shinfo(skb)->nr_frags;
928 unsigned int offset = offset_in_page(data);
929 unsigned int len = skb_headlen(skb);
931 frags += (offset + len + PAGE_SIZE - 1) / PAGE_SIZE;
932 if (unlikely(frags > MAX_SKB_FRAGS + 1)) {
933 printk(KERN_ALERT "xennet: skb rides the rocket: %d frags\n",
934 frags);
935 dump_stack();
936 goto drop;
937 }
939 spin_lock_irq(&np->tx_lock);
941 if (unlikely(!netif_carrier_ok(dev) ||
942 (frags > 1 && !xennet_can_sg(dev)) ||
943 netif_needs_gso(dev, skb))) {
944 spin_unlock_irq(&np->tx_lock);
945 goto drop;
946 }
948 i = np->tx.req_prod_pvt;
950 id = get_id_from_freelist(np->tx_skbs);
951 np->tx_skbs[id] = skb;
953 tx = RING_GET_REQUEST(&np->tx, i);
955 tx->id = id;
956 ref = gnttab_claim_grant_reference(&np->gref_tx_head);
957 BUG_ON((signed short)ref < 0);
958 mfn = virt_to_mfn(data);
959 gnttab_grant_foreign_access_ref(
960 ref, np->xbdev->otherend_id, mfn, GNTMAP_readonly);
961 tx->gref = np->grant_tx_ref[id] = ref;
962 tx->offset = offset;
963 tx->size = len;
965 tx->flags = 0;
966 extra = NULL;
968 if (skb->ip_summed == CHECKSUM_HW) /* local packet? */
969 tx->flags |= NETTXF_csum_blank | NETTXF_data_validated;
970 #ifdef CONFIG_XEN
971 if (skb->proto_data_valid) /* remote but checksummed? */
972 tx->flags |= NETTXF_data_validated;
973 #endif
975 #ifdef HAVE_TSO
976 if (skb_shinfo(skb)->gso_size) {
977 struct netif_extra_info *gso = (struct netif_extra_info *)
978 RING_GET_REQUEST(&np->tx, ++i);
980 if (extra)
981 extra->flags |= XEN_NETIF_EXTRA_FLAG_MORE;
982 else
983 tx->flags |= NETTXF_extra_info;
985 gso->u.gso.size = skb_shinfo(skb)->gso_size;
986 gso->u.gso.type = XEN_NETIF_GSO_TYPE_TCPV4;
987 gso->u.gso.pad = 0;
988 gso->u.gso.features = 0;
990 gso->type = XEN_NETIF_EXTRA_TYPE_GSO;
991 gso->flags = 0;
992 extra = gso;
993 }
994 #endif
996 np->tx.req_prod_pvt = i + 1;
998 xennet_make_frags(skb, dev, tx);
999 tx->size = skb->len;
1001 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->tx, notify);
1002 if (notify)
1003 notify_remote_via_irq(np->irq);
1005 network_tx_buf_gc(dev);
1007 if (!netfront_tx_slot_available(np))
1008 netif_stop_queue(dev);
1010 spin_unlock_irq(&np->tx_lock);
1012 np->stats.tx_bytes += skb->len;
1013 np->stats.tx_packets++;
1015 return 0;
1017 drop:
1018 np->stats.tx_dropped++;
1019 dev_kfree_skb(skb);
1020 return 0;
1023 static irqreturn_t netif_int(int irq, void *dev_id, struct pt_regs *ptregs)
1025 struct net_device *dev = dev_id;
1026 struct netfront_info *np = netdev_priv(dev);
1027 unsigned long flags;
1029 spin_lock_irqsave(&np->tx_lock, flags);
1031 if (likely(netif_carrier_ok(dev))) {
1032 network_tx_buf_gc(dev);
1033 /* Under tx_lock: protects access to rx shared-ring indexes. */
1034 if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
1035 netif_rx_schedule(dev);
1038 spin_unlock_irqrestore(&np->tx_lock, flags);
1040 return IRQ_HANDLED;
1043 static void xennet_move_rx_slot(struct netfront_info *np, struct sk_buff *skb,
1044 grant_ref_t ref)
1046 int new = xennet_rxidx(np->rx.req_prod_pvt);
1048 BUG_ON(np->rx_skbs[new]);
1049 np->rx_skbs[new] = skb;
1050 np->grant_rx_ref[new] = ref;
1051 RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->id = new;
1052 RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->gref = ref;
1053 np->rx.req_prod_pvt++;
1056 int xennet_get_extras(struct netfront_info *np,
1057 struct netif_extra_info *extras, RING_IDX rp)
1060 struct netif_extra_info *extra;
1061 RING_IDX cons = np->rx.rsp_cons;
1062 int err = 0;
1064 do {
1065 struct sk_buff *skb;
1066 grant_ref_t ref;
1068 if (unlikely(cons + 1 == rp)) {
1069 if (net_ratelimit())
1070 WPRINTK("Missing extra info\n");
1071 err = -EBADR;
1072 break;
1075 extra = (struct netif_extra_info *)
1076 RING_GET_RESPONSE(&np->rx, ++cons);
1078 if (unlikely(!extra->type ||
1079 extra->type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
1080 if (net_ratelimit())
1081 WPRINTK("Invalid extra type: %d\n",
1082 extra->type);
1083 err = -EINVAL;
1084 } else {
1085 memcpy(&extras[extra->type - 1], extra,
1086 sizeof(*extra));
1089 skb = xennet_get_rx_skb(np, cons);
1090 ref = xennet_get_rx_ref(np, cons);
1091 xennet_move_rx_slot(np, skb, ref);
1092 } while (extra->flags & XEN_NETIF_EXTRA_FLAG_MORE);
1094 np->rx.rsp_cons = cons;
1095 return err;
1098 static int xennet_get_responses(struct netfront_info *np,
1099 struct netfront_rx_info *rinfo, RING_IDX rp,
1100 struct sk_buff_head *list,
1101 int *pages_flipped_p)
1103 int pages_flipped = *pages_flipped_p;
1104 struct mmu_update *mmu;
1105 struct multicall_entry *mcl;
1106 struct netif_rx_response *rx = &rinfo->rx;
1107 struct netif_extra_info *extras = rinfo->extras;
1108 RING_IDX cons = np->rx.rsp_cons;
1109 struct sk_buff *skb = xennet_get_rx_skb(np, cons);
1110 grant_ref_t ref = xennet_get_rx_ref(np, cons);
1111 int max = MAX_SKB_FRAGS + (rx->status <= RX_COPY_THRESHOLD);
1112 int frags = 1;
1113 int err = 0;
1114 unsigned long ret;
1116 if (rx->flags & NETRXF_extra_info) {
1117 err = xennet_get_extras(np, extras, rp);
1118 cons = np->rx.rsp_cons;
1121 for (;;) {
1122 unsigned long mfn;
1124 if (unlikely(rx->status < 0 ||
1125 rx->offset + rx->status > PAGE_SIZE)) {
1126 if (net_ratelimit())
1127 WPRINTK("rx->offset: %x, size: %u\n",
1128 rx->offset, rx->status);
1129 xennet_move_rx_slot(np, skb, ref);
1130 err = -EINVAL;
1131 goto next;
1134 /*
1135 * This definitely indicates a bug, either in this driver or in
1136 * the backend driver. In future this should flag the bad
1137 * situation to the system controller to reboot the backed.
1138 */
1139 if (ref == GRANT_INVALID_REF) {
1140 if (net_ratelimit())
1141 WPRINTK("Bad rx response id %d.\n", rx->id);
1142 err = -EINVAL;
1143 goto next;
1146 if (!np->copying_receiver) {
1147 /* Memory pressure, insufficient buffer
1148 * headroom, ... */
1149 if (!(mfn = gnttab_end_foreign_transfer_ref(ref))) {
1150 if (net_ratelimit())
1151 WPRINTK("Unfulfilled rx req "
1152 "(id=%d, st=%d).\n",
1153 rx->id, rx->status);
1154 xennet_move_rx_slot(np, skb, ref);
1155 err = -ENOMEM;
1156 goto next;
1159 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1160 /* Remap the page. */
1161 struct page *page =
1162 skb_shinfo(skb)->frags[0].page;
1163 unsigned long pfn = page_to_pfn(page);
1164 void *vaddr = page_address(page);
1166 mcl = np->rx_mcl + pages_flipped;
1167 mmu = np->rx_mmu + pages_flipped;
1169 MULTI_update_va_mapping(mcl,
1170 (unsigned long)vaddr,
1171 pfn_pte_ma(mfn,
1172 PAGE_KERNEL),
1173 0);
1174 mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
1175 | MMU_MACHPHYS_UPDATE;
1176 mmu->val = pfn;
1178 set_phys_to_machine(pfn, mfn);
1180 pages_flipped++;
1181 } else {
1182 ret = gnttab_end_foreign_access_ref(ref, 0);
1183 BUG_ON(!ret);
1186 gnttab_release_grant_reference(&np->gref_rx_head, ref);
1188 __skb_queue_tail(list, skb);
1190 next:
1191 if (!(rx->flags & NETRXF_more_data))
1192 break;
1194 if (cons + frags == rp) {
1195 if (net_ratelimit())
1196 WPRINTK("Need more frags\n");
1197 err = -ENOENT;
1198 break;
1201 rx = RING_GET_RESPONSE(&np->rx, cons + frags);
1202 skb = xennet_get_rx_skb(np, cons + frags);
1203 ref = xennet_get_rx_ref(np, cons + frags);
1204 frags++;
1207 if (unlikely(frags > max)) {
1208 if (net_ratelimit())
1209 WPRINTK("Too many frags\n");
1210 err = -E2BIG;
1213 if (unlikely(err))
1214 np->rx.rsp_cons = cons + frags;
1216 *pages_flipped_p = pages_flipped;
1218 return err;
1221 static RING_IDX xennet_fill_frags(struct netfront_info *np,
1222 struct sk_buff *skb,
1223 struct sk_buff_head *list)
1225 struct skb_shared_info *shinfo = skb_shinfo(skb);
1226 int nr_frags = shinfo->nr_frags;
1227 RING_IDX cons = np->rx.rsp_cons;
1228 skb_frag_t *frag = shinfo->frags + nr_frags;
1229 struct sk_buff *nskb;
1231 while ((nskb = __skb_dequeue(list))) {
1232 struct netif_rx_response *rx =
1233 RING_GET_RESPONSE(&np->rx, ++cons);
1235 frag->page = skb_shinfo(nskb)->frags[0].page;
1236 frag->page_offset = rx->offset;
1237 frag->size = rx->status;
1239 skb->data_len += rx->status;
1241 skb_shinfo(nskb)->nr_frags = 0;
1242 kfree_skb(nskb);
1244 frag++;
1245 nr_frags++;
1248 shinfo->nr_frags = nr_frags;
1249 return cons;
1252 static int xennet_set_skb_gso(struct sk_buff *skb,
1253 struct netif_extra_info *gso)
1255 if (!gso->u.gso.size) {
1256 if (net_ratelimit())
1257 WPRINTK("GSO size must not be zero.\n");
1258 return -EINVAL;
1261 /* Currently only TCPv4 S.O. is supported. */
1262 if (gso->u.gso.type != XEN_NETIF_GSO_TYPE_TCPV4) {
1263 if (net_ratelimit())
1264 WPRINTK("Bad GSO type %d.\n", gso->u.gso.type);
1265 return -EINVAL;
1268 #ifdef HAVE_TSO
1269 skb_shinfo(skb)->gso_size = gso->u.gso.size;
1270 #ifdef HAVE_GSO
1271 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1273 /* Header must be checked, and gso_segs computed. */
1274 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
1275 #endif
1276 skb_shinfo(skb)->gso_segs = 0;
1278 return 0;
1279 #else
1280 if (net_ratelimit())
1281 WPRINTK("GSO unsupported by this kernel.\n");
1282 return -EINVAL;
1283 #endif
1286 static int netif_poll(struct net_device *dev, int *pbudget)
1288 struct netfront_info *np = netdev_priv(dev);
1289 struct sk_buff *skb;
1290 struct netfront_rx_info rinfo;
1291 struct netif_rx_response *rx = &rinfo.rx;
1292 struct netif_extra_info *extras = rinfo.extras;
1293 RING_IDX i, rp;
1294 struct multicall_entry *mcl;
1295 int work_done, budget, more_to_do = 1;
1296 struct sk_buff_head rxq;
1297 struct sk_buff_head errq;
1298 struct sk_buff_head tmpq;
1299 unsigned long flags;
1300 unsigned int len;
1301 int pages_flipped = 0;
1302 int err;
1304 spin_lock(&np->rx_lock);
1306 if (unlikely(!netif_carrier_ok(dev))) {
1307 spin_unlock(&np->rx_lock);
1308 return 0;
1311 skb_queue_head_init(&rxq);
1312 skb_queue_head_init(&errq);
1313 skb_queue_head_init(&tmpq);
1315 if ((budget = *pbudget) > dev->quota)
1316 budget = dev->quota;
1317 rp = np->rx.sring->rsp_prod;
1318 rmb(); /* Ensure we see queued responses up to 'rp'. */
1320 i = np->rx.rsp_cons;
1321 work_done = 0;
1322 while ((i != rp) && (work_done < budget)) {
1323 memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx));
1324 memset(extras, 0, sizeof(extras));
1326 err = xennet_get_responses(np, &rinfo, rp, &tmpq,
1327 &pages_flipped);
1329 if (unlikely(err)) {
1330 err:
1331 while ((skb = __skb_dequeue(&tmpq)))
1332 __skb_queue_tail(&errq, skb);
1333 np->stats.rx_errors++;
1334 i = np->rx.rsp_cons;
1335 continue;
1338 skb = __skb_dequeue(&tmpq);
1340 if (extras[XEN_NETIF_EXTRA_TYPE_GSO - 1].type) {
1341 struct netif_extra_info *gso;
1342 gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO - 1];
1344 if (unlikely(xennet_set_skb_gso(skb, gso))) {
1345 __skb_queue_head(&tmpq, skb);
1346 np->rx.rsp_cons += skb_queue_len(&tmpq);
1347 goto err;
1351 skb->nh.raw = (void *)skb_shinfo(skb)->frags[0].page;
1352 skb->h.raw = skb->nh.raw + rx->offset;
1354 len = rx->status;
1355 if (len > RX_COPY_THRESHOLD)
1356 len = RX_COPY_THRESHOLD;
1357 skb_put(skb, len);
1359 if (rx->status > len) {
1360 skb_shinfo(skb)->frags[0].page_offset =
1361 rx->offset + len;
1362 skb_shinfo(skb)->frags[0].size = rx->status - len;
1363 skb->data_len = rx->status - len;
1364 } else {
1365 skb_shinfo(skb)->frags[0].page = NULL;
1366 skb_shinfo(skb)->nr_frags = 0;
1369 i = xennet_fill_frags(np, skb, &tmpq);
1371 /*
1372 * Truesize must approximates the size of true data plus
1373 * any supervisor overheads. Adding hypervisor overheads
1374 * has been shown to significantly reduce achievable
1375 * bandwidth with the default receive buffer size. It is
1376 * therefore not wise to account for it here.
1378 * After alloc_skb(RX_COPY_THRESHOLD), truesize is set to
1379 * RX_COPY_THRESHOLD + the supervisor overheads. Here, we
1380 * add the size of the data pulled in xennet_fill_frags().
1382 * We also adjust for any unused space in the main data
1383 * area by subtracting (RX_COPY_THRESHOLD - len). This is
1384 * especially important with drivers which split incoming
1385 * packets into header and data, using only 66 bytes of
1386 * the main data area (see the e1000 driver for example.)
1387 * On such systems, without this last adjustement, our
1388 * achievable receive throughout using the standard receive
1389 * buffer size was cut by 25%(!!!).
1390 */
1391 skb->truesize += skb->data_len - (RX_COPY_THRESHOLD - len);
1392 skb->len += skb->data_len;
1394 /*
1395 * Old backends do not assert data_validated but we
1396 * can infer it from csum_blank so test both flags.
1397 */
1398 if (rx->flags & (NETRXF_data_validated|NETRXF_csum_blank))
1399 skb->ip_summed = CHECKSUM_UNNECESSARY;
1400 else
1401 skb->ip_summed = CHECKSUM_NONE;
1402 #ifdef CONFIG_XEN
1403 skb->proto_data_valid = (skb->ip_summed != CHECKSUM_NONE);
1404 skb->proto_csum_blank = !!(rx->flags & NETRXF_csum_blank);
1405 #endif
1406 np->stats.rx_packets++;
1407 np->stats.rx_bytes += skb->len;
1409 __skb_queue_tail(&rxq, skb);
1411 np->rx.rsp_cons = ++i;
1412 work_done++;
1415 if (pages_flipped) {
1416 /* Some pages are no longer absent... */
1417 balloon_update_driver_allowance(-pages_flipped);
1419 /* Do all the remapping work and M2P updates. */
1420 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1421 mcl = np->rx_mcl + pages_flipped;
1422 mcl->op = __HYPERVISOR_mmu_update;
1423 mcl->args[0] = (unsigned long)np->rx_mmu;
1424 mcl->args[1] = pages_flipped;
1425 mcl->args[2] = 0;
1426 mcl->args[3] = DOMID_SELF;
1427 (void)HYPERVISOR_multicall(np->rx_mcl,
1428 pages_flipped + 1);
1432 while ((skb = __skb_dequeue(&errq)))
1433 kfree_skb(skb);
1435 while ((skb = __skb_dequeue(&rxq)) != NULL) {
1436 struct page *page = (struct page *)skb->nh.raw;
1437 void *vaddr = page_address(page);
1439 memcpy(skb->data, vaddr + (skb->h.raw - skb->nh.raw),
1440 skb_headlen(skb));
1442 if (page != skb_shinfo(skb)->frags[0].page)
1443 __free_page(page);
1445 /* Ethernet work: Delayed to here as it peeks the header. */
1446 skb->protocol = eth_type_trans(skb, dev);
1448 /* Pass it up. */
1449 netif_receive_skb(skb);
1450 dev->last_rx = jiffies;
1453 /* If we get a callback with very few responses, reduce fill target. */
1454 /* NB. Note exponential increase, linear decrease. */
1455 if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) >
1456 ((3*np->rx_target) / 4)) &&
1457 (--np->rx_target < np->rx_min_target))
1458 np->rx_target = np->rx_min_target;
1460 network_alloc_rx_buffers(dev);
1462 *pbudget -= work_done;
1463 dev->quota -= work_done;
1465 if (work_done < budget) {
1466 local_irq_save(flags);
1468 RING_FINAL_CHECK_FOR_RESPONSES(&np->rx, more_to_do);
1469 if (!more_to_do)
1470 __netif_rx_complete(dev);
1472 local_irq_restore(flags);
1475 spin_unlock(&np->rx_lock);
1477 return more_to_do;
1480 static void netif_release_tx_bufs(struct netfront_info *np)
1482 struct sk_buff *skb;
1483 int i;
1485 for (i = 1; i <= NET_TX_RING_SIZE; i++) {
1486 if ((unsigned long)np->tx_skbs[i] < PAGE_OFFSET)
1487 continue;
1489 skb = np->tx_skbs[i];
1490 gnttab_end_foreign_access_ref(
1491 np->grant_tx_ref[i], GNTMAP_readonly);
1492 gnttab_release_grant_reference(
1493 &np->gref_tx_head, np->grant_tx_ref[i]);
1494 np->grant_tx_ref[i] = GRANT_INVALID_REF;
1495 add_id_to_freelist(np->tx_skbs, i);
1496 dev_kfree_skb_irq(skb);
1500 static void netif_release_rx_bufs(struct netfront_info *np)
1502 struct mmu_update *mmu = np->rx_mmu;
1503 struct multicall_entry *mcl = np->rx_mcl;
1504 struct sk_buff_head free_list;
1505 struct sk_buff *skb;
1506 unsigned long mfn;
1507 int xfer = 0, noxfer = 0, unused = 0;
1508 int id, ref;
1510 if (np->copying_receiver) {
1511 printk("%s: fix me for copying receiver.\n", __FUNCTION__);
1512 return;
1515 skb_queue_head_init(&free_list);
1517 spin_lock(&np->rx_lock);
1519 for (id = 0; id < NET_RX_RING_SIZE; id++) {
1520 if ((ref = np->grant_rx_ref[id]) == GRANT_INVALID_REF) {
1521 unused++;
1522 continue;
1525 skb = np->rx_skbs[id];
1526 mfn = gnttab_end_foreign_transfer_ref(ref);
1527 gnttab_release_grant_reference(&np->gref_rx_head, ref);
1528 np->grant_rx_ref[id] = GRANT_INVALID_REF;
1529 add_id_to_freelist(np->rx_skbs, id);
1531 if (0 == mfn) {
1532 struct page *page = skb_shinfo(skb)->frags[0].page;
1533 balloon_release_driver_page(page);
1534 skb_shinfo(skb)->nr_frags = 0;
1535 dev_kfree_skb(skb);
1536 noxfer++;
1537 continue;
1540 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1541 /* Remap the page. */
1542 struct page *page = skb_shinfo(skb)->frags[0].page;
1543 unsigned long pfn = page_to_pfn(page);
1544 void *vaddr = page_address(page);
1546 MULTI_update_va_mapping(mcl, (unsigned long)vaddr,
1547 pfn_pte_ma(mfn, PAGE_KERNEL),
1548 0);
1549 mcl++;
1550 mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
1551 | MMU_MACHPHYS_UPDATE;
1552 mmu->val = pfn;
1553 mmu++;
1555 set_phys_to_machine(pfn, mfn);
1557 __skb_queue_tail(&free_list, skb);
1558 xfer++;
1561 printk("%s: %d xfer, %d noxfer, %d unused\n",
1562 __FUNCTION__, xfer, noxfer, unused);
1564 if (xfer) {
1565 /* Some pages are no longer absent... */
1566 balloon_update_driver_allowance(-xfer);
1568 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1569 /* Do all the remapping work and M2P updates. */
1570 mcl->op = __HYPERVISOR_mmu_update;
1571 mcl->args[0] = (unsigned long)np->rx_mmu;
1572 mcl->args[1] = mmu - np->rx_mmu;
1573 mcl->args[2] = 0;
1574 mcl->args[3] = DOMID_SELF;
1575 mcl++;
1576 HYPERVISOR_multicall(np->rx_mcl, mcl - np->rx_mcl);
1580 while ((skb = __skb_dequeue(&free_list)) != NULL)
1581 dev_kfree_skb(skb);
1583 spin_unlock(&np->rx_lock);
1586 static int network_close(struct net_device *dev)
1588 struct netfront_info *np = netdev_priv(dev);
1589 netif_stop_queue(np->netdev);
1590 return 0;
1594 static struct net_device_stats *network_get_stats(struct net_device *dev)
1596 struct netfront_info *np = netdev_priv(dev);
1597 return &np->stats;
1600 static int xennet_change_mtu(struct net_device *dev, int mtu)
1602 int max = xennet_can_sg(dev) ? 65535 - ETH_HLEN : ETH_DATA_LEN;
1604 if (mtu > max)
1605 return -EINVAL;
1606 dev->mtu = mtu;
1607 return 0;
1610 static int xennet_set_sg(struct net_device *dev, u32 data)
1612 if (data) {
1613 struct netfront_info *np = netdev_priv(dev);
1614 int val;
1616 if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, "feature-sg",
1617 "%d", &val) < 0)
1618 val = 0;
1619 if (!val)
1620 return -ENOSYS;
1621 } else if (dev->mtu > ETH_DATA_LEN)
1622 dev->mtu = ETH_DATA_LEN;
1624 return ethtool_op_set_sg(dev, data);
1627 static int xennet_set_tso(struct net_device *dev, u32 data)
1629 #ifdef HAVE_TSO
1630 if (data) {
1631 struct netfront_info *np = netdev_priv(dev);
1632 int val;
1634 if (xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1635 "feature-gso-tcpv4", "%d", &val) < 0)
1636 val = 0;
1637 if (!val)
1638 return -ENOSYS;
1641 return ethtool_op_set_tso(dev, data);
1642 #else
1643 return -ENOSYS;
1644 #endif
1647 static void xennet_set_features(struct net_device *dev)
1649 dev_disable_gso_features(dev);
1650 xennet_set_sg(dev, 0);
1652 /* We need checksum offload to enable scatter/gather and TSO. */
1653 if (!(dev->features & NETIF_F_IP_CSUM))
1654 return;
1656 if (xennet_set_sg(dev, 1))
1657 return;
1659 /* Before 2.6.9 TSO seems to be unreliable so do not enable it
1660 * on older kernels.
1661 */
1662 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
1663 xennet_set_tso(dev, 1);
1664 #endif
1668 static int network_connect(struct net_device *dev)
1670 struct netfront_info *np = netdev_priv(dev);
1671 int i, requeue_idx, err;
1672 struct sk_buff *skb;
1673 grant_ref_t ref;
1674 netif_rx_request_t *req;
1675 unsigned int feature_rx_copy, feature_rx_flip;
1677 err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1678 "feature-rx-copy", "%u", &feature_rx_copy);
1679 if (err != 1)
1680 feature_rx_copy = 0;
1681 err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
1682 "feature-rx-flip", "%u", &feature_rx_flip);
1683 if (err != 1)
1684 feature_rx_flip = 1;
1686 /*
1687 * Copy packets on receive path if:
1688 * (a) This was requested by user, and the backend supports it; or
1689 * (b) Flipping was requested, but this is unsupported by the backend.
1690 */
1691 np->copying_receiver = ((MODPARM_rx_copy && feature_rx_copy) ||
1692 (MODPARM_rx_flip && !feature_rx_flip));
1694 err = talk_to_backend(np->xbdev, np);
1695 if (err)
1696 return err;
1698 xennet_set_features(dev);
1700 IPRINTK("device %s has %sing receive path.\n",
1701 dev->name, np->copying_receiver ? "copy" : "flipp");
1703 spin_lock_irq(&np->tx_lock);
1704 spin_lock(&np->rx_lock);
1706 /*
1707 * Recovery procedure:
1708 * NB. Freelist index entries are always going to be less than
1709 * PAGE_OFFSET, whereas pointers to skbs will always be equal or
1710 * greater than PAGE_OFFSET: we use this property to distinguish
1711 * them.
1712 */
1714 /* Step 1: Discard all pending TX packet fragments. */
1715 netif_release_tx_bufs(np);
1717 /* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
1718 for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
1719 if (!np->rx_skbs[i])
1720 continue;
1722 skb = np->rx_skbs[requeue_idx] = xennet_get_rx_skb(np, i);
1723 ref = np->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(np, i);
1724 req = RING_GET_REQUEST(&np->rx, requeue_idx);
1726 if (!np->copying_receiver) {
1727 gnttab_grant_foreign_transfer_ref(
1728 ref, np->xbdev->otherend_id,
1729 page_to_pfn(skb_shinfo(skb)->frags->page));
1730 } else {
1731 gnttab_grant_foreign_access_ref(
1732 ref, np->xbdev->otherend_id,
1733 pfn_to_mfn(page_to_pfn(skb_shinfo(skb)->
1734 frags->page)),
1735 0);
1737 req->gref = ref;
1738 req->id = requeue_idx;
1740 requeue_idx++;
1743 np->rx.req_prod_pvt = requeue_idx;
1745 /*
1746 * Step 3: All public and private state should now be sane. Get
1747 * ready to start sending and receiving packets and give the driver
1748 * domain a kick because we've probably just requeued some
1749 * packets.
1750 */
1751 netif_carrier_on(dev);
1752 notify_remote_via_irq(np->irq);
1753 network_tx_buf_gc(dev);
1754 network_alloc_rx_buffers(dev);
1756 spin_unlock(&np->rx_lock);
1757 spin_unlock_irq(&np->tx_lock);
1759 return 0;
1762 static void netif_uninit(struct net_device *dev)
1764 struct netfront_info *np = netdev_priv(dev);
1765 netif_release_tx_bufs(np);
1766 netif_release_rx_bufs(np);
1767 gnttab_free_grant_references(np->gref_tx_head);
1768 gnttab_free_grant_references(np->gref_rx_head);
1771 static struct ethtool_ops network_ethtool_ops =
1773 .get_tx_csum = ethtool_op_get_tx_csum,
1774 .set_tx_csum = ethtool_op_set_tx_csum,
1775 .get_sg = ethtool_op_get_sg,
1776 .set_sg = xennet_set_sg,
1777 .get_tso = ethtool_op_get_tso,
1778 .set_tso = xennet_set_tso,
1779 .get_link = ethtool_op_get_link,
1780 };
1782 #ifdef CONFIG_SYSFS
1783 static ssize_t show_rxbuf_min(struct class_device *cd, char *buf)
1785 struct net_device *netdev = container_of(cd, struct net_device,
1786 class_dev);
1787 struct netfront_info *info = netdev_priv(netdev);
1789 return sprintf(buf, "%u\n", info->rx_min_target);
1792 static ssize_t store_rxbuf_min(struct class_device *cd,
1793 const char *buf, size_t len)
1795 struct net_device *netdev = container_of(cd, struct net_device,
1796 class_dev);
1797 struct netfront_info *np = netdev_priv(netdev);
1798 char *endp;
1799 unsigned long target;
1801 if (!capable(CAP_NET_ADMIN))
1802 return -EPERM;
1804 target = simple_strtoul(buf, &endp, 0);
1805 if (endp == buf)
1806 return -EBADMSG;
1808 if (target < RX_MIN_TARGET)
1809 target = RX_MIN_TARGET;
1810 if (target > RX_MAX_TARGET)
1811 target = RX_MAX_TARGET;
1813 spin_lock(&np->rx_lock);
1814 if (target > np->rx_max_target)
1815 np->rx_max_target = target;
1816 np->rx_min_target = target;
1817 if (target > np->rx_target)
1818 np->rx_target = target;
1820 network_alloc_rx_buffers(netdev);
1822 spin_unlock(&np->rx_lock);
1823 return len;
1826 static ssize_t show_rxbuf_max(struct class_device *cd, char *buf)
1828 struct net_device *netdev = container_of(cd, struct net_device,
1829 class_dev);
1830 struct netfront_info *info = netdev_priv(netdev);
1832 return sprintf(buf, "%u\n", info->rx_max_target);
1835 static ssize_t store_rxbuf_max(struct class_device *cd,
1836 const char *buf, size_t len)
1838 struct net_device *netdev = container_of(cd, struct net_device,
1839 class_dev);
1840 struct netfront_info *np = netdev_priv(netdev);
1841 char *endp;
1842 unsigned long target;
1844 if (!capable(CAP_NET_ADMIN))
1845 return -EPERM;
1847 target = simple_strtoul(buf, &endp, 0);
1848 if (endp == buf)
1849 return -EBADMSG;
1851 if (target < RX_MIN_TARGET)
1852 target = RX_MIN_TARGET;
1853 if (target > RX_MAX_TARGET)
1854 target = RX_MAX_TARGET;
1856 spin_lock(&np->rx_lock);
1857 if (target < np->rx_min_target)
1858 np->rx_min_target = target;
1859 np->rx_max_target = target;
1860 if (target < np->rx_target)
1861 np->rx_target = target;
1863 network_alloc_rx_buffers(netdev);
1865 spin_unlock(&np->rx_lock);
1866 return len;
1869 static ssize_t show_rxbuf_cur(struct class_device *cd, char *buf)
1871 struct net_device *netdev = container_of(cd, struct net_device,
1872 class_dev);
1873 struct netfront_info *info = netdev_priv(netdev);
1875 return sprintf(buf, "%u\n", info->rx_target);
1878 static const struct class_device_attribute xennet_attrs[] = {
1879 __ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf_min, store_rxbuf_min),
1880 __ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf_max, store_rxbuf_max),
1881 __ATTR(rxbuf_cur, S_IRUGO, show_rxbuf_cur, NULL),
1882 };
1884 static int xennet_sysfs_addif(struct net_device *netdev)
1886 int i;
1887 int error = 0;
1889 for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
1890 error = class_device_create_file(&netdev->class_dev,
1891 &xennet_attrs[i]);
1892 if (error)
1893 goto fail;
1895 return 0;
1897 fail:
1898 while (--i >= 0)
1899 class_device_remove_file(&netdev->class_dev,
1900 &xennet_attrs[i]);
1901 return error;
1904 static void xennet_sysfs_delif(struct net_device *netdev)
1906 int i;
1908 for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
1909 class_device_remove_file(&netdev->class_dev,
1910 &xennet_attrs[i]);
1914 #endif /* CONFIG_SYSFS */
1917 /*
1918 * Nothing to do here. Virtual interface is point-to-point and the
1919 * physical interface is probably promiscuous anyway.
1920 */
1921 static void network_set_multicast_list(struct net_device *dev)
1925 static struct net_device * __devinit create_netdev(struct xenbus_device *dev)
1927 int i, err = 0;
1928 struct net_device *netdev = NULL;
1929 struct netfront_info *np = NULL;
1931 netdev = alloc_etherdev(sizeof(struct netfront_info));
1932 if (!netdev) {
1933 printk(KERN_WARNING "%s> alloc_etherdev failed.\n",
1934 __FUNCTION__);
1935 return ERR_PTR(-ENOMEM);
1938 np = netdev_priv(netdev);
1939 np->xbdev = dev;
1941 netif_carrier_off(netdev);
1943 spin_lock_init(&np->tx_lock);
1944 spin_lock_init(&np->rx_lock);
1946 skb_queue_head_init(&np->rx_batch);
1947 np->rx_target = RX_DFL_MIN_TARGET;
1948 np->rx_min_target = RX_DFL_MIN_TARGET;
1949 np->rx_max_target = RX_MAX_TARGET;
1951 init_timer(&np->rx_refill_timer);
1952 np->rx_refill_timer.data = (unsigned long)netdev;
1953 np->rx_refill_timer.function = rx_refill_timeout;
1955 /* Initialise {tx,rx}_skbs as a free chain containing every entry. */
1956 for (i = 0; i <= NET_TX_RING_SIZE; i++) {
1957 np->tx_skbs[i] = (void *)((unsigned long) i+1);
1958 np->grant_tx_ref[i] = GRANT_INVALID_REF;
1961 for (i = 0; i < NET_RX_RING_SIZE; i++) {
1962 np->rx_skbs[i] = NULL;
1963 np->grant_rx_ref[i] = GRANT_INVALID_REF;
1966 /* A grant for every tx ring slot */
1967 if (gnttab_alloc_grant_references(TX_MAX_TARGET,
1968 &np->gref_tx_head) < 0) {
1969 printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n");
1970 err = -ENOMEM;
1971 goto exit;
1973 /* A grant for every rx ring slot */
1974 if (gnttab_alloc_grant_references(RX_MAX_TARGET,
1975 &np->gref_rx_head) < 0) {
1976 printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
1977 err = -ENOMEM;
1978 goto exit_free_tx;
1981 netdev->open = network_open;
1982 netdev->hard_start_xmit = network_start_xmit;
1983 netdev->stop = network_close;
1984 netdev->get_stats = network_get_stats;
1985 netdev->poll = netif_poll;
1986 netdev->set_multicast_list = network_set_multicast_list;
1987 netdev->uninit = netif_uninit;
1988 netdev->change_mtu = xennet_change_mtu;
1989 netdev->weight = 64;
1990 netdev->features = NETIF_F_IP_CSUM;
1992 SET_ETHTOOL_OPS(netdev, &network_ethtool_ops);
1993 SET_MODULE_OWNER(netdev);
1994 SET_NETDEV_DEV(netdev, &dev->dev);
1996 np->netdev = netdev;
1997 return netdev;
1999 exit_free_tx:
2000 gnttab_free_grant_references(np->gref_tx_head);
2001 exit:
2002 free_netdev(netdev);
2003 return ERR_PTR(err);
2006 /*
2007 * We use this notifier to send out a fake ARP reply to reset switches and
2008 * router ARP caches when an IP interface is brought up on a VIF.
2009 */
2010 static int
2011 inetdev_notify(struct notifier_block *this, unsigned long event, void *ptr)
2013 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2014 struct net_device *dev = ifa->ifa_dev->dev;
2016 /* UP event and is it one of our devices? */
2017 if (event == NETDEV_UP && dev->open == network_open)
2018 (void)send_fake_arp(dev);
2020 return NOTIFY_DONE;
2024 static void netif_disconnect_backend(struct netfront_info *info)
2026 /* Stop old i/f to prevent errors whilst we rebuild the state. */
2027 spin_lock_irq(&info->tx_lock);
2028 spin_lock(&info->rx_lock);
2029 netif_carrier_off(info->netdev);
2030 spin_unlock(&info->rx_lock);
2031 spin_unlock_irq(&info->tx_lock);
2033 if (info->irq)
2034 unbind_from_irqhandler(info->irq, info->netdev);
2035 info->irq = 0;
2037 end_access(info->tx_ring_ref, info->tx.sring);
2038 end_access(info->rx_ring_ref, info->rx.sring);
2039 info->tx_ring_ref = GRANT_INVALID_REF;
2040 info->rx_ring_ref = GRANT_INVALID_REF;
2041 info->tx.sring = NULL;
2042 info->rx.sring = NULL;
2046 static void end_access(int ref, void *page)
2048 if (ref != GRANT_INVALID_REF)
2049 gnttab_end_foreign_access(ref, 0, (unsigned long)page);
2053 /* ** Driver registration ** */
2056 static struct xenbus_device_id netfront_ids[] = {
2057 { "vif" },
2058 { "" }
2059 };
2062 static struct xenbus_driver netfront = {
2063 .name = "vif",
2064 .owner = THIS_MODULE,
2065 .ids = netfront_ids,
2066 .probe = netfront_probe,
2067 .remove = __devexit_p(netfront_remove),
2068 .resume = netfront_resume,
2069 .otherend_changed = backend_changed,
2070 };
2073 static struct notifier_block notifier_inetdev = {
2074 .notifier_call = inetdev_notify,
2075 .next = NULL,
2076 .priority = 0
2077 };
2079 static int __init netif_init(void)
2081 if (!is_running_on_xen())
2082 return -ENODEV;
2084 #ifdef CONFIG_XEN
2085 if (MODPARM_rx_flip && MODPARM_rx_copy) {
2086 WPRINTK("Cannot specify both rx_copy and rx_flip.\n");
2087 return -EINVAL;
2090 if (!MODPARM_rx_flip && !MODPARM_rx_copy)
2091 MODPARM_rx_flip = 1; /* Default is to flip. */
2092 #endif
2094 if (is_initial_xendomain())
2095 return 0;
2097 IPRINTK("Initialising virtual ethernet driver.\n");
2099 (void)register_inetaddr_notifier(&notifier_inetdev);
2101 return xenbus_register_frontend(&netfront);
2103 module_init(netif_init);
2106 static void __exit netif_exit(void)
2108 if (is_initial_xendomain())
2109 return;
2111 unregister_inetaddr_notifier(&notifier_inetdev);
2113 return xenbus_unregister_driver(&netfront);
2115 module_exit(netif_exit);
2117 MODULE_LICENSE("Dual BSD/GPL");