netpoll.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. spin_lock(&napi->poll_lock);
  67. napi->poll_owner = smp_processor_id();
  68. return napi;
  69. }
  70. return NULL;
  71. }
  72. static inline void netpoll_poll_unlock(void *have)
  73. {
  74. struct napi_struct *napi = have;
  75. if (napi) {
  76. napi->poll_owner = -1;
  77. spin_unlock(&napi->poll_lock);
  78. }
  79. }
  80. static inline bool netpoll_tx_running(struct net_device *dev)
  81. {
  82. return irqs_disabled();
  83. }
  84. #else
  85. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  86. {
  87. return NULL;
  88. }
  89. static inline void netpoll_poll_unlock(void *have)
  90. {
  91. }
  92. static inline void netpoll_netdev_init(struct net_device *dev)
  93. {
  94. }
  95. static inline bool netpoll_tx_running(struct net_device *dev)
  96. {
  97. return false;
  98. }
  99. #endif
  100. #endif