Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 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 | |
| 18 | #ifndef _HV_UTILS_TRANSPORT_H |
| 19 | #define _HV_UTILS_TRANSPORT_H |
| 20 | |
| 21 | #include <linux/connector.h> |
| 22 | #include <linux/miscdevice.h> |
| 23 | |
| 24 | enum hvutil_transport_mode { |
| 25 | HVUTIL_TRANSPORT_INIT = 0, |
| 26 | HVUTIL_TRANSPORT_NETLINK, |
| 27 | HVUTIL_TRANSPORT_CHARDEV, |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 28 | HVUTIL_TRANSPORT_DESTROY, |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | struct hvutil_transport { |
| 32 | int mode; /* hvutil_transport_mode */ |
| 33 | struct file_operations fops; /* file operations */ |
| 34 | struct miscdevice mdev; /* misc device */ |
| 35 | struct cb_id cn_id; /* CN_*_IDX/CN_*_VAL */ |
| 36 | struct list_head list; /* hvt_list */ |
| 37 | int (*on_msg)(void *, int); /* callback on new user message */ |
| 38 | void (*on_reset)(void); /* callback when userspace drops */ |
Vitaly Kuznetsov | e0fa3e5 | 2016-06-09 17:08:57 -0700 | [diff] [blame] | 39 | void (*on_read)(void); /* callback on message read */ |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 40 | u8 *outmsg; /* message to the userspace */ |
| 41 | int outmsg_len; /* its length */ |
| 42 | wait_queue_head_t outmsg_q; /* poll/read wait queue */ |
Vitaly Kuznetsov | a72f3a4 | 2015-12-14 19:01:54 -0800 | [diff] [blame] | 43 | struct mutex lock; /* protects struct members */ |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | struct hvutil_transport *hvutil_transport_init(const char *name, |
| 47 | u32 cn_idx, u32 cn_val, |
| 48 | int (*on_msg)(void *, int), |
| 49 | void (*on_reset)(void)); |
Vitaly Kuznetsov | e0fa3e5 | 2016-06-09 17:08:57 -0700 | [diff] [blame] | 50 | int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len, |
| 51 | void (*on_read_cb)(void)); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 52 | void hvutil_transport_destroy(struct hvutil_transport *hvt); |
| 53 | |
| 54 | #endif /* _HV_UTILS_TRANSPORT_H */ |