netpoll.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Common code for low-level network console, dump, and debugger code
  4. *
  5. * Derived from netconsole, kgdb-over-ethernet, and netdump patches
  6. */
  7. #ifndef _LINUX_NETPOLL_H
  8. #define _LINUX_NETPOLL_H
  9. #include <linux/netdevice.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/rcupdate.h>
  12. #include <linux/list.h>
  13. #include <linux/refcount.h>
  14. union inet_addr {
  15. __u32 all[4];
  16. __be32 ip;
  17. __be32 ip6[4];
  18. struct in_addr in;
  19. struct in6_addr in6;
  20. };
  21. struct netpoll {
  22. struct net_device *dev;
  23. netdevice_tracker dev_tracker;
  24. char dev_name[IFNAMSIZ];
  25. const char *name;
  26. union inet_addr local_ip, remote_ip;
  27. bool ipv6;
  28. u16 local_port, remote_port;
  29. u8 remote_mac[ETH_ALEN];
  30. };
  31. struct netpoll_info {
  32. refcount_t refcnt;
  33. struct semaphore dev_lock;
  34. struct sk_buff_head txq;
  35. struct delayed_work tx_work;
  36. struct netpoll *netpoll;
  37. struct rcu_head rcu;
  38. };
  39. #ifdef CONFIG_NETPOLL
  40. void netpoll_poll_dev(struct net_device *dev);
  41. void netpoll_poll_disable(struct net_device *dev);
  42. void netpoll_poll_enable(struct net_device *dev);
  43. #else
  44. static inline void netpoll_poll_disable(struct net_device *dev) { return; }
  45. static inline void netpoll_poll_enable(struct net_device *dev) { return; }
  46. #endif
  47. void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
  48. void netpoll_print_options(struct netpoll *np);
  49. int netpoll_parse_options(struct netpoll *np, char *opt);
  50. int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
  51. int netpoll_setup(struct netpoll *np);
  52. void __netpoll_cleanup(struct netpoll *np);
  53. void __netpoll_free(struct netpoll *np);
  54. void netpoll_cleanup(struct netpoll *np);
  55. netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb);
  56. #ifdef CONFIG_NETPOLL
  57. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  58. {
  59. struct net_device *dev = napi->dev;
  60. if (dev && dev->npinfo) {
  61. int owner = smp_processor_id();
  62. while (cmpxchg(&napi->poll_owner, -1, owner) != -1)
  63. cpu_relax();
  64. return napi;
  65. }
  66. return NULL;
  67. }
  68. static inline void netpoll_poll_unlock(void *have)
  69. {
  70. struct napi_struct *napi = have;
  71. if (napi)
  72. smp_store_release(&napi->poll_owner, -1);
  73. }
  74. static inline bool netpoll_tx_running(struct net_device *dev)
  75. {
  76. return irqs_disabled();
  77. }
  78. #else
  79. static inline void *netpoll_poll_lock(struct napi_struct *napi)
  80. {
  81. return NULL;
  82. }
  83. static inline void netpoll_poll_unlock(void *have)
  84. {
  85. }
  86. static inline bool netpoll_tx_running(struct net_device *dev)
  87. {
  88. return false;
  89. }
  90. #endif
  91. #endif