netpoll.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_hook)(struct netpoll *, int, char *, int);
  24. union inet_addr local_ip, remote_ip;
  25. bool ipv6;
  26. u16 local_port, remote_port;
  27. u8 remote_mac[ETH_ALEN];
  28. struct list_head rx; /* rx_np list element */
  29. struct rcu_head rcu;
  30. };
  31. struct netpoll_info {
  32. atomic_t refcnt;
  33. unsigned long rx_flags;
  34. spinlock_t rx_lock;
  35. struct mutex dev_lock;
  36. struct list_head rx_np; /* netpolls that registered an rx_hook */
  37. struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */
  38. struct sk_buff_head txq;
  39. struct delayed_work tx_work;
  40. struct netpoll *netpoll;
  41. struct rcu_head rcu;
  42. };
  43. #ifdef CONFIG_NETPOLL
  44. extern int netpoll_rx_disable(struct net_device *dev);
  45. extern void netpoll_rx_enable(struct net_device *dev);
  46. #else
  47. static inline int netpoll_rx_disable(struct net_device *dev) { return 0; }
  48. static inline void netpoll_rx_enable(struct net_device *dev) { return; }
  49. #endif
  50. void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
  51. void netpoll_print_options(struct netpoll *np);
  52. int netpoll_parse_options(struct netpoll *np, char *opt);
  53. int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp);
  54. int netpoll_setup(struct netpoll *np);
  55. int netpoll_trap(void);
  56. void netpoll_set_trap(int trap);
  57. void __netpoll_cleanup(struct netpoll *np);
  58. void __netpoll_free_rcu(struct netpoll *np);
  59. void netpoll_cleanup(struct netpoll *np);
  60. int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo);
  61. void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
  62. struct net_device *dev);
  63. static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
  64. {
  65. unsigned long flags;
  66. local_irq_save(flags);
  67. netpoll_send_skb_on_dev(np, skb, np->dev);
  68. local_irq_restore(flags);
  69. }
  70. #ifdef CONFIG_NETPOLL
  71. static inline bool netpoll_rx_on(struct sk_buff *skb)
  72. {
  73. struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo);
  74. return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
  75. }
  76. static inline bool netpoll_rx(struct sk_buff *skb)
  77. {
  78. struct netpoll_info *npinfo;
  79. unsigned long flags;
  80. bool ret = false;
  81. local_irq_save(flags);
  82. if (!netpoll_rx_on(skb))
  83. goto out;
  84. npinfo = rcu_dereference_bh(skb->dev->npinfo);
  85. spin_lock(&npinfo->rx_lock);
  86. /* check rx_flags again with the lock held */
  87. if (npinfo->rx_flags && __netpoll_rx(skb, npinfo))
  88. ret = true;
  89. spin_unlock(&npinfo->rx_lock);
  90. out:
  91. local_irq_restore(flags);
  92. return ret;
  93. }
  94. static inline int netpoll_receive_skb(struct sk_buff *skb)
  95. {
  96. if (!list_empty(&skb->dev->napi_list))
  97. return netpoll_rx(skb);
  98. return 0;
  99. }
  100. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  101. {
  102. struct net_device *dev = napi->dev;
  103. if (dev && dev->npinfo) {
  104. spin_lock(&napi->poll_lock);
  105. napi->poll_owner = smp_processor_id();
  106. return napi;
  107. }
  108. return NULL;
  109. }
  110. static inline void netpoll_poll_unlock(void *have)
  111. {
  112. struct napi_struct *napi = have;
  113. if (napi) {
  114. napi->poll_owner = -1;
  115. spin_unlock(&napi->poll_lock);
  116. }
  117. }
  118. static inline bool netpoll_tx_running(struct net_device *dev)
  119. {
  120. return irqs_disabled();
  121. }
  122. #else
  123. static inline bool netpoll_rx(struct sk_buff *skb)
  124. {
  125. return false;
  126. }
  127. static inline bool netpoll_rx_on(struct sk_buff *skb)
  128. {
  129. return false;
  130. }
  131. static inline int netpoll_receive_skb(struct sk_buff *skb)
  132. {
  133. return 0;
  134. }
  135. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  136. {
  137. return NULL;
  138. }
  139. static inline void netpoll_poll_unlock(void *have)
  140. {
  141. }
  142. static inline void netpoll_netdev_init(struct net_device *dev)
  143. {
  144. }
  145. static inline bool netpoll_tx_running(struct net_device *dev)
  146. {
  147. return false;
  148. }
  149. #endif
  150. #endif