netpoll.h 3.3 KB

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