Loading...
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
8#ifndef _HV_UTILS_TRANSPORT_H
9#define _HV_UTILS_TRANSPORT_H
10
11#include <linux/connector.h>
12#include <linux/miscdevice.h>
13
14enum hvutil_transport_mode {
15 HVUTIL_TRANSPORT_INIT = 0,
16 HVUTIL_TRANSPORT_NETLINK,
17 HVUTIL_TRANSPORT_CHARDEV,
18 HVUTIL_TRANSPORT_DESTROY,
19};
20
21struct 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 */
29 void (*on_read)(void); /* callback on message read */
30 u8 *outmsg; /* message to the userspace */
31 int outmsg_len; /* its length */
32 wait_queue_head_t outmsg_q; /* poll/read wait queue */
33 struct mutex lock; /* protects struct members */
34 struct completion release; /* synchronize with fd release */
35};
36
37struct 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));
41int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len,
42 void (*on_read_cb)(void));
43void hvutil_transport_destroy(struct hvutil_transport *hvt);
44
45#endif /* _HV_UTILS_TRANSPORT_H */
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
24enum hvutil_transport_mode {
25 HVUTIL_TRANSPORT_INIT = 0,
26 HVUTIL_TRANSPORT_NETLINK,
27 HVUTIL_TRANSPORT_CHARDEV,
28 HVUTIL_TRANSPORT_DESTROY,
29};
30
31struct 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 */
39 u8 *outmsg; /* message to the userspace */
40 int outmsg_len; /* its length */
41 wait_queue_head_t outmsg_q; /* poll/read wait queue */
42 struct mutex lock; /* protects struct members */
43};
44
45struct hvutil_transport *hvutil_transport_init(const char *name,
46 u32 cn_idx, u32 cn_val,
47 int (*on_msg)(void *, int),
48 void (*on_reset)(void));
49int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len);
50void hvutil_transport_destroy(struct hvutil_transport *hvt);
51
52#endif /* _HV_UTILS_TRANSPORT_H */