Lines Matching refs:vu_dev
77 #define vu_err(vu_dev, ...) dev_err(&(vu_dev)->pdev->dev, ##__VA_ARGS__)
125 static int vhost_user_recv(struct virtio_uml_device *vu_dev,
149 if (rc == -ECONNRESET && vu_dev->registered) {
152 pdata = vu_dev->pdev->dev.platform_data;
154 virtio_break_device(&vu_dev->vdev);
165 static int vhost_user_recv_resp(struct virtio_uml_device *vu_dev,
169 int rc = vhost_user_recv(vu_dev, vu_dev->sock, msg,
181 static int vhost_user_recv_u64(struct virtio_uml_device *vu_dev,
185 int rc = vhost_user_recv_resp(vu_dev, &msg,
196 static int vhost_user_recv_req(struct virtio_uml_device *vu_dev,
200 int rc = vhost_user_recv(vu_dev, vu_dev->req_fd, msg,
213 static int vhost_user_send(struct virtio_uml_device *vu_dev,
230 if (!(vu_dev->protocol_features &
237 spin_lock_irqsave(&vu_dev->sock_lock, flags);
238 rc = full_sendmsg_fds(vu_dev->sock, msg, size, fds, num_fds);
245 rc = vhost_user_recv_u64(vu_dev, &status);
250 vu_err(vu_dev, "slave reports error: %llu\n", status);
257 spin_unlock_irqrestore(&vu_dev->sock_lock, flags);
261 static int vhost_user_send_no_payload(struct virtio_uml_device *vu_dev,
268 return vhost_user_send(vu_dev, need_response, &msg, NULL, 0);
271 static int vhost_user_send_no_payload_fd(struct virtio_uml_device *vu_dev,
278 return vhost_user_send(vu_dev, false, &msg, &fd, 1);
281 static int vhost_user_send_u64(struct virtio_uml_device *vu_dev,
290 return vhost_user_send(vu_dev, false, &msg, NULL, 0);
293 static int vhost_user_set_owner(struct virtio_uml_device *vu_dev)
295 return vhost_user_send_no_payload(vu_dev, false, VHOST_USER_SET_OWNER);
298 static int vhost_user_get_features(struct virtio_uml_device *vu_dev,
301 int rc = vhost_user_send_no_payload(vu_dev, true,
306 return vhost_user_recv_u64(vu_dev, features);
309 static int vhost_user_set_features(struct virtio_uml_device *vu_dev,
312 return vhost_user_send_u64(vu_dev, VHOST_USER_SET_FEATURES, features);
315 static int vhost_user_get_protocol_features(struct virtio_uml_device *vu_dev,
318 int rc = vhost_user_send_no_payload(vu_dev, true,
323 return vhost_user_recv_u64(vu_dev, protocol_features);
326 static int vhost_user_set_protocol_features(struct virtio_uml_device *vu_dev,
329 return vhost_user_send_u64(vu_dev, VHOST_USER_SET_PROTOCOL_FEATURES,
333 static void vhost_user_reply(struct virtio_uml_device *vu_dev,
347 rc = full_sendmsg_fds(vu_dev->req_fd, &reply, size, NULL, 0);
350 vu_err(vu_dev,
357 struct virtio_uml_device *vu_dev = data;
366 rc = vhost_user_recv_req(vu_dev, &msg.msg,
375 virtio_config_changed(&vu_dev->vdev);
379 virtio_device_for_each_vq((&vu_dev->vdev), vq) {
392 vu_err(vu_dev, "unexpected slave request %d\n",
397 vhost_user_reply(vu_dev, &msg.msg, response);
402 static int vhost_user_init_slave_req(struct virtio_uml_device *vu_dev)
410 vu_dev->req_fd = req_fds[0];
412 rc = um_request_irq(VIRTIO_IRQ, vu_dev->req_fd, IRQ_READ,
414 vu_dev->pdev->name, vu_dev);
418 rc = vhost_user_send_no_payload_fd(vu_dev, VHOST_USER_SET_SLAVE_REQ_FD,
426 um_free_irq(VIRTIO_IRQ, vu_dev);
435 static int vhost_user_init(struct virtio_uml_device *vu_dev)
437 int rc = vhost_user_set_owner(vu_dev);
441 rc = vhost_user_get_features(vu_dev, &vu_dev->features);
445 if (vu_dev->features & BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)) {
446 rc = vhost_user_get_protocol_features(vu_dev,
447 &vu_dev->protocol_features);
450 vu_dev->protocol_features &= VHOST_USER_SUPPORTED_PROTOCOL_F;
451 rc = vhost_user_set_protocol_features(vu_dev,
452 vu_dev->protocol_features);
457 if (vu_dev->protocol_features &
459 rc = vhost_user_init_slave_req(vu_dev);
467 static void vhost_user_get_config(struct virtio_uml_device *vu_dev,
476 if (!(vu_dev->protocol_features &
488 rc = vhost_user_send(vu_dev, true, msg, NULL, 0);
490 vu_err(vu_dev, "sending VHOST_USER_GET_CONFIG failed: %d\n",
495 rc = vhost_user_recv_resp(vu_dev, msg, msg_size);
497 vu_err(vu_dev,
506 vu_err(vu_dev,
518 static void vhost_user_set_config(struct virtio_uml_device *vu_dev,
526 if (!(vu_dev->protocol_features &
539 rc = vhost_user_send(vu_dev, false, msg, NULL, 0);
541 vu_err(vu_dev, "sending VHOST_USER_SET_CONFIG failed: %d\n",
569 static int vhost_user_set_mem_table(struct virtio_uml_device *vu_dev)
629 return vhost_user_send(vu_dev, false, &msg, fds,
633 static int vhost_user_set_vring_state(struct virtio_uml_device *vu_dev,
643 return vhost_user_send(vu_dev, false, &msg, NULL, 0);
646 static int vhost_user_set_vring_num(struct virtio_uml_device *vu_dev,
649 return vhost_user_set_vring_state(vu_dev, VHOST_USER_SET_VRING_NUM,
653 static int vhost_user_set_vring_base(struct virtio_uml_device *vu_dev,
656 return vhost_user_set_vring_state(vu_dev, VHOST_USER_SET_VRING_BASE,
660 static int vhost_user_set_vring_addr(struct virtio_uml_device *vu_dev,
674 return vhost_user_send(vu_dev, false, &msg, NULL, 0);
677 static int vhost_user_set_vring_fd(struct virtio_uml_device *vu_dev,
690 return vhost_user_send(vu_dev, false, &msg, NULL, 0);
692 return vhost_user_send(vu_dev, false, &msg, &fd, 1);
695 static int vhost_user_set_vring_call(struct virtio_uml_device *vu_dev,
698 return vhost_user_set_vring_fd(vu_dev, VHOST_USER_SET_VRING_CALL,
702 static int vhost_user_set_vring_kick(struct virtio_uml_device *vu_dev,
705 return vhost_user_set_vring_fd(vu_dev, VHOST_USER_SET_VRING_KICK,
709 static int vhost_user_set_vring_enable(struct virtio_uml_device *vu_dev,
712 if (!(vu_dev->features & BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)))
715 return vhost_user_set_vring_state(vu_dev, VHOST_USER_SET_VRING_ENABLE,
731 struct virtio_uml_device *vu_dev;
733 vu_dev = to_virtio_uml_device(vq->vdev);
735 return vhost_user_set_vring_state(vu_dev, VHOST_USER_VRING_KICK,
766 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
768 vhost_user_get_config(vu_dev, offset, buf, len);
774 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
776 vhost_user_set_config(vu_dev, offset, buf, len);
781 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
783 return vu_dev->status;
788 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
790 vu_dev->status = status;
795 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
797 vu_dev->status = 0;
818 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
824 WARN_ON(vhost_user_set_vring_enable(vu_dev, vq->index, false));
827 WARN_ON(vhost_user_get_features(vu_dev, &features));
833 static int vu_setup_vq_call_fd(struct virtio_uml_device *vu_dev,
841 if (vu_dev->protocol_features &
843 vu_dev->protocol_features &
860 rc = vhost_user_set_vring_call(vu_dev, vq->index, call_fds[1]);
898 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
899 struct platform_device *pdev = vu_dev->pdev;
938 if (vu_dev->protocol_features &
948 rc = vu_setup_vq_call_fd(vu_dev, vq);
952 rc = vhost_user_set_vring_num(vu_dev, index, num);
956 rc = vhost_user_set_vring_base(vu_dev, index, 0);
960 rc = vhost_user_set_vring_addr(vu_dev, index,
991 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
995 rc = vhost_user_set_mem_table(vu_dev);
1017 rc = vhost_user_set_vring_kick(vu_dev, vq->index,
1023 rc = vhost_user_set_vring_enable(vu_dev, vq->index, true);
1037 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
1039 return vu_dev->features;
1044 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
1048 vu_dev->features = vdev->features | supported;
1050 return vhost_user_set_features(vu_dev, vu_dev->features);
1055 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
1057 return vu_dev->pdev->name;
1077 struct virtio_uml_device *vu_dev = to_virtio_uml_device(vdev);
1082 if (vu_dev->req_fd >= 0) {
1083 um_free_irq(VIRTIO_IRQ, vu_dev);
1084 os_close_file(vu_dev->req_fd);
1087 os_close_file(vu_dev->sock);
1088 kfree(vu_dev);
1096 struct virtio_uml_device *vu_dev;
1102 vu_dev = kzalloc(sizeof(*vu_dev), GFP_KERNEL);
1103 if (!vu_dev)
1106 vu_dev->vdev.dev.parent = &pdev->dev;
1107 vu_dev->vdev.dev.release = virtio_uml_release_dev;
1108 vu_dev->vdev.config = &virtio_uml_config_ops;
1109 vu_dev->vdev.id.device = pdata->virtio_device_id;
1110 vu_dev->vdev.id.vendor = VIRTIO_DEV_ANY_ID;
1111 vu_dev->pdev = pdev;
1112 vu_dev->req_fd = -1;
1121 vu_dev->sock = rc;
1123 spin_lock_init(&vu_dev->sock_lock);
1125 rc = vhost_user_init(vu_dev);
1129 platform_set_drvdata(pdev, vu_dev);
1131 rc = register_virtio_device(&vu_dev->vdev);
1133 put_device(&vu_dev->vdev.dev);
1134 vu_dev->registered = 1;
1138 os_close_file(vu_dev->sock);
1140 kfree(vu_dev);
1146 struct virtio_uml_device *vu_dev = platform_get_drvdata(pdev);
1148 unregister_virtio_device(&vu_dev->vdev);