netpoll.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 netpoll {
  14. struct net_device *dev;
  15. char dev_name[16], *name;
  16. void (*rx_hook)(struct netpoll *, int, char *, int);
  17. void (*drop)(struct sk_buff *skb);
  18. u32 local_ip, remote_ip;
  19. u16 local_port, remote_port;
  20. unsigned char local_mac[6], remote_mac[6];
  21. };
  22. struct netpoll_info {
  23. atomic_t refcnt;
  24. spinlock_t poll_lock;
  25. int poll_owner;
  26. int tries;
  27. int rx_flags;
  28. spinlock_t rx_lock;
  29. struct netpoll *rx_np; /* netpoll that registered an rx_hook */
  30. struct sk_buff_head arp_tx; /* list of arp requests to reply to */
  31. struct sk_buff_head txq;
  32. struct work_struct tx_work;
  33. };
  34. void netpoll_poll(struct netpoll *np);
  35. void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
  36. int netpoll_parse_options(struct netpoll *np, char *opt);
  37. int netpoll_setup(struct netpoll *np);
  38. int netpoll_trap(void);
  39. void netpoll_set_trap(int trap);
  40. void netpoll_cleanup(struct netpoll *np);
  41. int __netpoll_rx(struct sk_buff *skb);
  42. void netpoll_queue(struct sk_buff *skb);
  43. #ifdef CONFIG_NETPOLL
  44. static inline int netpoll_rx(struct sk_buff *skb)
  45. {
  46. struct netpoll_info *npinfo = skb->dev->npinfo;
  47. unsigned long flags;
  48. int ret = 0;
  49. if (!npinfo || (!npinfo->rx_np && !npinfo->rx_flags))
  50. return 0;
  51. spin_lock_irqsave(&npinfo->rx_lock, flags);
  52. /* check rx_flags again with the lock held */
  53. if (npinfo->rx_flags && __netpoll_rx(skb))
  54. ret = 1;
  55. spin_unlock_irqrestore(&npinfo->rx_lock, flags);
  56. return ret;
  57. }
  58. static inline void *netpoll_poll_lock(struct net_device *dev)
  59. {
  60. rcu_read_lock(); /* deal with race on ->npinfo */
  61. if (dev->npinfo) {
  62. spin_lock(&dev->npinfo->poll_lock);
  63. dev->npinfo->poll_owner = smp_processor_id();
  64. return dev->npinfo;
  65. }
  66. return NULL;
  67. }
  68. static inline void netpoll_poll_unlock(void *have)
  69. {
  70. struct netpoll_info *npi = have;
  71. if (npi) {
  72. npi->poll_owner = -1;
  73. spin_unlock(&npi->poll_lock);
  74. }
  75. rcu_read_unlock();
  76. }
  77. #else
  78. #define netpoll_rx(a) 0
  79. #define netpoll_poll_lock(a) NULL
  80. #define netpoll_poll_unlock(a)
  81. #endif
  82. #endif