Lines Matching +full:5 +full:vs
257 static void vhost_scsi_init_inflight(struct vhost_scsi *vs, in vhost_scsi_init_inflight() argument
265 vq = &vs->vqs[i].vq; in vhost_scsi_init_inflight()
270 idx = vs->vqs[i].inflight_idx; in vhost_scsi_init_inflight()
272 old_inflight[i] = &vs->vqs[i].inflights[idx]; in vhost_scsi_init_inflight()
275 vs->vqs[i].inflight_idx = idx ^ 1; in vhost_scsi_init_inflight()
276 new_inflight = &vs->vqs[i].inflights[idx ^ 1]; in vhost_scsi_init_inflight()
384 struct vhost_scsi *vs = cmd->tvc_vhost; in vhost_scsi_release_cmd() local
386 llist_add(&cmd->tvc_completion_list, &vs->vs_completion_list); in vhost_scsi_release_cmd()
387 vhost_work_queue(&vs->dev, &vs->vs_completion_work); in vhost_scsi_release_cmd()
439 static void vhost_scsi_free_evt(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_free_evt() argument
441 vs->vs_events_nr--; in vhost_scsi_free_evt()
446 vhost_scsi_allocate_evt(struct vhost_scsi *vs, in vhost_scsi_allocate_evt() argument
449 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_allocate_evt()
452 if (vs->vs_events_nr > VHOST_SCSI_MAX_EVENT) { in vhost_scsi_allocate_evt()
453 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
460 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
466 vs->vs_events_nr++; in vhost_scsi_allocate_evt()
477 vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_do_evt_work() argument
479 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_evt_work()
486 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
491 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_do_evt_work()
496 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
500 if (vhost_enable_notify(&vs->dev, vq)) in vhost_scsi_do_evt_work()
502 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
509 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
513 if (vs->vs_events_missed) { in vhost_scsi_do_evt_work()
515 vs->vs_events_missed = false; in vhost_scsi_do_evt_work()
521 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_do_evt_work()
528 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, in vhost_scsi_evt_work() local
530 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_evt_work()
535 llnode = llist_del_all(&vs->vs_event_list); in vhost_scsi_evt_work()
537 vhost_scsi_do_evt_work(vs, evt); in vhost_scsi_evt_work()
538 vhost_scsi_free_evt(vs, evt); in vhost_scsi_evt_work()
550 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, in vhost_scsi_complete_cmd_work() local
561 llnode = llist_del_all(&vs->vs_completion_list); in vhost_scsi_complete_cmd_work()
584 vq = q - vs->vqs; in vhost_scsi_complete_cmd_work()
595 vhost_signal(&vs->dev, &vs->vqs[vq].vq); in vhost_scsi_complete_cmd_work()
823 vhost_scsi_send_bad_target(struct vhost_scsi *vs, in vhost_scsi_send_bad_target() argument
836 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_send_bad_target()
842 vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_get_desc() argument
860 if (unlikely(vhost_enable_notify(&vs->dev, vq))) { in vhost_scsi_get_desc()
861 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_get_desc()
945 vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_handle_vq() argument
973 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_handle_vq()
976 ret = vhost_scsi_get_desc(vs, vq, &vc); in vhost_scsi_handle_vq()
1013 * iovec sizes + incoming iovec sizes vs. virtio-scsi request + in vhost_scsi_handle_vq()
1110 cmd->tvc_vhost = vs; in vhost_scsi_handle_vq()
1154 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); in vhost_scsi_handle_vq()
1161 vhost_scsi_send_tmf_resp(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_send_tmf_resp() argument
1177 vhost_add_used_and_signal(&vs->dev, vq, vq_desc, 0); in vhost_scsi_send_tmf_resp()
1199 vhost_scsi_handle_tmf(struct vhost_scsi *vs, struct vhost_scsi_tpg *tpg, in vhost_scsi_handle_tmf() argument
1230 tmf->vhost = vs; in vhost_scsi_handle_tmf()
1248 vhost_scsi_send_tmf_resp(vs, vq, vc->in, vc->head, &vq->iov[vc->out], in vhost_scsi_handle_tmf()
1253 vhost_scsi_send_an_resp(struct vhost_scsi *vs, in vhost_scsi_send_an_resp() argument
1269 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); in vhost_scsi_send_an_resp()
1275 vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_ctl_handle_vq() argument
1297 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_ctl_handle_vq()
1300 ret = vhost_scsi_get_desc(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1364 vhost_scsi_handle_tmf(vs, tpg, vq, &v_req.tmf, &vc); in vhost_scsi_ctl_handle_vq()
1366 vhost_scsi_send_an_resp(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1377 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); in vhost_scsi_ctl_handle_vq()
1387 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_ctl_handle_kick() local
1390 vhost_scsi_ctl_handle_vq(vs, vq); in vhost_scsi_ctl_handle_kick()
1394 vhost_scsi_send_evt(struct vhost_scsi *vs, in vhost_scsi_send_evt() argument
1402 evt = vhost_scsi_allocate_evt(vs, event, reason); in vhost_scsi_send_evt()
1419 llist_add(&evt->list, &vs->vs_event_list); in vhost_scsi_send_evt()
1420 vhost_work_queue(&vs->dev, &vs->vs_event_work); in vhost_scsi_send_evt()
1427 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_evt_handle_kick() local
1433 if (vs->vs_events_missed) in vhost_scsi_evt_handle_kick()
1434 vhost_scsi_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); in vhost_scsi_evt_handle_kick()
1443 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_handle_kick() local
1445 vhost_scsi_handle_vq(vs, vq); in vhost_scsi_handle_kick()
1448 static void vhost_scsi_flush_vq(struct vhost_scsi *vs, int index) in vhost_scsi_flush_vq() argument
1450 vhost_poll_flush(&vs->vqs[index].vq.poll); in vhost_scsi_flush_vq()
1454 static void vhost_scsi_flush(struct vhost_scsi *vs) in vhost_scsi_flush() argument
1460 vhost_scsi_init_inflight(vs, old_inflight); in vhost_scsi_flush()
1472 vhost_scsi_flush_vq(vs, i); in vhost_scsi_flush()
1473 vhost_work_flush(&vs->dev, &vs->vs_completion_work); in vhost_scsi_flush()
1474 vhost_work_flush(&vs->dev, &vs->vs_event_work); in vhost_scsi_flush()
1563 * vhost_scsi_mutex -> vs->dev.mutex -> tpg->tv_tpg_mutex -> vq->mutex
1566 vhost_scsi_set_endpoint(struct vhost_scsi *vs, in vhost_scsi_set_endpoint() argument
1578 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1581 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_set_endpoint()
1583 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_set_endpoint()
1595 if (vs->vs_tpg) in vhost_scsi_set_endpoint()
1596 memcpy(vs_tpg, vs->vs_tpg, len); in vhost_scsi_set_endpoint()
1611 if (vs->vs_tpg && vs->vs_tpg[tpg->tport_tpgt]) { in vhost_scsi_set_endpoint()
1630 tpg->vhost_scsi = vs; in vhost_scsi_set_endpoint()
1638 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn, in vhost_scsi_set_endpoint()
1639 sizeof(vs->vs_vhost_wwpn)); in vhost_scsi_set_endpoint()
1642 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1651 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1664 * old vs->vs_tpg is finished. in vhost_scsi_set_endpoint()
1666 vhost_scsi_flush(vs); in vhost_scsi_set_endpoint()
1667 kfree(vs->vs_tpg); in vhost_scsi_set_endpoint()
1668 vs->vs_tpg = vs_tpg; in vhost_scsi_set_endpoint()
1673 if (!vhost_vq_get_backend(&vs->vqs[i].vq)) in vhost_scsi_set_endpoint()
1674 vhost_scsi_destroy_vq_cmds(&vs->vqs[i].vq); in vhost_scsi_set_endpoint()
1686 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1692 vhost_scsi_clear_endpoint(struct vhost_scsi *vs, in vhost_scsi_clear_endpoint() argument
1704 mutex_lock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1706 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_clear_endpoint()
1707 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_clear_endpoint()
1713 if (!vs->vs_tpg) { in vhost_scsi_clear_endpoint()
1720 tpg = vs->vs_tpg[target]; in vhost_scsi_clear_endpoint()
1741 vs->vs_tpg[target] = NULL; in vhost_scsi_clear_endpoint()
1753 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
1761 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1767 * old vs->vs_tpg is finished. in vhost_scsi_clear_endpoint()
1769 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1770 kfree(vs->vs_tpg); in vhost_scsi_clear_endpoint()
1771 vs->vs_tpg = NULL; in vhost_scsi_clear_endpoint()
1772 WARN_ON(vs->vs_events_nr); in vhost_scsi_clear_endpoint()
1773 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1780 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1785 static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) in vhost_scsi_set_features() argument
1793 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_features()
1795 !vhost_log_access_ok(&vs->dev)) { in vhost_scsi_set_features()
1796 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1801 vq = &vs->vqs[i].vq; in vhost_scsi_set_features()
1806 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1812 struct vhost_scsi *vs; in vhost_scsi_open() local
1816 vs = kzalloc(sizeof(*vs), GFP_KERNEL | __GFP_NOWARN | __GFP_RETRY_MAYFAIL); in vhost_scsi_open()
1817 if (!vs) { in vhost_scsi_open()
1818 vs = vzalloc(sizeof(*vs)); in vhost_scsi_open()
1819 if (!vs) in vhost_scsi_open()
1827 vhost_work_init(&vs->vs_completion_work, vhost_scsi_complete_cmd_work); in vhost_scsi_open()
1828 vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); in vhost_scsi_open()
1830 vs->vs_events_nr = 0; in vhost_scsi_open()
1831 vs->vs_events_missed = false; in vhost_scsi_open()
1833 vqs[VHOST_SCSI_VQ_CTL] = &vs->vqs[VHOST_SCSI_VQ_CTL].vq; in vhost_scsi_open()
1834 vqs[VHOST_SCSI_VQ_EVT] = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_open()
1835 vs->vqs[VHOST_SCSI_VQ_CTL].vq.handle_kick = vhost_scsi_ctl_handle_kick; in vhost_scsi_open()
1836 vs->vqs[VHOST_SCSI_VQ_EVT].vq.handle_kick = vhost_scsi_evt_handle_kick; in vhost_scsi_open()
1838 vqs[i] = &vs->vqs[i].vq; in vhost_scsi_open()
1839 vs->vqs[i].vq.handle_kick = vhost_scsi_handle_kick; in vhost_scsi_open()
1841 vhost_dev_init(&vs->dev, vqs, VHOST_SCSI_MAX_VQ, UIO_MAXIOV, in vhost_scsi_open()
1844 vhost_scsi_init_inflight(vs, NULL); in vhost_scsi_open()
1846 f->private_data = vs; in vhost_scsi_open()
1850 kvfree(vs); in vhost_scsi_open()
1857 struct vhost_scsi *vs = f->private_data; in vhost_scsi_release() local
1860 mutex_lock(&vs->dev.mutex); in vhost_scsi_release()
1861 memcpy(t.vhost_wwpn, vs->vs_vhost_wwpn, sizeof(t.vhost_wwpn)); in vhost_scsi_release()
1862 mutex_unlock(&vs->dev.mutex); in vhost_scsi_release()
1863 vhost_scsi_clear_endpoint(vs, &t); in vhost_scsi_release()
1864 vhost_dev_stop(&vs->dev); in vhost_scsi_release()
1865 vhost_dev_cleanup(&vs->dev); in vhost_scsi_release()
1867 vhost_scsi_flush(vs); in vhost_scsi_release()
1868 kfree(vs->dev.vqs); in vhost_scsi_release()
1869 kvfree(vs); in vhost_scsi_release()
1878 struct vhost_scsi *vs = f->private_data; in vhost_scsi_ioctl() local
1886 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_ioctl()
1895 return vhost_scsi_set_endpoint(vs, &backend); in vhost_scsi_ioctl()
1902 return vhost_scsi_clear_endpoint(vs, &backend); in vhost_scsi_ioctl()
1911 vs->vs_events_missed = events_missed; in vhost_scsi_ioctl()
1916 events_missed = vs->vs_events_missed; in vhost_scsi_ioctl()
1929 return vhost_scsi_set_features(vs, features); in vhost_scsi_ioctl()
1931 mutex_lock(&vs->dev.mutex); in vhost_scsi_ioctl()
1932 r = vhost_dev_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
1935 r = vhost_vring_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
1936 mutex_unlock(&vs->dev.mutex); in vhost_scsi_ioctl()
1987 struct vhost_scsi *vs = tpg->vhost_scsi; in vhost_scsi_do_plug() local
1991 if (!vs) in vhost_scsi_do_plug()
1994 mutex_lock(&vs->dev.mutex); in vhost_scsi_do_plug()
2001 vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_plug()
2004 vhost_scsi_send_evt(vs, tpg, lun, in vhost_scsi_do_plug()
2007 mutex_unlock(&vs->dev.mutex); in vhost_scsi_do_plug()
2312 if (kstrtou16(name + 5, 10, &tpgt) || tpgt >= VHOST_SCSI_MAX_TARGET) in vhost_scsi_make_tpg()