netpoll.h 3.5 KB

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