netpoll.h 2.2 KB

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