netpoll.h 2.2 KB

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