netpoll.h 2.4 KB

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