blob: b9de31ea7fc48ac333f30dfa17041fdef893895a [file] [log] [blame]
Ian Campbellf942dc22011-03-15 00:06:18 +00001/*
2 * Network-device interface management.
3 *
4 * Copyright (c) 2004-2005, Keir Fraser
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation; or, when distributed
9 * separately from the Linux kernel or incorporated into other
10 * software packages, subject to the following license:
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this source file (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use, copy, modify,
15 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
16 * and to permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
30
31#include "common.h"
32
Wei Liub3f980b2013-08-26 12:59:38 +010033#include <linux/kthread.h>
Ian Campbellf942dc22011-03-15 00:06:18 +000034#include <linux/ethtool.h>
35#include <linux/rtnetlink.h>
36#include <linux/if_vlan.h>
Josh Boyerf35f76e2014-01-05 10:24:01 -050037#include <linux/vmalloc.h>
Ian Campbellf942dc22011-03-15 00:06:18 +000038
39#include <xen/events.h>
40#include <asm/xen/hypercall.h>
41
42#define XENVIF_QUEUE_LENGTH 32
Wei Liub3f980b2013-08-26 12:59:38 +010043#define XENVIF_NAPI_WEIGHT 64
Ian Campbellf942dc22011-03-15 00:06:18 +000044
45int xenvif_schedulable(struct xenvif *vif)
46{
47 return netif_running(vif->dev) && netif_carrier_ok(vif->dev);
48}
49
Wei Liue1f00a692013-05-22 06:34:45 +000050static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id)
Ian Campbellf942dc22011-03-15 00:06:18 +000051{
52 struct xenvif *vif = dev_id;
53
Wei Liub3f980b2013-08-26 12:59:38 +010054 if (RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
55 napi_schedule(&vif->napi);
Ian Campbellf942dc22011-03-15 00:06:18 +000056
Wei Liue1f00a692013-05-22 06:34:45 +000057 return IRQ_HANDLED;
58}
59
Wei Liub3f980b2013-08-26 12:59:38 +010060static int xenvif_poll(struct napi_struct *napi, int budget)
61{
62 struct xenvif *vif = container_of(napi, struct xenvif, napi);
63 int work_done;
64
Wei Liu73764192013-08-26 12:59:39 +010065 work_done = xenvif_tx_action(vif, budget);
Wei Liub3f980b2013-08-26 12:59:38 +010066
67 if (work_done < budget) {
68 int more_to_do = 0;
69 unsigned long flags;
70
71 /* It is necessary to disable IRQ before calling
72 * RING_HAS_UNCONSUMED_REQUESTS. Otherwise we might
73 * lose event from the frontend.
74 *
75 * Consider:
76 * RING_HAS_UNCONSUMED_REQUESTS
77 * <frontend generates event to trigger napi_schedule>
78 * __napi_complete
79 *
80 * This handler is still in scheduled state so the
81 * event has no effect at all. After __napi_complete
82 * this handler is descheduled and cannot get
83 * scheduled again. We lose event in this case and the ring
84 * will be completely stalled.
85 */
86
87 local_irq_save(flags);
88
89 RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, more_to_do);
90 if (!more_to_do)
91 __napi_complete(napi);
92
93 local_irq_restore(flags);
94 }
95
96 return work_done;
97}
98
Wei Liue1f00a692013-05-22 06:34:45 +000099static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id)
100{
101 struct xenvif *vif = dev_id;
102
Paul Durrantca2f09f2013-12-06 16:36:07 +0000103 vif->rx_event = true;
104 xenvif_kick_thread(vif);
Ian Campbellf942dc22011-03-15 00:06:18 +0000105
106 return IRQ_HANDLED;
107}
108
Wei Liue1f00a692013-05-22 06:34:45 +0000109static irqreturn_t xenvif_interrupt(int irq, void *dev_id)
110{
111 xenvif_tx_interrupt(irq, dev_id);
112 xenvif_rx_interrupt(irq, dev_id);
113
114 return IRQ_HANDLED;
115}
116
Ian Campbellf942dc22011-03-15 00:06:18 +0000117static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
118{
119 struct xenvif *vif = netdev_priv(dev);
Paul Durrantca2f09f2013-12-06 16:36:07 +0000120 int min_slots_needed;
Ian Campbellf942dc22011-03-15 00:06:18 +0000121
122 BUG_ON(skb->dev != dev);
123
Wei Liub3f980b2013-08-26 12:59:38 +0100124 /* Drop the packet if vif is not ready */
Paul Durrantca2f09f2013-12-06 16:36:07 +0000125 if (vif->task == NULL || !xenvif_schedulable(vif))
Ian Campbellf942dc22011-03-15 00:06:18 +0000126 goto drop;
127
Paul Durrantca2f09f2013-12-06 16:36:07 +0000128 /* At best we'll need one slot for the header and one for each
129 * frag.
130 */
131 min_slots_needed = 1 + skb_shinfo(skb)->nr_frags;
Ian Campbellf942dc22011-03-15 00:06:18 +0000132
Paul Durrantca2f09f2013-12-06 16:36:07 +0000133 /* If the skb is GSO then we'll also need an extra slot for the
134 * metadata.
135 */
136 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 ||
137 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
138 min_slots_needed++;
Ian Campbellf942dc22011-03-15 00:06:18 +0000139
Paul Durrantca2f09f2013-12-06 16:36:07 +0000140 /* If the skb can't possibly fit in the remaining slots
141 * then turn off the queue to give the ring a chance to
142 * drain.
143 */
144 if (!xenvif_rx_ring_slots_available(vif, min_slots_needed))
145 xenvif_stop_queue(vif);
Ian Campbellf942dc22011-03-15 00:06:18 +0000146
Paul Durrantca2f09f2013-12-06 16:36:07 +0000147 skb_queue_tail(&vif->rx_queue, skb);
148 xenvif_kick_thread(vif);
Ian Campbellf942dc22011-03-15 00:06:18 +0000149
150 return NETDEV_TX_OK;
151
152 drop:
153 vif->dev->stats.tx_dropped++;
154 dev_kfree_skb(skb);
155 return NETDEV_TX_OK;
156}
157
Ian Campbellf942dc22011-03-15 00:06:18 +0000158static struct net_device_stats *xenvif_get_stats(struct net_device *dev)
159{
160 struct xenvif *vif = netdev_priv(dev);
161 return &vif->dev->stats;
162}
163
164static void xenvif_up(struct xenvif *vif)
165{
Wei Liub3f980b2013-08-26 12:59:38 +0100166 napi_enable(&vif->napi);
Wei Liue1f00a692013-05-22 06:34:45 +0000167 enable_irq(vif->tx_irq);
168 if (vif->tx_irq != vif->rx_irq)
169 enable_irq(vif->rx_irq);
Wei Liu73764192013-08-26 12:59:39 +0100170 xenvif_check_rx_xenvif(vif);
Ian Campbellf942dc22011-03-15 00:06:18 +0000171}
172
173static void xenvif_down(struct xenvif *vif)
174{
Wei Liub3f980b2013-08-26 12:59:38 +0100175 napi_disable(&vif->napi);
Wei Liue1f00a692013-05-22 06:34:45 +0000176 disable_irq(vif->tx_irq);
177 if (vif->tx_irq != vif->rx_irq)
178 disable_irq(vif->rx_irq);
David Vrabel3e55f8b2013-02-14 03:18:58 +0000179 del_timer_sync(&vif->credit_timeout);
Ian Campbellf942dc22011-03-15 00:06:18 +0000180}
181
182static int xenvif_open(struct net_device *dev)
183{
184 struct xenvif *vif = netdev_priv(dev);
185 if (netif_carrier_ok(dev))
186 xenvif_up(vif);
187 netif_start_queue(dev);
188 return 0;
189}
190
191static int xenvif_close(struct net_device *dev)
192{
193 struct xenvif *vif = netdev_priv(dev);
194 if (netif_carrier_ok(dev))
195 xenvif_down(vif);
196 netif_stop_queue(dev);
197 return 0;
198}
199
200static int xenvif_change_mtu(struct net_device *dev, int mtu)
201{
202 struct xenvif *vif = netdev_priv(dev);
203 int max = vif->can_sg ? 65535 - VLAN_ETH_HLEN : ETH_DATA_LEN;
204
205 if (mtu > max)
206 return -EINVAL;
207 dev->mtu = mtu;
208 return 0;
209}
210
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000211static netdev_features_t xenvif_fix_features(struct net_device *dev,
212 netdev_features_t features)
Ian Campbellf942dc22011-03-15 00:06:18 +0000213{
214 struct xenvif *vif = netdev_priv(dev);
Ian Campbellf942dc22011-03-15 00:06:18 +0000215
Michał Mirosław47103042011-04-19 03:35:06 +0000216 if (!vif->can_sg)
217 features &= ~NETIF_F_SG;
Paul Durrant82cada22013-10-16 17:50:32 +0100218 if (~(vif->gso_mask | vif->gso_prefix_mask) & GSO_BIT(TCPV4))
Michał Mirosław47103042011-04-19 03:35:06 +0000219 features &= ~NETIF_F_TSO;
Paul Durrant82cada22013-10-16 17:50:32 +0100220 if (~(vif->gso_mask | vif->gso_prefix_mask) & GSO_BIT(TCPV6))
221 features &= ~NETIF_F_TSO6;
Paul Durrant146c8a72013-10-16 17:50:28 +0100222 if (!vif->ip_csum)
Michał Mirosław47103042011-04-19 03:35:06 +0000223 features &= ~NETIF_F_IP_CSUM;
Paul Durrant146c8a72013-10-16 17:50:28 +0100224 if (!vif->ipv6_csum)
225 features &= ~NETIF_F_IPV6_CSUM;
Ian Campbellf942dc22011-03-15 00:06:18 +0000226
Michał Mirosław47103042011-04-19 03:35:06 +0000227 return features;
Ian Campbellf942dc22011-03-15 00:06:18 +0000228}
229
230static const struct xenvif_stat {
231 char name[ETH_GSTRING_LEN];
232 u16 offset;
233} xenvif_stats[] = {
234 {
235 "rx_gso_checksum_fixup",
236 offsetof(struct xenvif, rx_gso_checksum_fixup)
237 },
238};
239
240static int xenvif_get_sset_count(struct net_device *dev, int string_set)
241{
242 switch (string_set) {
243 case ETH_SS_STATS:
244 return ARRAY_SIZE(xenvif_stats);
245 default:
246 return -EINVAL;
247 }
248}
249
250static void xenvif_get_ethtool_stats(struct net_device *dev,
251 struct ethtool_stats *stats, u64 * data)
252{
253 void *vif = netdev_priv(dev);
254 int i;
255
256 for (i = 0; i < ARRAY_SIZE(xenvif_stats); i++)
257 data[i] = *(unsigned long *)(vif + xenvif_stats[i].offset);
258}
259
260static void xenvif_get_strings(struct net_device *dev, u32 stringset, u8 * data)
261{
262 int i;
263
264 switch (stringset) {
265 case ETH_SS_STATS:
266 for (i = 0; i < ARRAY_SIZE(xenvif_stats); i++)
267 memcpy(data + i * ETH_GSTRING_LEN,
268 xenvif_stats[i].name, ETH_GSTRING_LEN);
269 break;
270 }
271}
272
stephen hemminger813abbb2012-01-04 11:56:58 +0000273static const struct ethtool_ops xenvif_ethtool_ops = {
Ian Campbellf942dc22011-03-15 00:06:18 +0000274 .get_link = ethtool_op_get_link,
275
276 .get_sset_count = xenvif_get_sset_count,
277 .get_ethtool_stats = xenvif_get_ethtool_stats,
278 .get_strings = xenvif_get_strings,
279};
280
stephen hemminger813abbb2012-01-04 11:56:58 +0000281static const struct net_device_ops xenvif_netdev_ops = {
Ian Campbellf942dc22011-03-15 00:06:18 +0000282 .ndo_start_xmit = xenvif_start_xmit,
283 .ndo_get_stats = xenvif_get_stats,
284 .ndo_open = xenvif_open,
285 .ndo_stop = xenvif_close,
286 .ndo_change_mtu = xenvif_change_mtu,
Michał Mirosław47103042011-04-19 03:35:06 +0000287 .ndo_fix_features = xenvif_fix_features,
Matt Wilson4a633a62013-01-22 08:08:25 +0000288 .ndo_set_mac_address = eth_mac_addr,
289 .ndo_validate_addr = eth_validate_addr,
Ian Campbellf942dc22011-03-15 00:06:18 +0000290};
291
292struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
293 unsigned int handle)
294{
295 int err;
296 struct net_device *dev;
297 struct xenvif *vif;
298 char name[IFNAMSIZ] = {};
Wei Liub3f980b2013-08-26 12:59:38 +0100299 int i;
Ian Campbellf942dc22011-03-15 00:06:18 +0000300
301 snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
302 dev = alloc_netdev(sizeof(struct xenvif), name, ether_setup);
303 if (dev == NULL) {
Wei Liub3f980b2013-08-26 12:59:38 +0100304 pr_warn("Could not allocate netdev for %s\n", name);
Ian Campbellf942dc22011-03-15 00:06:18 +0000305 return ERR_PTR(-ENOMEM);
306 }
307
308 SET_NETDEV_DEV(dev, parent);
309
310 vif = netdev_priv(dev);
Paul Durrantac3d5ac2013-12-23 09:27:17 +0000311
312 vif->grant_copy_op = vmalloc(sizeof(struct gnttab_copy) *
313 MAX_GRANT_COPY_OPS);
314 if (vif->grant_copy_op == NULL) {
315 pr_warn("Could not allocate grant copy space for %s\n", name);
316 free_netdev(dev);
317 return ERR_PTR(-ENOMEM);
318 }
319
Ian Campbellf942dc22011-03-15 00:06:18 +0000320 vif->domid = domid;
321 vif->handle = handle;
Ian Campbellf942dc22011-03-15 00:06:18 +0000322 vif->can_sg = 1;
Paul Durrant146c8a72013-10-16 17:50:28 +0100323 vif->ip_csum = 1;
Ian Campbellf942dc22011-03-15 00:06:18 +0000324 vif->dev = dev;
Ian Campbellf942dc22011-03-15 00:06:18 +0000325
326 vif->credit_bytes = vif->remaining_credit = ~0UL;
327 vif->credit_usec = 0UL;
328 init_timer(&vif->credit_timeout);
Wei Liu059dfa62013-10-28 12:07:57 +0000329 vif->credit_window_start = get_jiffies_64();
Ian Campbellf942dc22011-03-15 00:06:18 +0000330
331 dev->netdev_ops = &xenvif_netdev_ops;
Paul Durrant146c8a72013-10-16 17:50:28 +0100332 dev->hw_features = NETIF_F_SG |
333 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
Paul Durrant82cada22013-10-16 17:50:32 +0100334 NETIF_F_TSO | NETIF_F_TSO6;
Paul Durrant7365bcf2013-10-16 17:50:30 +0100335 dev->features = dev->hw_features | NETIF_F_RXCSUM;
Ian Campbellf942dc22011-03-15 00:06:18 +0000336 SET_ETHTOOL_OPS(dev, &xenvif_ethtool_ops);
337
338 dev->tx_queue_len = XENVIF_QUEUE_LENGTH;
339
Wei Liub3f980b2013-08-26 12:59:38 +0100340 skb_queue_head_init(&vif->rx_queue);
341 skb_queue_head_init(&vif->tx_queue);
342
343 vif->pending_cons = 0;
344 vif->pending_prod = MAX_PENDING_REQS;
345 for (i = 0; i < MAX_PENDING_REQS; i++)
346 vif->pending_ring[i] = i;
347 for (i = 0; i < MAX_PENDING_REQS; i++)
348 vif->mmap_pages[i] = NULL;
349
Ian Campbellf942dc22011-03-15 00:06:18 +0000350 /*
351 * Initialise a dummy MAC address. We choose the numerically
352 * largest non-broadcast address to prevent the address getting
353 * stolen by an Ethernet bridge for STP purposes.
354 * (FE:FF:FF:FF:FF:FF)
355 */
356 memset(dev->dev_addr, 0xFF, ETH_ALEN);
357 dev->dev_addr[0] &= ~0x01;
358
Wei Liub3f980b2013-08-26 12:59:38 +0100359 netif_napi_add(dev, &vif->napi, xenvif_poll, XENVIF_NAPI_WEIGHT);
360
Ian Campbellf942dc22011-03-15 00:06:18 +0000361 netif_carrier_off(dev);
362
363 err = register_netdev(dev);
364 if (err) {
365 netdev_warn(dev, "Could not register device: err=%d\n", err);
366 free_netdev(dev);
367 return ERR_PTR(err);
368 }
369
370 netdev_dbg(dev, "Successfully created xenvif\n");
Paul Durrant279f4382013-09-17 17:46:08 +0100371
372 __module_get(THIS_MODULE);
373
Ian Campbellf942dc22011-03-15 00:06:18 +0000374 return vif;
375}
376
377int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
Wei Liue1f00a692013-05-22 06:34:45 +0000378 unsigned long rx_ring_ref, unsigned int tx_evtchn,
379 unsigned int rx_evtchn)
Ian Campbellf942dc22011-03-15 00:06:18 +0000380{
Paul Durrant67fa3662013-12-03 14:06:25 +0000381 struct task_struct *task;
Ian Campbellf942dc22011-03-15 00:06:18 +0000382 int err = -ENOMEM;
383
Paul Durrant67fa3662013-12-03 14:06:25 +0000384 BUG_ON(vif->tx_irq);
385 BUG_ON(vif->task);
Ian Campbellf942dc22011-03-15 00:06:18 +0000386
Wei Liu73764192013-08-26 12:59:39 +0100387 err = xenvif_map_frontend_rings(vif, tx_ring_ref, rx_ring_ref);
Ian Campbellf942dc22011-03-15 00:06:18 +0000388 if (err < 0)
389 goto err;
390
Paul Durrantca2f09f2013-12-06 16:36:07 +0000391 init_waitqueue_head(&vif->wq);
392
Wei Liue1f00a692013-05-22 06:34:45 +0000393 if (tx_evtchn == rx_evtchn) {
394 /* feature-split-event-channels == 0 */
395 err = bind_interdomain_evtchn_to_irqhandler(
396 vif->domid, tx_evtchn, xenvif_interrupt, 0,
397 vif->dev->name, vif);
398 if (err < 0)
399 goto err_unmap;
400 vif->tx_irq = vif->rx_irq = err;
401 disable_irq(vif->tx_irq);
402 } else {
403 /* feature-split-event-channels == 1 */
404 snprintf(vif->tx_irq_name, sizeof(vif->tx_irq_name),
405 "%s-tx", vif->dev->name);
406 err = bind_interdomain_evtchn_to_irqhandler(
407 vif->domid, tx_evtchn, xenvif_tx_interrupt, 0,
408 vif->tx_irq_name, vif);
409 if (err < 0)
410 goto err_unmap;
411 vif->tx_irq = err;
412 disable_irq(vif->tx_irq);
413
414 snprintf(vif->rx_irq_name, sizeof(vif->rx_irq_name),
415 "%s-rx", vif->dev->name);
416 err = bind_interdomain_evtchn_to_irqhandler(
417 vif->domid, rx_evtchn, xenvif_rx_interrupt, 0,
418 vif->rx_irq_name, vif);
419 if (err < 0)
420 goto err_tx_unbind;
421 vif->rx_irq = err;
422 disable_irq(vif->rx_irq);
423 }
Ian Campbellf942dc22011-03-15 00:06:18 +0000424
Paul Durrant67fa3662013-12-03 14:06:25 +0000425 task = kthread_create(xenvif_kthread,
426 (void *)vif, "%s", vif->dev->name);
427 if (IS_ERR(task)) {
Wei Liub3f980b2013-08-26 12:59:38 +0100428 pr_warn("Could not allocate kthread for %s\n", vif->dev->name);
Paul Durrant67fa3662013-12-03 14:06:25 +0000429 err = PTR_ERR(task);
Wei Liub3f980b2013-08-26 12:59:38 +0100430 goto err_rx_unbind;
431 }
Ian Campbellf942dc22011-03-15 00:06:18 +0000432
Paul Durrant67fa3662013-12-03 14:06:25 +0000433 vif->task = task;
434
Ian Campbellf942dc22011-03-15 00:06:18 +0000435 rtnl_lock();
Michał Mirosław47103042011-04-19 03:35:06 +0000436 if (!vif->can_sg && vif->dev->mtu > ETH_DATA_LEN)
437 dev_set_mtu(vif->dev, ETH_DATA_LEN);
438 netdev_update_features(vif->dev);
439 netif_carrier_on(vif->dev);
David Vrabeld0e5d832011-09-30 06:37:51 +0000440 if (netif_running(vif->dev))
441 xenvif_up(vif);
Ian Campbellf942dc22011-03-15 00:06:18 +0000442 rtnl_unlock();
443
Wei Liub3f980b2013-08-26 12:59:38 +0100444 wake_up_process(vif->task);
445
Ian Campbellf942dc22011-03-15 00:06:18 +0000446 return 0;
Wei Liub3f980b2013-08-26 12:59:38 +0100447
448err_rx_unbind:
449 unbind_from_irqhandler(vif->rx_irq, vif);
450 vif->rx_irq = 0;
Wei Liue1f00a692013-05-22 06:34:45 +0000451err_tx_unbind:
452 unbind_from_irqhandler(vif->tx_irq, vif);
453 vif->tx_irq = 0;
Ian Campbellf942dc22011-03-15 00:06:18 +0000454err_unmap:
Wei Liu73764192013-08-26 12:59:39 +0100455 xenvif_unmap_frontend_rings(vif);
Ian Campbellf942dc22011-03-15 00:06:18 +0000456err:
Wei Liub103f352013-05-16 23:26:11 +0000457 module_put(THIS_MODULE);
Ian Campbellf942dc22011-03-15 00:06:18 +0000458 return err;
459}
460
Ian Campbell488562862013-02-06 23:41:35 +0000461void xenvif_carrier_off(struct xenvif *vif)
Ian Campbellf942dc22011-03-15 00:06:18 +0000462{
463 struct net_device *dev = vif->dev;
Ian Campbell488562862013-02-06 23:41:35 +0000464
465 rtnl_lock();
466 netif_carrier_off(dev); /* discard queued packets */
467 if (netif_running(dev))
468 xenvif_down(vif);
469 rtnl_unlock();
Ian Campbell488562862013-02-06 23:41:35 +0000470}
471
472void xenvif_disconnect(struct xenvif *vif)
473{
474 if (netif_carrier_ok(vif->dev))
475 xenvif_carrier_off(vif);
Ian Campbellf942dc22011-03-15 00:06:18 +0000476
Paul Durrant67fa3662013-12-03 14:06:25 +0000477 if (vif->task) {
David Vrabeldb739ef2013-11-21 15:26:09 +0000478 kthread_stop(vif->task);
Paul Durrant67fa3662013-12-03 14:06:25 +0000479 vif->task = NULL;
480 }
David Vrabeldb739ef2013-11-21 15:26:09 +0000481
Wei Liue1f00a692013-05-22 06:34:45 +0000482 if (vif->tx_irq) {
483 if (vif->tx_irq == vif->rx_irq)
484 unbind_from_irqhandler(vif->tx_irq, vif);
485 else {
486 unbind_from_irqhandler(vif->tx_irq, vif);
487 unbind_from_irqhandler(vif->rx_irq, vif);
488 }
Paul Durrant279f4382013-09-17 17:46:08 +0100489 vif->tx_irq = 0;
Wei Liub103f352013-05-16 23:26:11 +0000490 }
Ian Campbellf942dc22011-03-15 00:06:18 +0000491
Paul Durrant279f4382013-09-17 17:46:08 +0100492 xenvif_unmap_frontend_rings(vif);
493}
494
495void xenvif_free(struct xenvif *vif)
496{
Wei Liub3f980b2013-08-26 12:59:38 +0100497 netif_napi_del(&vif->napi);
498
Ian Campbellf942dc22011-03-15 00:06:18 +0000499 unregister_netdev(vif->dev);
500
Paul Durrantac3d5ac2013-12-23 09:27:17 +0000501 vfree(vif->grant_copy_op);
Ian Campbellf942dc22011-03-15 00:06:18 +0000502 free_netdev(vif->dev);
Wei Liub103f352013-05-16 23:26:11 +0000503
Paul Durrant279f4382013-09-17 17:46:08 +0100504 module_put(THIS_MODULE);
Ian Campbellf942dc22011-03-15 00:06:18 +0000505}