Lines Matching refs:hvt
18 static void hvt_reset(struct hvutil_transport *hvt) in hvt_reset() argument
20 kfree(hvt->outmsg); in hvt_reset()
21 hvt->outmsg = NULL; in hvt_reset()
22 hvt->outmsg_len = 0; in hvt_reset()
23 if (hvt->on_reset) in hvt_reset()
24 hvt->on_reset(); in hvt_reset()
30 struct hvutil_transport *hvt; in hvt_op_read() local
33 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_read()
35 if (wait_event_interruptible(hvt->outmsg_q, hvt->outmsg_len > 0 || in hvt_op_read()
36 hvt->mode != HVUTIL_TRANSPORT_CHARDEV)) in hvt_op_read()
39 mutex_lock(&hvt->lock); in hvt_op_read()
41 if (hvt->mode == HVUTIL_TRANSPORT_DESTROY) { in hvt_op_read()
46 if (!hvt->outmsg) { in hvt_op_read()
51 if (count < hvt->outmsg_len) { in hvt_op_read()
56 if (!copy_to_user(buf, hvt->outmsg, hvt->outmsg_len)) in hvt_op_read()
57 ret = hvt->outmsg_len; in hvt_op_read()
61 kfree(hvt->outmsg); in hvt_op_read()
62 hvt->outmsg = NULL; in hvt_op_read()
63 hvt->outmsg_len = 0; in hvt_op_read()
65 if (hvt->on_read) in hvt_op_read()
66 hvt->on_read(); in hvt_op_read()
67 hvt->on_read = NULL; in hvt_op_read()
70 mutex_unlock(&hvt->lock); in hvt_op_read()
77 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->mode == HVUTIL_TRANSPORT_DESTROY) in hvt_op_write()
90 ret = hvt->on_msg(inmsg, count); in hvt_op_write()
99 struct hvutil_transport *hvt; in hvt_op_poll() local
101 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_poll()
103 poll_wait(file, &hvt->outmsg_q, wait); in hvt_op_poll()
105 if (hvt->mode == HVUTIL_TRANSPORT_DESTROY) in hvt_op_poll()
108 if (hvt->outmsg_len > 0) in hvt_op_poll()
116 struct hvutil_transport *hvt; in hvt_op_open() local
120 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_open()
122 mutex_lock(&hvt->lock); in hvt_op_open()
124 if (hvt->mode == HVUTIL_TRANSPORT_DESTROY) { in hvt_op_open()
126 } else if (hvt->mode == HVUTIL_TRANSPORT_INIT) { in hvt_op_open()
131 hvt->mode = HVUTIL_TRANSPORT_CHARDEV; in hvt_op_open()
133 else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) { in hvt_op_open()
139 hvt->mode = HVUTIL_TRANSPORT_CHARDEV; in hvt_op_open()
145 hvt_reset(hvt); in hvt_op_open()
147 mutex_unlock(&hvt->lock); in hvt_op_open()
152 static void hvt_transport_free(struct hvutil_transport *hvt) in hvt_transport_free() argument
154 misc_deregister(&hvt->mdev); in hvt_transport_free()
155 kfree(hvt->outmsg); in hvt_transport_free()
156 kfree(hvt); in hvt_transport_free()
161 struct hvutil_transport *hvt; in hvt_op_release() local
164 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_release()
166 mutex_lock(&hvt->lock); in hvt_op_release()
167 mode_old = hvt->mode; in hvt_op_release()
168 if (hvt->mode != HVUTIL_TRANSPORT_DESTROY) in hvt_op_release()
169 hvt->mode = HVUTIL_TRANSPORT_INIT; in hvt_op_release()
174 hvt_reset(hvt); in hvt_op_release()
177 complete(&hvt->release); in hvt_op_release()
179 mutex_unlock(&hvt->lock); in hvt_op_release()
186 struct hvutil_transport *hvt, *hvt_found = NULL; in hvt_cn_callback() local
189 list_for_each_entry(hvt, &hvt_list, list) { in hvt_cn_callback()
190 if (hvt->cn_id.idx == msg->id.idx && in hvt_cn_callback()
191 hvt->cn_id.val == msg->id.val) { in hvt_cn_callback()
192 hvt_found = hvt; in hvt_cn_callback()
206 mutex_lock(&hvt->lock); in hvt_cn_callback()
207 if (hvt->mode == HVUTIL_TRANSPORT_INIT) in hvt_cn_callback()
208 hvt->mode = HVUTIL_TRANSPORT_NETLINK; in hvt_cn_callback()
210 if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) in hvt_cn_callback()
214 mutex_unlock(&hvt->lock); in hvt_cn_callback()
217 int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len, in hvutil_transport_send() argument
223 if (hvt->mode == HVUTIL_TRANSPORT_INIT || in hvutil_transport_send()
224 hvt->mode == HVUTIL_TRANSPORT_DESTROY) { in hvutil_transport_send()
226 } else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) { in hvutil_transport_send()
230 cn_msg->id.idx = hvt->cn_id.idx; in hvutil_transport_send()
231 cn_msg->id.val = hvt->cn_id.val; in hvutil_transport_send()
246 mutex_lock(&hvt->lock); in hvutil_transport_send()
247 if (hvt->mode != HVUTIL_TRANSPORT_CHARDEV) { in hvutil_transport_send()
252 if (hvt->outmsg) { in hvutil_transport_send()
257 hvt->outmsg = kzalloc(len, GFP_KERNEL); in hvutil_transport_send()
258 if (hvt->outmsg) { in hvutil_transport_send()
259 memcpy(hvt->outmsg, msg, len); in hvutil_transport_send()
260 hvt->outmsg_len = len; in hvutil_transport_send()
261 hvt->on_read = on_read_cb; in hvutil_transport_send()
262 wake_up_interruptible(&hvt->outmsg_q); in hvutil_transport_send()
266 mutex_unlock(&hvt->lock); in hvutil_transport_send()
275 struct hvutil_transport *hvt; in hvutil_transport_init() local
277 hvt = kzalloc(sizeof(*hvt), GFP_KERNEL); in hvutil_transport_init()
278 if (!hvt) in hvutil_transport_init()
281 hvt->cn_id.idx = cn_idx; in hvutil_transport_init()
282 hvt->cn_id.val = cn_val; in hvutil_transport_init()
284 hvt->mdev.minor = MISC_DYNAMIC_MINOR; in hvutil_transport_init()
285 hvt->mdev.name = name; in hvutil_transport_init()
287 hvt->fops.owner = THIS_MODULE; in hvutil_transport_init()
288 hvt->fops.read = hvt_op_read; in hvutil_transport_init()
289 hvt->fops.write = hvt_op_write; in hvutil_transport_init()
290 hvt->fops.poll = hvt_op_poll; in hvutil_transport_init()
291 hvt->fops.open = hvt_op_open; in hvutil_transport_init()
292 hvt->fops.release = hvt_op_release; in hvutil_transport_init()
294 hvt->mdev.fops = &hvt->fops; in hvutil_transport_init()
296 init_waitqueue_head(&hvt->outmsg_q); in hvutil_transport_init()
297 mutex_init(&hvt->lock); in hvutil_transport_init()
298 init_completion(&hvt->release); in hvutil_transport_init()
301 list_add(&hvt->list, &hvt_list); in hvutil_transport_init()
304 hvt->on_msg = on_msg; in hvutil_transport_init()
305 hvt->on_reset = on_reset; in hvutil_transport_init()
307 if (misc_register(&hvt->mdev)) in hvutil_transport_init()
311 if (hvt->cn_id.idx > 0 && hvt->cn_id.val > 0 && in hvutil_transport_init()
312 cn_add_callback(&hvt->cn_id, name, hvt_cn_callback)) in hvutil_transport_init()
315 return hvt; in hvutil_transport_init()
319 list_del(&hvt->list); in hvutil_transport_init()
321 kfree(hvt); in hvutil_transport_init()
325 void hvutil_transport_destroy(struct hvutil_transport *hvt) in hvutil_transport_destroy() argument
329 mutex_lock(&hvt->lock); in hvutil_transport_destroy()
330 mode_old = hvt->mode; in hvutil_transport_destroy()
331 hvt->mode = HVUTIL_TRANSPORT_DESTROY; in hvutil_transport_destroy()
332 wake_up_interruptible(&hvt->outmsg_q); in hvutil_transport_destroy()
333 mutex_unlock(&hvt->lock); in hvutil_transport_destroy()
341 list_del(&hvt->list); in hvutil_transport_destroy()
343 if (hvt->cn_id.idx > 0 && hvt->cn_id.val > 0) in hvutil_transport_destroy()
344 cn_del_callback(&hvt->cn_id); in hvutil_transport_destroy()
347 wait_for_completion(&hvt->release); in hvutil_transport_destroy()
349 hvt_transport_free(hvt); in hvutil_transport_destroy()