hv_utils_transport.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Kernel/userspace transport abstraction for Hyper-V util driver.
  4. *
  5. * Copyright (C) 2015, Vitaly Kuznetsov <vkuznets@redhat.com>
  6. */
  7. #ifndef _HV_UTILS_TRANSPORT_H
  8. #define _HV_UTILS_TRANSPORT_H
  9. #include <linux/connector.h>
  10. #include <linux/miscdevice.h>
  11. enum hvutil_transport_mode {
  12. HVUTIL_TRANSPORT_INIT = 0,
  13. HVUTIL_TRANSPORT_NETLINK,
  14. HVUTIL_TRANSPORT_CHARDEV,
  15. HVUTIL_TRANSPORT_DESTROY,
  16. };
  17. struct hvutil_transport {
  18. int mode; /* hvutil_transport_mode */
  19. struct file_operations fops; /* file operations */
  20. struct miscdevice mdev; /* misc device */
  21. struct cb_id cn_id; /* CN_*_IDX/CN_*_VAL */
  22. struct list_head list; /* hvt_list */
  23. int (*on_msg)(void *, int); /* callback on new user message */
  24. void (*on_reset)(void); /* callback when userspace drops */
  25. void (*on_read)(void); /* callback on message read */
  26. u8 *outmsg; /* message to the userspace */
  27. int outmsg_len; /* its length */
  28. wait_queue_head_t outmsg_q; /* poll/read wait queue */
  29. struct mutex lock; /* protects struct members */
  30. struct completion release; /* synchronize with fd release */
  31. };
  32. struct hvutil_transport *hvutil_transport_init(const char *name,
  33. u32 cn_idx, u32 cn_val,
  34. int (*on_msg)(void *, int),
  35. void (*on_reset)(void));
  36. int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len,
  37. void (*on_read_cb)(void));
  38. void hvutil_transport_destroy(struct hvutil_transport *hvt);
  39. #endif /* _HV_UTILS_TRANSPORT_H */