Lines Matching refs:vu_dev

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