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