hv_utils_transport.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Kernel/userspace transport abstraction for Hyper-V util driver.
  3. *
  4. * Copyright (C) 2015, Vitaly Kuznetsov <vkuznets@redhat.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  13. * NON INFRINGEMENT. See the GNU General Public License for more
  14. * details.
  15. *
  16. */
  17. #ifndef _HV_UTILS_TRANSPORT_H
  18. #define _HV_UTILS_TRANSPORT_H
  19. #include <linux/connector.h>
  20. #include <linux/miscdevice.h>
  21. enum hvutil_transport_mode {
  22. HVUTIL_TRANSPORT_INIT = 0,
  23. HVUTIL_TRANSPORT_NETLINK,
  24. HVUTIL_TRANSPORT_CHARDEV,
  25. HVUTIL_TRANSPORT_DESTROY,
  26. };
  27. struct hvutil_transport {
  28. int mode; /* hvutil_transport_mode */
  29. struct file_operations fops; /* file operations */
  30. struct miscdevice mdev; /* misc device */
  31. struct cb_id cn_id; /* CN_*_IDX/CN_*_VAL */
  32. struct list_head list; /* hvt_list */
  33. int (*on_msg)(void *, int); /* callback on new user message */
  34. void (*on_reset)(void); /* callback when userspace drops */
  35. void (*on_read)(void); /* callback on message read */
  36. u8 *outmsg; /* message to the userspace */
  37. int outmsg_len; /* its length */
  38. wait_queue_head_t outmsg_q; /* poll/read wait queue */
  39. struct mutex lock; /* protects struct members */
  40. struct completion release; /* synchronize with fd release */
  41. };
  42. struct hvutil_transport *hvutil_transport_init(const char *name,
  43. u32 cn_idx, u32 cn_val,
  44. int (*on_msg)(void *, int),
  45. void (*on_reset)(void));
  46. int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len,
  47. void (*on_read_cb)(void));
  48. void hvutil_transport_destroy(struct hvutil_transport *hvt);
  49. #endif /* _HV_UTILS_TRANSPORT_H */