netpoll.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Common code for low-level network console, dump, and debugger code
  3. *
  4. * Derived from netconsole, kgdb-over-ethernet, and netdump patches
  5. */
  6. #ifndef _LINUX_NETPOLL_H
  7. #define _LINUX_NETPOLL_H
  8. #include <linux/netdevice.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/rcupdate.h>
  11. #include <linux/list.h>
  12. union inet_addr {
  13. __u32 all[4];
  14. __be32 ip;
  15. __be32 ip6[4];
  16. struct in_addr in;
  17. struct in6_addr in6;
  18. };
  19. struct netpoll {
  20. struct net_device *dev;
  21. char dev_name[IFNAMSIZ];
  22. const char *name;
  23. void (*rx_skb_hook)(struct netpoll *np, int source, struct sk_buff *skb,
  24. int offset, int len);
  25. union inet_addr local_ip, remote_ip;
  26. bool ipv6;
  27. u16 local_port, remote_port;
  28. u8 remote_mac[ETH_ALEN];
  29. struct list_head rx; /* rx_np list element */
  30. struct work_struct cleanup_work;
  31. };
  32. struct netpoll_info {
  33. atomic_t refcnt;
  34. unsigned long rx_flags;
  35. spinlock_t rx_lock;
  36. struct semaphore dev_lock;
  37. struct list_head rx_np; /* netpolls that registered an rx_skb_hook */
  38. struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */
  39. struct sk_buff_head txq;
  40. struct delayed_work tx_work;
  41. struct netpoll *netpoll;
  42. struct rcu_head rcu;
  43. };
  44. #ifdef CONFIG_NETPOLL
  45. extern void netpoll_rx_disable(struct net_device *dev);
  46. extern void netpoll_rx_enable(struct net_device *dev);
  47. #else
  48. static inline void netpoll_rx_disable(struct net_device *dev) { return; }
  49. static inline void netpoll_rx_enable(struct net_device *dev) { return; }
  50. #endif
  51. void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
  52. void netpoll_print_options(struct netpoll *np);
  53. int netpoll_parse_options(struct netpoll *np, char *opt);
  54. int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp);
  55. int netpoll_setup(struct netpoll *np);
  56. int netpoll_trap(void);
  57. void netpoll_set_trap(int trap);
  58. void __netpoll_cleanup(struct netpoll *np);
  59. void __netpoll_free_async(struct netpoll *np);
  60. void netpoll_cleanup(struct netpoll *np);
  61. int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo);
  62. void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
  63. struct net_device *dev);
  64. static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
  65. {
  66. unsigned long flags;
  67. local_irq_save(flags);
  68. netpoll_send_skb_on_dev(np, skb, np->dev);
  69. local_irq_restore(flags);
  70. }
  71. #ifdef CONFIG_NETPOLL
  72. static inline bool netpoll_rx_on(struct sk_buff *skb)
  73. {
  74. struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo);
  75. return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
  76. }
  77. static inline bool netpoll_rx(struct sk_buff *skb)
  78. {
  79. struct netpoll_info *npinfo;
  80. unsigned long flags;
  81. bool ret = false;
  82. local_irq_save(flags);
  83. if (!netpoll_rx_on(skb))
  84. goto out;
  85. npinfo = rcu_dereference_bh(skb->dev->npinfo);
  86. spin_lock(&npinfo->rx_lock);
  87. /* check rx_flags again with the lock held */
  88. if (npinfo->rx_flags && __netpoll_rx(skb, npinfo))
  89. ret = true;
  90. spin_unlock(&npinfo->rx_lock);
  91. out:
  92. local_irq_restore(flags);
  93. return ret;
  94. }
  95. static inline int netpoll_receive_skb(struct sk_buff *skb)
  96. {
  97. if (!list_empty(&skb->dev->napi_list))
  98. return netpoll_rx(skb);
  99. return 0;
  100. }
  101. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  102. {
  103. struct net_device *dev = napi->dev;
  104. if (dev && dev->npinfo) {
  105. spin_lock(&napi->poll_lock);
  106. napi->poll_owner = smp_processor_id();
  107. return napi;
  108. }
  109. return NULL;
  110. }
  111. static inline void netpoll_poll_unlock(void *have)
  112. {
  113. struct napi_struct *napi = have;
  114. if (napi) {
  115. napi->poll_owner = -1;
  116. spin_unlock(&napi->poll_lock);
  117. }
  118. }
  119. static inline bool netpoll_tx_running(struct net_device *dev)
  120. {
  121. return irqs_disabled();
  122. }
  123. #else
  124. static inline bool netpoll_rx(struct sk_buff *skb)
  125. {
  126. return false;
  127. }
  128. static inline bool netpoll_rx_on(struct sk_buff *skb)
  129. {
  130. return false;
  131. }
  132. static inline int netpoll_receive_skb(struct sk_buff *skb)
  133. {
  134. return 0;
  135. }
  136. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  137. {
  138. return NULL;
  139. }
  140. static inline void netpoll_poll_unlock(void *have)
  141. {
  142. }
  143. static inline void netpoll_netdev_init(struct net_device *dev)
  144. {
  145. }
  146. static inline bool netpoll_tx_running(struct net_device *dev)
  147. {
  148. return false;
  149. }
  150. #endif
  151. #endif