Lines Matching refs:vu_dev

77 #define vu_err(vu_dev, ...)	dev_err(&(vu_dev)->pdev->dev, ##__VA_ARGS__)  argument
128 static int vhost_user_recv(struct virtio_uml_device *vu_dev, in vhost_user_recv() argument
160 static void vhost_user_check_reset(struct virtio_uml_device *vu_dev, in vhost_user_check_reset() argument
163 struct virtio_uml_platform_data *pdata = vu_dev->pdata; in vhost_user_check_reset()
168 if (!vu_dev->registered) in vhost_user_check_reset()
171 vu_dev->registered = 0; in vhost_user_check_reset()
176 static int vhost_user_recv_resp(struct virtio_uml_device *vu_dev, in vhost_user_recv_resp() argument
180 int rc = vhost_user_recv(vu_dev, vu_dev->sock, msg, in vhost_user_recv_resp()
184 vhost_user_check_reset(vu_dev, rc); in vhost_user_recv_resp()
194 static int vhost_user_recv_u64(struct virtio_uml_device *vu_dev, in vhost_user_recv_u64() argument
198 int rc = vhost_user_recv_resp(vu_dev, &msg, in vhost_user_recv_u64()
209 static int vhost_user_recv_req(struct virtio_uml_device *vu_dev, in vhost_user_recv_req() argument
213 int rc = vhost_user_recv(vu_dev, vu_dev->req_fd, msg, in vhost_user_recv_req()
226 static int vhost_user_send(struct virtio_uml_device *vu_dev, in vhost_user_send() argument
243 if (!(vu_dev->protocol_features & in vhost_user_send()
250 spin_lock_irqsave(&vu_dev->sock_lock, flags); in vhost_user_send()
251 rc = full_sendmsg_fds(vu_dev->sock, msg, size, fds, num_fds); in vhost_user_send()
258 rc = vhost_user_recv_u64(vu_dev, &status); in vhost_user_send()
263 vu_err(vu_dev, "slave reports error: %llu\n", status); in vhost_user_send()
270 spin_unlock_irqrestore(&vu_dev->sock_lock, flags); in vhost_user_send()
274 static int vhost_user_send_no_payload(struct virtio_uml_device *vu_dev, in vhost_user_send_no_payload() argument
281 return vhost_user_send(vu_dev, need_response, &msg, NULL, 0); in vhost_user_send_no_payload()
284 static int vhost_user_send_no_payload_fd(struct virtio_uml_device *vu_dev, in vhost_user_send_no_payload_fd() argument
291 return vhost_user_send(vu_dev, false, &msg, &fd, 1); in vhost_user_send_no_payload_fd()
294 static int vhost_user_send_u64(struct virtio_uml_device *vu_dev, in vhost_user_send_u64() argument
303 return vhost_user_send(vu_dev, false, &msg, NULL, 0); in vhost_user_send_u64()
306 static int vhost_user_set_owner(struct virtio_uml_device *vu_dev) in vhost_user_set_owner() argument
308 return vhost_user_send_no_payload(vu_dev, false, VHOST_USER_SET_OWNER); in vhost_user_set_owner()
311 static int vhost_user_get_features(struct virtio_uml_device *vu_dev, in vhost_user_get_features() argument
314 int rc = vhost_user_send_no_payload(vu_dev, true, in vhost_user_get_features()
319 return vhost_user_recv_u64(vu_dev, features); in vhost_user_get_features()
322 static int vhost_user_set_features(struct virtio_uml_device *vu_dev, in vhost_user_set_features() argument
325 return vhost_user_send_u64(vu_dev, VHOST_USER_SET_FEATURES, features); in vhost_user_set_features()
328 static int vhost_user_get_protocol_features(struct virtio_uml_device *vu_dev, in vhost_user_get_protocol_features() argument
331 int rc = vhost_user_send_no_payload(vu_dev, true, in vhost_user_get_protocol_features()
336 return vhost_user_recv_u64(vu_dev, protocol_features); in vhost_user_get_protocol_features()
339 static int vhost_user_set_protocol_features(struct virtio_uml_device *vu_dev, in vhost_user_set_protocol_features() argument
342 return vhost_user_send_u64(vu_dev, VHOST_USER_SET_PROTOCOL_FEATURES, in vhost_user_set_protocol_features()
346 static void vhost_user_reply(struct virtio_uml_device *vu_dev, in vhost_user_reply() argument
360 rc = full_sendmsg_fds(vu_dev->req_fd, &reply, size, NULL, 0); in vhost_user_reply()
363 vu_err(vu_dev, in vhost_user_reply()
368 static irqreturn_t vu_req_read_message(struct virtio_uml_device *vu_dev, in vu_req_read_message() argument
381 rc = vhost_user_recv_req(vu_dev, &msg.msg, in vu_req_read_message()
389 vu_dev->config_changed_irq = true; in vu_req_read_message()
393 virtio_device_for_each_vq((&vu_dev->vdev), vq) { in vu_req_read_message()
396 vu_dev->vq_irq_vq_map |= BIT_ULL(vq->index); in vu_req_read_message()
406 vu_err(vu_dev, "unexpected slave request %d\n", in vu_req_read_message()
410 if (ev && !vu_dev->suspended) in vu_req_read_message()
414 vhost_user_reply(vu_dev, &msg.msg, response); in vu_req_read_message()
418 vu_dev->recv_rc = (rc == -EAGAIN) ? 0 : rc; in vu_req_read_message()
424 struct virtio_uml_device *vu_dev = data; in vu_req_interrupt() local
428 ret = vu_req_read_message(vu_dev, NULL); in vu_req_interrupt()
430 if (vu_dev->recv_rc) { in vu_req_interrupt()
431 vhost_user_check_reset(vu_dev, vu_dev->recv_rc); in vu_req_interrupt()
432 } else if (vu_dev->vq_irq_vq_map) { in vu_req_interrupt()
435 virtio_device_for_each_vq((&vu_dev->vdev), vq) { in vu_req_interrupt()
436 if (vu_dev->vq_irq_vq_map & BIT_ULL(vq->index)) in vu_req_interrupt()
439 vu_dev->vq_irq_vq_map = 0; in vu_req_interrupt()
440 } else if (vu_dev->config_changed_irq) { in vu_req_interrupt()
441 virtio_config_changed(&vu_dev->vdev); in vu_req_interrupt()
442 vu_dev->config_changed_irq = false; in vu_req_interrupt()
454 static int vhost_user_init_slave_req(struct virtio_uml_device *vu_dev) in vhost_user_init_slave_req() argument
462 vu_dev->req_fd = req_fds[0]; in vhost_user_init_slave_req()
464 rc = um_request_irq_tt(UM_IRQ_ALLOC, vu_dev->req_fd, IRQ_READ, in vhost_user_init_slave_req()
466 vu_dev->pdev->name, vu_dev, in vhost_user_init_slave_req()
471 vu_dev->irq = rc; in vhost_user_init_slave_req()
473 rc = vhost_user_send_no_payload_fd(vu_dev, VHOST_USER_SET_SLAVE_REQ_FD, in vhost_user_init_slave_req()
481 um_free_irq(vu_dev->irq, vu_dev); in vhost_user_init_slave_req()
490 static int vhost_user_init(struct virtio_uml_device *vu_dev) in vhost_user_init() argument
492 int rc = vhost_user_set_owner(vu_dev); in vhost_user_init()
496 rc = vhost_user_get_features(vu_dev, &vu_dev->features); in vhost_user_init()
500 if (vu_dev->features & BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)) { in vhost_user_init()
501 rc = vhost_user_get_protocol_features(vu_dev, in vhost_user_init()
502 &vu_dev->protocol_features); in vhost_user_init()
505 vu_dev->protocol_features &= VHOST_USER_SUPPORTED_PROTOCOL_F; in vhost_user_init()
506 rc = vhost_user_set_protocol_features(vu_dev, in vhost_user_init()
507 vu_dev->protocol_features); in vhost_user_init()
512 if (vu_dev->protocol_features & in vhost_user_init()
514 rc = vhost_user_init_slave_req(vu_dev); in vhost_user_init()
522 static void vhost_user_get_config(struct virtio_uml_device *vu_dev, in vhost_user_get_config() argument
531 if (!(vu_dev->protocol_features & in vhost_user_get_config()
543 rc = vhost_user_send(vu_dev, true, msg, NULL, 0); in vhost_user_get_config()
545 vu_err(vu_dev, "sending VHOST_USER_GET_CONFIG failed: %d\n", in vhost_user_get_config()
550 rc = vhost_user_recv_resp(vu_dev, msg, msg_size); in vhost_user_get_config()
552 vu_err(vu_dev, in vhost_user_get_config()
561 vu_err(vu_dev, in vhost_user_get_config()
573 static void vhost_user_set_config(struct virtio_uml_device *vu_dev, in vhost_user_set_config() argument
581 if (!(vu_dev->protocol_features & in vhost_user_set_config()
594 rc = vhost_user_send(vu_dev, false, msg, NULL, 0); in vhost_user_set_config()
596 vu_err(vu_dev, "sending VHOST_USER_SET_CONFIG failed: %d\n", in vhost_user_set_config()
624 static int vhost_user_set_mem_table(struct virtio_uml_device *vu_dev) in vhost_user_set_mem_table() argument
684 return vhost_user_send(vu_dev, false, &msg, fds, in vhost_user_set_mem_table()
688 static int vhost_user_set_vring_state(struct virtio_uml_device *vu_dev, in vhost_user_set_vring_state() argument
698 return vhost_user_send(vu_dev, false, &msg, NULL, 0); in vhost_user_set_vring_state()
701 static int vhost_user_set_vring_num(struct virtio_uml_device *vu_dev, in vhost_user_set_vring_num() argument
704 return vhost_user_set_vring_state(vu_dev, VHOST_USER_SET_VRING_NUM, in vhost_user_set_vring_num()
708 static int vhost_user_set_vring_base(struct virtio_uml_device *vu_dev, in vhost_user_set_vring_base() argument
711 return vhost_user_set_vring_state(vu_dev, VHOST_USER_SET_VRING_BASE, in vhost_user_set_vring_base()
715 static int vhost_user_set_vring_addr(struct virtio_uml_device *vu_dev, in vhost_user_set_vring_addr() argument
729 return vhost_user_send(vu_dev, false, &msg, NULL, 0); in vhost_user_set_vring_addr()
732 static int vhost_user_set_vring_fd(struct virtio_uml_device *vu_dev, in vhost_user_set_vring_fd() argument
745 return vhost_user_send(vu_dev, false, &msg, NULL, 0); in vhost_user_set_vring_fd()
747 return vhost_user_send(vu_dev, false, &msg, &fd, 1); in vhost_user_set_vring_fd()
750 static int vhost_user_set_vring_call(struct virtio_uml_device *vu_dev, in vhost_user_set_vring_call() argument
753 return vhost_user_set_vring_fd(vu_dev, VHOST_USER_SET_VRING_CALL, in vhost_user_set_vring_call()
757 static int vhost_user_set_vring_kick(struct virtio_uml_device *vu_dev, in vhost_user_set_vring_kick() argument
760 return vhost_user_set_vring_fd(vu_dev, VHOST_USER_SET_VRING_KICK, in vhost_user_set_vring_kick()
764 static int vhost_user_set_vring_enable(struct virtio_uml_device *vu_dev, in vhost_user_set_vring_enable() argument
767 if (!(vu_dev->features & BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES))) in vhost_user_set_vring_enable()
770 return vhost_user_set_vring_state(vu_dev, VHOST_USER_SET_VRING_ENABLE, in vhost_user_set_vring_enable()
789 struct virtio_uml_device *vu_dev; in vu_notify() local
791 vu_dev = to_virtio_uml_device(vq->vdev); in vu_notify()
793 return vhost_user_set_vring_state(vu_dev, VHOST_USER_VRING_KICK, in vu_notify()
824 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_get() local
826 vhost_user_get_config(vu_dev, offset, buf, len); in vu_get()
832 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_set() local
834 vhost_user_set_config(vu_dev, offset, buf, len); in vu_set()
839 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_get_status() local
841 return vu_dev->status; in vu_get_status()
846 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_set_status() local
848 vu_dev->status = status; in vu_set_status()
853 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_reset() local
855 vu_dev->status = 0; in vu_reset()
863 struct virtio_uml_device *vu_dev; in vu_del_vq() local
865 vu_dev = to_virtio_uml_device(vq->vdev); in vu_del_vq()
867 um_free_irq(vu_dev->irq, vq); in vu_del_vq()
880 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_del_vqs() local
886 WARN_ON(vhost_user_set_vring_enable(vu_dev, vq->index, false)); in vu_del_vqs()
889 WARN_ON(vhost_user_get_features(vu_dev, &features)); in vu_del_vqs()
895 static int vu_setup_vq_call_fd(struct virtio_uml_device *vu_dev, in vu_setup_vq_call_fd() argument
903 if (vu_dev->protocol_features & in vu_setup_vq_call_fd()
905 vu_dev->protocol_features & in vu_setup_vq_call_fd()
917 rc = um_request_irq(vu_dev->irq, info->call_fd, IRQ_READ, in vu_setup_vq_call_fd()
922 rc = vhost_user_set_vring_call(vu_dev, vq->index, call_fds[1]); in vu_setup_vq_call_fd()
929 um_free_irq(vu_dev->irq, vq); in vu_setup_vq_call_fd()
943 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_setup_vq() local
944 struct platform_device *pdev = vu_dev->pdev; in vu_setup_vq()
968 if (vu_dev->protocol_features & in vu_setup_vq()
978 rc = vu_setup_vq_call_fd(vu_dev, vq); in vu_setup_vq()
982 rc = vhost_user_set_vring_num(vu_dev, index, num); in vu_setup_vq()
986 rc = vhost_user_set_vring_base(vu_dev, index, 0); in vu_setup_vq()
990 rc = vhost_user_set_vring_addr(vu_dev, index, in vu_setup_vq()
1002 um_free_irq(vu_dev->irq, vq); in vu_setup_vq()
1021 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_find_vqs() local
1029 rc = vhost_user_set_mem_table(vu_dev); in vu_find_vqs()
1051 rc = vhost_user_set_vring_kick(vu_dev, vq->index, in vu_find_vqs()
1057 rc = vhost_user_set_vring_enable(vu_dev, vq->index, true); in vu_find_vqs()
1071 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_get_features() local
1073 return vu_dev->features; in vu_get_features()
1078 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_finalize_features() local
1082 vu_dev->features = vdev->features | supported; in vu_finalize_features()
1084 return vhost_user_set_features(vu_dev, vu_dev->features); in vu_finalize_features()
1089 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in vu_bus_name() local
1091 return vu_dev->pdev->name; in vu_bus_name()
1111 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in virtio_uml_release_dev() local
1116 if (vu_dev->req_fd >= 0) { in virtio_uml_release_dev()
1117 um_free_irq(vu_dev->irq, vu_dev); in virtio_uml_release_dev()
1118 os_close_file(vu_dev->req_fd); in virtio_uml_release_dev()
1121 os_close_file(vu_dev->sock); in virtio_uml_release_dev()
1122 kfree(vu_dev); in virtio_uml_release_dev()
1128 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev); in virtio_uml_set_no_vq_suspend() local
1133 vu_dev->no_vq_suspend = no_vq_suspend; in virtio_uml_set_no_vq_suspend()
1141 struct virtio_uml_device *vu_dev; in vu_of_conn_broken() local
1145 vu_dev = platform_get_drvdata(pdata->pdev); in vu_of_conn_broken()
1147 virtio_break_device(&vu_dev->vdev); in vu_of_conn_broken()
1190 struct virtio_uml_device *vu_dev; in virtio_uml_probe() local
1199 vu_dev = kzalloc(sizeof(*vu_dev), GFP_KERNEL); in virtio_uml_probe()
1200 if (!vu_dev) in virtio_uml_probe()
1203 vu_dev->pdata = pdata; in virtio_uml_probe()
1204 vu_dev->vdev.dev.parent = &pdev->dev; in virtio_uml_probe()
1205 vu_dev->vdev.dev.release = virtio_uml_release_dev; in virtio_uml_probe()
1206 vu_dev->vdev.config = &virtio_uml_config_ops; in virtio_uml_probe()
1207 vu_dev->vdev.id.device = pdata->virtio_device_id; in virtio_uml_probe()
1208 vu_dev->vdev.id.vendor = VIRTIO_DEV_ANY_ID; in virtio_uml_probe()
1209 vu_dev->pdev = pdev; in virtio_uml_probe()
1210 vu_dev->req_fd = -1; in virtio_uml_probe()
1219 vu_dev->sock = rc; in virtio_uml_probe()
1221 spin_lock_init(&vu_dev->sock_lock); in virtio_uml_probe()
1223 rc = vhost_user_init(vu_dev); in virtio_uml_probe()
1227 platform_set_drvdata(pdev, vu_dev); in virtio_uml_probe()
1229 device_set_wakeup_capable(&vu_dev->vdev.dev, true); in virtio_uml_probe()
1231 rc = register_virtio_device(&vu_dev->vdev); in virtio_uml_probe()
1233 put_device(&vu_dev->vdev.dev); in virtio_uml_probe()
1234 vu_dev->registered = 1; in virtio_uml_probe()
1238 os_close_file(vu_dev->sock); in virtio_uml_probe()
1240 kfree(vu_dev); in virtio_uml_probe()
1246 struct virtio_uml_device *vu_dev = platform_get_drvdata(pdev); in virtio_uml_remove() local
1248 unregister_virtio_device(&vu_dev->vdev); in virtio_uml_remove()
1279 struct virtio_uml_device *vu_dev; in vu_conn_broken() local
1283 vu_dev = platform_get_drvdata(pdata->pdev); in vu_conn_broken()
1285 virtio_break_device(&vu_dev->vdev); in vu_conn_broken()
1402 struct virtio_uml_device *vu_dev = platform_get_drvdata(pdev); in virtio_uml_suspend() local
1404 if (!vu_dev->no_vq_suspend) { in virtio_uml_suspend()
1407 virtio_device_for_each_vq((&vu_dev->vdev), vq) { in virtio_uml_suspend()
1411 vhost_user_set_vring_enable(vu_dev, vq->index, false); in virtio_uml_suspend()
1415 if (!device_may_wakeup(&vu_dev->vdev.dev)) { in virtio_uml_suspend()
1416 vu_dev->suspended = true; in virtio_uml_suspend()
1420 return irq_set_irq_wake(vu_dev->irq, 1); in virtio_uml_suspend()
1425 struct virtio_uml_device *vu_dev = platform_get_drvdata(pdev); in virtio_uml_resume() local
1427 if (!vu_dev->no_vq_suspend) { in virtio_uml_resume()
1430 virtio_device_for_each_vq((&vu_dev->vdev), vq) { in virtio_uml_resume()
1434 vhost_user_set_vring_enable(vu_dev, vq->index, true); in virtio_uml_resume()
1438 vu_dev->suspended = false; in virtio_uml_resume()
1440 if (!device_may_wakeup(&vu_dev->vdev.dev)) in virtio_uml_resume()
1443 return irq_set_irq_wake(vu_dev->irq, 0); in virtio_uml_resume()