2 * Common framework for low-level network console, dump, and debugger code
4 * Sep 8 2003 Matt Mackall <mpm@selenic.com>
6 * based on the netconsole code from:
8 * Copyright (C) 2001 Ingo Molnar <mingo@redhat.com>
9 * Copyright (C) 2002 Red Hat, Inc.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/moduleparam.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/string.h>
18 #include <linux/if_arp.h>
19 #include <linux/inetdevice.h>
20 #include <linux/inet.h>
21 #include <linux/interrupt.h>
22 #include <linux/netpoll.h>
23 #include <linux/sched.h>
24 #include <linux/delay.h>
25 #include <linux/rcupdate.h>
26 #include <linux/workqueue.h>
27 #include <linux/slab.h>
28 #include <linux/export.h>
31 #include <asm/unaligned.h>
32 #include <trace/events/napi.h>
35 * We maintain a small pool of fully-sized skbs, to make sure the
36 * message gets out even in extreme OOM situations.
39 #define MAX_UDP_CHUNK 1460
42 static struct sk_buff_head skb_pool
;
44 static atomic_t trapped
;
46 #define USEC_PER_POLL 50
47 #define NETPOLL_RX_ENABLED 1
48 #define NETPOLL_RX_DROP 2
50 #define MAX_SKB_SIZE \
51 (sizeof(struct ethhdr) + \
52 sizeof(struct iphdr) + \
53 sizeof(struct udphdr) + \
56 static void zap_completion_queue(void);
57 static void netpoll_arp_reply(struct sk_buff
*skb
, struct netpoll_info
*npinfo
);
59 static unsigned int carrier_timeout
= 4;
60 module_param(carrier_timeout
, uint
, 0644);
62 #define np_info(np, fmt, ...) \
63 pr_info("%s: " fmt, np->name, ##__VA_ARGS__)
64 #define np_err(np, fmt, ...) \
65 pr_err("%s: " fmt, np->name, ##__VA_ARGS__)
66 #define np_notice(np, fmt, ...) \
67 pr_notice("%s: " fmt, np->name, ##__VA_ARGS__)
69 static void queue_process(struct work_struct
*work
)
71 struct netpoll_info
*npinfo
=
72 container_of(work
, struct netpoll_info
, tx_work
.work
);
76 while ((skb
= skb_dequeue(&npinfo
->txq
))) {
77 struct net_device
*dev
= skb
->dev
;
78 const struct net_device_ops
*ops
= dev
->netdev_ops
;
79 struct netdev_queue
*txq
;
81 if (!netif_device_present(dev
) || !netif_running(dev
)) {
86 txq
= netdev_get_tx_queue(dev
, skb_get_queue_mapping(skb
));
88 local_irq_save(flags
);
89 __netif_tx_lock(txq
, smp_processor_id());
90 if (netif_xmit_frozen_or_stopped(txq
) ||
91 ops
->ndo_start_xmit(skb
, dev
) != NETDEV_TX_OK
) {
92 skb_queue_head(&npinfo
->txq
, skb
);
93 __netif_tx_unlock(txq
);
94 local_irq_restore(flags
);
96 schedule_delayed_work(&npinfo
->tx_work
, HZ
/10);
99 __netif_tx_unlock(txq
);
100 local_irq_restore(flags
);
104 static __sum16
checksum_udp(struct sk_buff
*skb
, struct udphdr
*uh
,
105 unsigned short ulen
, __be32 saddr
, __be32 daddr
)
109 if (uh
->check
== 0 || skb_csum_unnecessary(skb
))
112 psum
= csum_tcpudp_nofold(saddr
, daddr
, ulen
, IPPROTO_UDP
, 0);
114 if (skb
->ip_summed
== CHECKSUM_COMPLETE
&&
115 !csum_fold(csum_add(psum
, skb
->csum
)))
120 return __skb_checksum_complete(skb
);
124 * Check whether delayed processing was scheduled for our NIC. If so,
125 * we attempt to grab the poll lock and use ->poll() to pump the card.
126 * If this fails, either we've recursed in ->poll() or it's already
127 * running on another CPU.
129 * Note: we don't mask interrupts with this lock because we're using
130 * trylock here and interrupts are already disabled in the softirq
131 * case. Further, we test the poll_owner to avoid recursion on UP
132 * systems where the lock doesn't exist.
134 * In cases where there is bi-directional communications, reading only
135 * one message at a time can lead to packets being dropped by the
136 * network adapter, forcing superfluous retries and possibly timeouts.
137 * Thus, we set our budget to greater than 1.
139 static int poll_one_napi(struct netpoll_info
*npinfo
,
140 struct napi_struct
*napi
, int budget
)
144 /* net_rx_action's ->poll() invocations and our's are
145 * synchronized by this test which is only made while
146 * holding the napi->poll_lock.
148 if (!test_bit(NAPI_STATE_SCHED
, &napi
->state
))
151 npinfo
->rx_flags
|= NETPOLL_RX_DROP
;
152 atomic_inc(&trapped
);
153 set_bit(NAPI_STATE_NPSVC
, &napi
->state
);
155 work
= napi
->poll(napi
, budget
);
156 trace_napi_poll(napi
);
158 clear_bit(NAPI_STATE_NPSVC
, &napi
->state
);
159 atomic_dec(&trapped
);
160 npinfo
->rx_flags
&= ~NETPOLL_RX_DROP
;
162 return budget
- work
;
165 static void poll_napi(struct net_device
*dev
)
167 struct napi_struct
*napi
;
170 list_for_each_entry(napi
, &dev
->napi_list
, dev_list
) {
171 if (napi
->poll_owner
!= smp_processor_id() &&
172 spin_trylock(&napi
->poll_lock
)) {
173 budget
= poll_one_napi(rcu_dereference_bh(dev
->npinfo
),
175 spin_unlock(&napi
->poll_lock
);
183 static void service_arp_queue(struct netpoll_info
*npi
)
188 while ((skb
= skb_dequeue(&npi
->arp_tx
)))
189 netpoll_arp_reply(skb
, npi
);
193 static void netpoll_poll_dev(struct net_device
*dev
)
195 const struct net_device_ops
*ops
;
196 struct netpoll_info
*ni
= rcu_dereference_bh(dev
->npinfo
);
198 if (!dev
|| !netif_running(dev
))
201 ops
= dev
->netdev_ops
;
202 if (!ops
->ndo_poll_controller
)
205 /* Process pending work on NIC */
206 ops
->ndo_poll_controller(dev
);
210 if (dev
->flags
& IFF_SLAVE
) {
212 struct net_device
*bond_dev
= dev
->master
;
214 struct netpoll_info
*bond_ni
= rcu_dereference_bh(bond_dev
->npinfo
);
215 while ((skb
= skb_dequeue(&ni
->arp_tx
))) {
217 skb_queue_tail(&bond_ni
->arp_tx
, skb
);
222 service_arp_queue(ni
);
224 zap_completion_queue();
227 static void refill_skbs(void)
232 spin_lock_irqsave(&skb_pool
.lock
, flags
);
233 while (skb_pool
.qlen
< MAX_SKBS
) {
234 skb
= alloc_skb(MAX_SKB_SIZE
, GFP_ATOMIC
);
238 __skb_queue_tail(&skb_pool
, skb
);
240 spin_unlock_irqrestore(&skb_pool
.lock
, flags
);
243 static void zap_completion_queue(void)
246 struct softnet_data
*sd
= &get_cpu_var(softnet_data
);
248 if (sd
->completion_queue
) {
249 struct sk_buff
*clist
;
251 local_irq_save(flags
);
252 clist
= sd
->completion_queue
;
253 sd
->completion_queue
= NULL
;
254 local_irq_restore(flags
);
256 while (clist
!= NULL
) {
257 struct sk_buff
*skb
= clist
;
259 if (skb
->destructor
) {
260 atomic_inc(&skb
->users
);
261 dev_kfree_skb_any(skb
); /* put this one back */
268 put_cpu_var(softnet_data
);
271 static struct sk_buff
*find_skb(struct netpoll
*np
, int len
, int reserve
)
276 zap_completion_queue();
280 skb
= alloc_skb(len
, GFP_ATOMIC
);
282 skb
= skb_dequeue(&skb_pool
);
286 netpoll_poll_dev(np
->dev
);
292 atomic_set(&skb
->users
, 1);
293 skb_reserve(skb
, reserve
);
297 static int netpoll_owner_active(struct net_device
*dev
)
299 struct napi_struct
*napi
;
301 list_for_each_entry(napi
, &dev
->napi_list
, dev_list
) {
302 if (napi
->poll_owner
== smp_processor_id())
308 /* call with IRQ disabled */
309 void netpoll_send_skb_on_dev(struct netpoll
*np
, struct sk_buff
*skb
,
310 struct net_device
*dev
)
312 int status
= NETDEV_TX_BUSY
;
314 const struct net_device_ops
*ops
= dev
->netdev_ops
;
315 /* It is up to the caller to keep npinfo alive. */
316 struct netpoll_info
*npinfo
;
318 WARN_ON_ONCE(!irqs_disabled());
320 npinfo
= rcu_dereference_bh(np
->dev
->npinfo
);
321 if (!npinfo
|| !netif_running(dev
) || !netif_device_present(dev
)) {
326 /* don't get messages out of order, and no recursion */
327 if (skb_queue_len(&npinfo
->txq
) == 0 && !netpoll_owner_active(dev
)) {
328 struct netdev_queue
*txq
;
330 txq
= netdev_get_tx_queue(dev
, skb_get_queue_mapping(skb
));
332 /* try until next clock tick */
333 for (tries
= jiffies_to_usecs(1)/USEC_PER_POLL
;
334 tries
> 0; --tries
) {
335 if (__netif_tx_trylock(txq
)) {
336 if (!netif_xmit_stopped(txq
)) {
337 status
= ops
->ndo_start_xmit(skb
, dev
);
338 if (status
== NETDEV_TX_OK
)
339 txq_trans_update(txq
);
341 __netif_tx_unlock(txq
);
343 if (status
== NETDEV_TX_OK
)
348 /* tickle device maybe there is some cleanup */
349 netpoll_poll_dev(np
->dev
);
351 udelay(USEC_PER_POLL
);
354 WARN_ONCE(!irqs_disabled(),
355 "netpoll_send_skb_on_dev(): %s enabled interrupts in poll (%pF)\n",
356 dev
->name
, ops
->ndo_start_xmit
);
360 if (status
!= NETDEV_TX_OK
) {
361 skb_queue_tail(&npinfo
->txq
, skb
);
362 schedule_delayed_work(&npinfo
->tx_work
,0);
365 EXPORT_SYMBOL(netpoll_send_skb_on_dev
);
367 void netpoll_send_udp(struct netpoll
*np
, const char *msg
, int len
)
369 int total_len
, ip_len
, udp_len
;
375 udp_len
= len
+ sizeof(*udph
);
376 ip_len
= udp_len
+ sizeof(*iph
);
377 total_len
= ip_len
+ LL_RESERVED_SPACE(np
->dev
);
379 skb
= find_skb(np
, total_len
+ np
->dev
->needed_tailroom
,
384 skb_copy_to_linear_data(skb
, msg
, len
);
387 skb_push(skb
, sizeof(*udph
));
388 skb_reset_transport_header(skb
);
390 udph
->source
= htons(np
->local_port
);
391 udph
->dest
= htons(np
->remote_port
);
392 udph
->len
= htons(udp_len
);
394 udph
->check
= csum_tcpudp_magic(np
->local_ip
,
396 udp_len
, IPPROTO_UDP
,
397 csum_partial(udph
, udp_len
, 0));
398 if (udph
->check
== 0)
399 udph
->check
= CSUM_MANGLED_0
;
401 skb_push(skb
, sizeof(*iph
));
402 skb_reset_network_header(skb
);
405 /* iph->version = 4; iph->ihl = 5; */
406 put_unaligned(0x45, (unsigned char *)iph
);
408 put_unaligned(htons(ip_len
), &(iph
->tot_len
));
412 iph
->protocol
= IPPROTO_UDP
;
414 put_unaligned(np
->local_ip
, &(iph
->saddr
));
415 put_unaligned(np
->remote_ip
, &(iph
->daddr
));
416 iph
->check
= ip_fast_csum((unsigned char *)iph
, iph
->ihl
);
418 eth
= (struct ethhdr
*) skb_push(skb
, ETH_HLEN
);
419 skb_reset_mac_header(skb
);
420 skb
->protocol
= eth
->h_proto
= htons(ETH_P_IP
);
421 memcpy(eth
->h_source
, np
->dev
->dev_addr
, ETH_ALEN
);
422 memcpy(eth
->h_dest
, np
->remote_mac
, ETH_ALEN
);
426 netpoll_send_skb(np
, skb
);
428 EXPORT_SYMBOL(netpoll_send_udp
);
430 static void netpoll_arp_reply(struct sk_buff
*skb
, struct netpoll_info
*npinfo
)
433 unsigned char *arp_ptr
;
434 int size
, type
= ARPOP_REPLY
, ptype
= ETH_P_ARP
;
437 struct sk_buff
*send_skb
;
438 struct netpoll
*np
, *tmp
;
443 if (list_empty(&npinfo
->rx_np
))
446 /* Before checking the packet, we do some early
447 inspection whether this is interesting at all */
448 spin_lock_irqsave(&npinfo
->rx_lock
, flags
);
449 list_for_each_entry_safe(np
, tmp
, &npinfo
->rx_np
, rx
) {
450 if (np
->dev
== skb
->dev
)
453 spin_unlock_irqrestore(&npinfo
->rx_lock
, flags
);
455 /* No netpoll struct is using this dev */
459 /* No arp on this interface */
460 if (skb
->dev
->flags
& IFF_NOARP
)
463 if (!pskb_may_pull(skb
, arp_hdr_len(skb
->dev
)))
466 skb_reset_network_header(skb
);
467 skb_reset_transport_header(skb
);
470 if ((arp
->ar_hrd
!= htons(ARPHRD_ETHER
) &&
471 arp
->ar_hrd
!= htons(ARPHRD_IEEE802
)) ||
472 arp
->ar_pro
!= htons(ETH_P_IP
) ||
473 arp
->ar_op
!= htons(ARPOP_REQUEST
))
476 arp_ptr
= (unsigned char *)(arp
+1);
477 /* save the location of the src hw addr */
479 arp_ptr
+= skb
->dev
->addr_len
;
480 memcpy(&sip
, arp_ptr
, 4);
482 /* If we actually cared about dst hw addr,
483 it would get copied here */
484 arp_ptr
+= skb
->dev
->addr_len
;
485 memcpy(&tip
, arp_ptr
, 4);
487 /* Should we ignore arp? */
488 if (ipv4_is_loopback(tip
) || ipv4_is_multicast(tip
))
491 size
= arp_hdr_len(skb
->dev
);
493 spin_lock_irqsave(&npinfo
->rx_lock
, flags
);
494 list_for_each_entry_safe(np
, tmp
, &npinfo
->rx_np
, rx
) {
495 if (tip
!= np
->local_ip
)
498 hlen
= LL_RESERVED_SPACE(np
->dev
);
499 tlen
= np
->dev
->needed_tailroom
;
500 send_skb
= find_skb(np
, size
+ hlen
+ tlen
, hlen
);
504 skb_reset_network_header(send_skb
);
505 arp
= (struct arphdr
*) skb_put(send_skb
, size
);
506 send_skb
->dev
= skb
->dev
;
507 send_skb
->protocol
= htons(ETH_P_ARP
);
509 /* Fill the device header for the ARP frame */
510 if (dev_hard_header(send_skb
, skb
->dev
, ptype
,
511 sha
, np
->dev
->dev_addr
,
512 send_skb
->len
) < 0) {
518 * Fill out the arp protocol part.
520 * we only support ethernet device type,
521 * which (according to RFC 1390) should
522 * always equal 1 (Ethernet).
525 arp
->ar_hrd
= htons(np
->dev
->type
);
526 arp
->ar_pro
= htons(ETH_P_IP
);
527 arp
->ar_hln
= np
->dev
->addr_len
;
529 arp
->ar_op
= htons(type
);
531 arp_ptr
= (unsigned char *)(arp
+ 1);
532 memcpy(arp_ptr
, np
->dev
->dev_addr
, np
->dev
->addr_len
);
533 arp_ptr
+= np
->dev
->addr_len
;
534 memcpy(arp_ptr
, &tip
, 4);
536 memcpy(arp_ptr
, sha
, np
->dev
->addr_len
);
537 arp_ptr
+= np
->dev
->addr_len
;
538 memcpy(arp_ptr
, &sip
, 4);
540 netpoll_send_skb(np
, send_skb
);
542 /* If there are several rx_hooks for the same address,
543 we're fine by sending a single reply */
546 spin_unlock_irqrestore(&npinfo
->rx_lock
, flags
);
549 int __netpoll_rx(struct sk_buff
*skb
, struct netpoll_info
*npinfo
)
551 int proto
, len
, ulen
;
553 const struct iphdr
*iph
;
555 struct netpoll
*np
, *tmp
;
557 if (list_empty(&npinfo
->rx_np
))
560 if (skb
->dev
->type
!= ARPHRD_ETHER
)
563 /* check if netpoll clients need ARP */
564 if (skb
->protocol
== htons(ETH_P_ARP
) &&
565 atomic_read(&trapped
)) {
566 skb_queue_tail(&npinfo
->arp_tx
, skb
);
570 proto
= ntohs(eth_hdr(skb
)->h_proto
);
571 if (proto
!= ETH_P_IP
)
573 if (skb
->pkt_type
== PACKET_OTHERHOST
)
578 if (!pskb_may_pull(skb
, sizeof(struct iphdr
)))
580 iph
= (struct iphdr
*)skb
->data
;
581 if (iph
->ihl
< 5 || iph
->version
!= 4)
583 if (!pskb_may_pull(skb
, iph
->ihl
*4))
585 iph
= (struct iphdr
*)skb
->data
;
586 if (ip_fast_csum((u8
*)iph
, iph
->ihl
) != 0)
589 len
= ntohs(iph
->tot_len
);
590 if (skb
->len
< len
|| len
< iph
->ihl
*4)
594 * Our transport medium may have padded the buffer out.
595 * Now We trim to the true length of the frame.
597 if (pskb_trim_rcsum(skb
, len
))
600 iph
= (struct iphdr
*)skb
->data
;
601 if (iph
->protocol
!= IPPROTO_UDP
)
605 uh
= (struct udphdr
*)(((char *)iph
) + iph
->ihl
*4);
606 ulen
= ntohs(uh
->len
);
610 if (checksum_udp(skb
, uh
, ulen
, iph
->saddr
, iph
->daddr
))
613 list_for_each_entry_safe(np
, tmp
, &npinfo
->rx_np
, rx
) {
614 if (np
->local_ip
&& np
->local_ip
!= iph
->daddr
)
616 if (np
->remote_ip
&& np
->remote_ip
!= iph
->saddr
)
618 if (np
->local_port
&& np
->local_port
!= ntohs(uh
->dest
))
621 np
->rx_hook(np
, ntohs(uh
->source
),
623 ulen
- sizeof(struct udphdr
));
634 if (atomic_read(&trapped
)) {
642 void netpoll_print_options(struct netpoll
*np
)
644 np_info(np
, "local port %d\n", np
->local_port
);
645 np_info(np
, "local IP %pI4\n", &np
->local_ip
);
646 np_info(np
, "interface '%s'\n", np
->dev_name
);
647 np_info(np
, "remote port %d\n", np
->remote_port
);
648 np_info(np
, "remote IP %pI4\n", &np
->remote_ip
);
649 np_info(np
, "remote ethernet address %pM\n", np
->remote_mac
);
651 EXPORT_SYMBOL(netpoll_print_options
);
653 int netpoll_parse_options(struct netpoll
*np
, char *opt
)
655 char *cur
=opt
, *delim
;
658 if ((delim
= strchr(cur
, '@')) == NULL
)
661 np
->local_port
= simple_strtol(cur
, NULL
, 10);
667 if ((delim
= strchr(cur
, '/')) == NULL
)
670 np
->local_ip
= in_aton(cur
);
676 /* parse out dev name */
677 if ((delim
= strchr(cur
, ',')) == NULL
)
680 strlcpy(np
->dev_name
, cur
, sizeof(np
->dev_name
));
687 if ((delim
= strchr(cur
, '@')) == NULL
)
690 if (*cur
== ' ' || *cur
== '\t')
691 np_info(np
, "warning: whitespace is not allowed\n");
692 np
->remote_port
= simple_strtol(cur
, NULL
, 10);
698 if ((delim
= strchr(cur
, '/')) == NULL
)
701 np
->remote_ip
= in_aton(cur
);
706 if (!mac_pton(cur
, np
->remote_mac
))
710 netpoll_print_options(np
);
715 np_info(np
, "couldn't parse config at '%s'!\n", cur
);
718 EXPORT_SYMBOL(netpoll_parse_options
);
720 int __netpoll_setup(struct netpoll
*np
, struct net_device
*ndev
, gfp_t gfp
)
722 struct netpoll_info
*npinfo
;
723 const struct net_device_ops
*ops
;
728 strlcpy(np
->dev_name
, ndev
->name
, IFNAMSIZ
);
730 if ((ndev
->priv_flags
& IFF_DISABLE_NETPOLL
) ||
731 !ndev
->netdev_ops
->ndo_poll_controller
) {
732 np_err(np
, "%s doesn't support polling, aborting\n",
739 npinfo
= kmalloc(sizeof(*npinfo
), gfp
);
745 npinfo
->rx_flags
= 0;
746 INIT_LIST_HEAD(&npinfo
->rx_np
);
748 spin_lock_init(&npinfo
->rx_lock
);
749 skb_queue_head_init(&npinfo
->arp_tx
);
750 skb_queue_head_init(&npinfo
->txq
);
751 INIT_DELAYED_WORK(&npinfo
->tx_work
, queue_process
);
753 atomic_set(&npinfo
->refcnt
, 1);
755 ops
= np
->dev
->netdev_ops
;
756 if (ops
->ndo_netpoll_setup
) {
757 err
= ops
->ndo_netpoll_setup(ndev
, npinfo
, gfp
);
762 npinfo
= ndev
->npinfo
;
763 atomic_inc(&npinfo
->refcnt
);
766 npinfo
->netpoll
= np
;
769 spin_lock_irqsave(&npinfo
->rx_lock
, flags
);
770 npinfo
->rx_flags
|= NETPOLL_RX_ENABLED
;
771 list_add_tail(&np
->rx
, &npinfo
->rx_np
);
772 spin_unlock_irqrestore(&npinfo
->rx_lock
, flags
);
775 /* last thing to do is link it to the net device structure */
776 rcu_assign_pointer(ndev
->npinfo
, npinfo
);
785 EXPORT_SYMBOL_GPL(__netpoll_setup
);
787 int netpoll_setup(struct netpoll
*np
)
789 struct net_device
*ndev
= NULL
;
790 struct in_device
*in_dev
;
794 ndev
= dev_get_by_name(&init_net
, np
->dev_name
);
796 np_err(np
, "%s doesn't exist, aborting\n", np
->dev_name
);
801 np_err(np
, "%s is a slave device, aborting\n", np
->dev_name
);
806 if (!netif_running(ndev
)) {
807 unsigned long atmost
, atleast
;
809 np_info(np
, "device %s not up yet, forcing it\n", np
->dev_name
);
812 err
= dev_open(ndev
);
816 np_err(np
, "failed to open %s\n", ndev
->name
);
820 atleast
= jiffies
+ HZ
/10;
821 atmost
= jiffies
+ carrier_timeout
* HZ
;
822 while (!netif_carrier_ok(ndev
)) {
823 if (time_after(jiffies
, atmost
)) {
824 np_notice(np
, "timeout waiting for carrier\n");
830 /* If carrier appears to come up instantly, we don't
831 * trust it and pause so that we don't pump all our
832 * queued console messages into the bitbucket.
835 if (time_before(jiffies
, atleast
)) {
836 np_notice(np
, "carrier detect appears untrustworthy, waiting 4 seconds\n");
843 in_dev
= __in_dev_get_rcu(ndev
);
845 if (!in_dev
|| !in_dev
->ifa_list
) {
847 np_err(np
, "no IP address for %s, aborting\n",
853 np
->local_ip
= in_dev
->ifa_list
->ifa_local
;
855 np_info(np
, "local IP %pI4\n", &np
->local_ip
);
858 /* fill up the skb queue */
862 err
= __netpoll_setup(np
, ndev
, GFP_KERNEL
);
874 EXPORT_SYMBOL(netpoll_setup
);
876 static int __init
netpoll_init(void)
878 skb_queue_head_init(&skb_pool
);
881 core_initcall(netpoll_init
);
883 static void rcu_cleanup_netpoll_info(struct rcu_head
*rcu_head
)
885 struct netpoll_info
*npinfo
=
886 container_of(rcu_head
, struct netpoll_info
, rcu
);
888 skb_queue_purge(&npinfo
->arp_tx
);
889 skb_queue_purge(&npinfo
->txq
);
891 /* we can't call cancel_delayed_work_sync here, as we are in softirq */
892 cancel_delayed_work(&npinfo
->tx_work
);
894 /* clean after last, unfinished work */
895 __skb_queue_purge(&npinfo
->txq
);
896 /* now cancel it again */
897 cancel_delayed_work(&npinfo
->tx_work
);
901 void __netpoll_cleanup(struct netpoll
*np
)
903 struct netpoll_info
*npinfo
;
906 npinfo
= np
->dev
->npinfo
;
910 if (!list_empty(&npinfo
->rx_np
)) {
911 spin_lock_irqsave(&npinfo
->rx_lock
, flags
);
913 if (list_empty(&npinfo
->rx_np
))
914 npinfo
->rx_flags
&= ~NETPOLL_RX_ENABLED
;
915 spin_unlock_irqrestore(&npinfo
->rx_lock
, flags
);
918 if (atomic_dec_and_test(&npinfo
->refcnt
)) {
919 const struct net_device_ops
*ops
;
921 ops
= np
->dev
->netdev_ops
;
922 if (ops
->ndo_netpoll_cleanup
)
923 ops
->ndo_netpoll_cleanup(np
->dev
);
925 RCU_INIT_POINTER(np
->dev
->npinfo
, NULL
);
926 call_rcu_bh(&npinfo
->rcu
, rcu_cleanup_netpoll_info
);
929 EXPORT_SYMBOL_GPL(__netpoll_cleanup
);
931 static void rcu_cleanup_netpoll(struct rcu_head
*rcu_head
)
933 struct netpoll
*np
= container_of(rcu_head
, struct netpoll
, rcu
);
935 __netpoll_cleanup(np
);
939 void __netpoll_free_rcu(struct netpoll
*np
)
941 call_rcu_bh(&np
->rcu
, rcu_cleanup_netpoll
);
943 EXPORT_SYMBOL_GPL(__netpoll_free_rcu
);
945 void netpoll_cleanup(struct netpoll
*np
)
951 __netpoll_cleanup(np
);
957 EXPORT_SYMBOL(netpoll_cleanup
);
959 int netpoll_trap(void)
961 return atomic_read(&trapped
);
963 EXPORT_SYMBOL(netpoll_trap
);
965 void netpoll_set_trap(int trap
)
968 atomic_inc(&trapped
);
970 atomic_dec(&trapped
);
972 EXPORT_SYMBOL(netpoll_set_trap
);
This page took 0.050355 seconds and 5 git commands to generate.