Lines Matching refs:hvt
28 static void hvt_reset(struct hvutil_transport *hvt) in hvt_reset() argument
30 mutex_lock(&hvt->outmsg_lock); in hvt_reset()
31 kfree(hvt->outmsg); in hvt_reset()
32 hvt->outmsg = NULL; in hvt_reset()
33 hvt->outmsg_len = 0; in hvt_reset()
34 mutex_unlock(&hvt->outmsg_lock); in hvt_reset()
35 if (hvt->on_reset) in hvt_reset()
36 hvt->on_reset(); in hvt_reset()
42 struct hvutil_transport *hvt; in hvt_op_read() local
45 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_read()
47 if (wait_event_interruptible(hvt->outmsg_q, hvt->outmsg_len > 0)) in hvt_op_read()
50 mutex_lock(&hvt->outmsg_lock); in hvt_op_read()
51 if (!hvt->outmsg) { in hvt_op_read()
56 if (count < hvt->outmsg_len) { in hvt_op_read()
61 if (!copy_to_user(buf, hvt->outmsg, hvt->outmsg_len)) in hvt_op_read()
62 ret = hvt->outmsg_len; in hvt_op_read()
66 kfree(hvt->outmsg); in hvt_op_read()
67 hvt->outmsg = NULL; in hvt_op_read()
68 hvt->outmsg_len = 0; in hvt_op_read()
71 mutex_unlock(&hvt->outmsg_lock); in hvt_op_read()
78 struct hvutil_transport *hvt; in hvt_op_write() local
81 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_write()
87 if (hvt->on_msg(inmsg, count)) in hvt_op_write()
96 struct hvutil_transport *hvt; in hvt_op_poll() local
98 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_poll()
100 poll_wait(file, &hvt->outmsg_q, wait); in hvt_op_poll()
101 if (hvt->outmsg_len > 0) in hvt_op_poll()
109 struct hvutil_transport *hvt; in hvt_op_open() local
111 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_open()
117 if (hvt->mode == HVUTIL_TRANSPORT_INIT) in hvt_op_open()
118 hvt->mode = HVUTIL_TRANSPORT_CHARDEV; in hvt_op_open()
119 else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) { in hvt_op_open()
124 hvt_reset(hvt); in hvt_op_open()
125 hvt->mode = HVUTIL_TRANSPORT_CHARDEV; in hvt_op_open()
134 struct hvutil_transport *hvt; in hvt_op_release() local
136 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_release()
138 hvt->mode = HVUTIL_TRANSPORT_INIT; in hvt_op_release()
143 hvt_reset(hvt); in hvt_op_release()
150 struct hvutil_transport *hvt, *hvt_found = NULL; in hvt_cn_callback() local
153 list_for_each_entry(hvt, &hvt_list, list) { in hvt_cn_callback()
154 if (hvt->cn_id.idx == msg->id.idx && in hvt_cn_callback()
155 hvt->cn_id.val == msg->id.val) { in hvt_cn_callback()
156 hvt_found = hvt; in hvt_cn_callback()
170 if (hvt->mode == HVUTIL_TRANSPORT_INIT) in hvt_cn_callback()
171 hvt->mode = HVUTIL_TRANSPORT_NETLINK; in hvt_cn_callback()
173 if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) in hvt_cn_callback()
179 int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len) in hvutil_transport_send() argument
184 if (hvt->mode == HVUTIL_TRANSPORT_INIT) { in hvutil_transport_send()
186 } else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) { in hvutil_transport_send()
190 cn_msg->id.idx = hvt->cn_id.idx; in hvutil_transport_send()
191 cn_msg->id.val = hvt->cn_id.val; in hvutil_transport_send()
199 mutex_lock(&hvt->outmsg_lock); in hvutil_transport_send()
200 if (hvt->outmsg) { in hvutil_transport_send()
205 hvt->outmsg = kzalloc(len, GFP_KERNEL); in hvutil_transport_send()
206 if (hvt->outmsg) { in hvutil_transport_send()
207 memcpy(hvt->outmsg, msg, len); in hvutil_transport_send()
208 hvt->outmsg_len = len; in hvutil_transport_send()
209 wake_up_interruptible(&hvt->outmsg_q); in hvutil_transport_send()
213 mutex_unlock(&hvt->outmsg_lock); in hvutil_transport_send()
222 struct hvutil_transport *hvt; in hvutil_transport_init() local
224 hvt = kzalloc(sizeof(*hvt), GFP_KERNEL); in hvutil_transport_init()
225 if (!hvt) in hvutil_transport_init()
228 hvt->cn_id.idx = cn_idx; in hvutil_transport_init()
229 hvt->cn_id.val = cn_val; in hvutil_transport_init()
231 hvt->mdev.minor = MISC_DYNAMIC_MINOR; in hvutil_transport_init()
232 hvt->mdev.name = name; in hvutil_transport_init()
234 hvt->fops.owner = THIS_MODULE; in hvutil_transport_init()
235 hvt->fops.read = hvt_op_read; in hvutil_transport_init()
236 hvt->fops.write = hvt_op_write; in hvutil_transport_init()
237 hvt->fops.poll = hvt_op_poll; in hvutil_transport_init()
238 hvt->fops.open = hvt_op_open; in hvutil_transport_init()
239 hvt->fops.release = hvt_op_release; in hvutil_transport_init()
241 hvt->mdev.fops = &hvt->fops; in hvutil_transport_init()
243 init_waitqueue_head(&hvt->outmsg_q); in hvutil_transport_init()
244 mutex_init(&hvt->outmsg_lock); in hvutil_transport_init()
247 list_add(&hvt->list, &hvt_list); in hvutil_transport_init()
250 hvt->on_msg = on_msg; in hvutil_transport_init()
251 hvt->on_reset = on_reset; in hvutil_transport_init()
253 if (misc_register(&hvt->mdev)) in hvutil_transport_init()
257 if (hvt->cn_id.idx > 0 && hvt->cn_id.val > 0 && in hvutil_transport_init()
258 cn_add_callback(&hvt->cn_id, name, hvt_cn_callback)) in hvutil_transport_init()
261 return hvt; in hvutil_transport_init()
264 kfree(hvt); in hvutil_transport_init()
268 void hvutil_transport_destroy(struct hvutil_transport *hvt) in hvutil_transport_destroy() argument
271 list_del(&hvt->list); in hvutil_transport_destroy()
273 if (hvt->cn_id.idx > 0 && hvt->cn_id.val > 0) in hvutil_transport_destroy()
274 cn_del_callback(&hvt->cn_id); in hvutil_transport_destroy()
275 misc_deregister(&hvt->mdev); in hvutil_transport_destroy()
276 kfree(hvt->outmsg); in hvutil_transport_destroy()
277 kfree(hvt); in hvutil_transport_destroy()