netpoll.h 2.0 KB

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