netpoll.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. union inet_addr local_ip, remote_ip;
  24. bool ipv6;
  25. u16 local_port, remote_port;
  26. u8 remote_mac[ETH_ALEN];
  27. struct work_struct cleanup_work;
  28. };
  29. struct netpoll_info {
  30. atomic_t refcnt;
  31. struct semaphore dev_lock;
  32. struct sk_buff_head txq;
  33. struct delayed_work tx_work;
  34. struct netpoll *netpoll;
  35. struct rcu_head rcu;
  36. };
  37. #ifdef CONFIG_NETPOLL
  38. extern void netpoll_poll_disable(struct net_device *dev);
  39. extern void netpoll_poll_enable(struct net_device *dev);
  40. #else
  41. static inline void netpoll_poll_disable(struct net_device *dev) { return; }
  42. static inline void netpoll_poll_enable(struct net_device *dev) { return; }
  43. #endif
  44. void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
  45. void netpoll_print_options(struct netpoll *np);
  46. int netpoll_parse_options(struct netpoll *np, char *opt);
  47. int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
  48. int netpoll_setup(struct netpoll *np);
  49. void __netpoll_cleanup(struct netpoll *np);
  50. void __netpoll_free_async(struct netpoll *np);
  51. void netpoll_cleanup(struct netpoll *np);
  52. void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
  53. struct net_device *dev);
  54. static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
  55. {
  56. unsigned long flags;
  57. local_irq_save(flags);
  58. netpoll_send_skb_on_dev(np, skb, np->dev);
  59. local_irq_restore(flags);
  60. }
  61. #ifdef CONFIG_NETPOLL
  62. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  63. {
  64. struct net_device *dev = napi->dev;
  65. if (dev && dev->npinfo) {
  66. int owner = smp_processor_id();
  67. while (cmpxchg(&napi->poll_owner, -1, owner) != -1)
  68. cpu_relax();
  69. return napi;
  70. }
  71. return NULL;
  72. }
  73. static inline void netpoll_poll_unlock(void *have)
  74. {
  75. struct napi_struct *napi = have;
  76. if (napi)
  77. smp_store_release(&napi->poll_owner, -1);
  78. }
  79. static inline bool netpoll_tx_running(struct net_device *dev)
  80. {
  81. return irqs_disabled();
  82. }
  83. #else
  84. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  85. {
  86. return NULL;
  87. }
  88. static inline void netpoll_poll_unlock(void *have)
  89. {
  90. }
  91. static inline void netpoll_netdev_init(struct net_device *dev)
  92. {
  93. }
  94. static inline bool netpoll_tx_running(struct net_device *dev)
  95. {
  96. return false;
  97. }
  98. #endif
  99. #endif