18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Kernel/userspace transport abstraction for Hyper-V util driver. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2015, Vitaly Kuznetsov <vkuznets@redhat.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _HV_UTILS_TRANSPORT_H 98c2ecf20Sopenharmony_ci#define _HV_UTILS_TRANSPORT_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/connector.h> 128c2ecf20Sopenharmony_ci#include <linux/miscdevice.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cienum hvutil_transport_mode { 158c2ecf20Sopenharmony_ci HVUTIL_TRANSPORT_INIT = 0, 168c2ecf20Sopenharmony_ci HVUTIL_TRANSPORT_NETLINK, 178c2ecf20Sopenharmony_ci HVUTIL_TRANSPORT_CHARDEV, 188c2ecf20Sopenharmony_ci HVUTIL_TRANSPORT_DESTROY, 198c2ecf20Sopenharmony_ci}; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistruct hvutil_transport { 228c2ecf20Sopenharmony_ci int mode; /* hvutil_transport_mode */ 238c2ecf20Sopenharmony_ci struct file_operations fops; /* file operations */ 248c2ecf20Sopenharmony_ci struct miscdevice mdev; /* misc device */ 258c2ecf20Sopenharmony_ci struct cb_id cn_id; /* CN_*_IDX/CN_*_VAL */ 268c2ecf20Sopenharmony_ci struct list_head list; /* hvt_list */ 278c2ecf20Sopenharmony_ci int (*on_msg)(void *, int); /* callback on new user message */ 288c2ecf20Sopenharmony_ci void (*on_reset)(void); /* callback when userspace drops */ 298c2ecf20Sopenharmony_ci void (*on_read)(void); /* callback on message read */ 308c2ecf20Sopenharmony_ci u8 *outmsg; /* message to the userspace */ 318c2ecf20Sopenharmony_ci int outmsg_len; /* its length */ 328c2ecf20Sopenharmony_ci wait_queue_head_t outmsg_q; /* poll/read wait queue */ 338c2ecf20Sopenharmony_ci struct mutex lock; /* protects struct members */ 348c2ecf20Sopenharmony_ci struct completion release; /* synchronize with fd release */ 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistruct hvutil_transport *hvutil_transport_init(const char *name, 388c2ecf20Sopenharmony_ci u32 cn_idx, u32 cn_val, 398c2ecf20Sopenharmony_ci int (*on_msg)(void *, int), 408c2ecf20Sopenharmony_ci void (*on_reset)(void)); 418c2ecf20Sopenharmony_ciint hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len, 428c2ecf20Sopenharmony_ci void (*on_read_cb)(void)); 438c2ecf20Sopenharmony_civoid hvutil_transport_destroy(struct hvutil_transport *hvt); 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#endif /* _HV_UTILS_TRANSPORT_H */ 46