Lines Matching defs:hvt

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