Lines Matching refs:vs

247 static void vhost_scsi_init_inflight(struct vhost_scsi *vs,  in vhost_scsi_init_inflight()  argument
254 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_init_inflight()
255 vq = &vs->vqs[i].vq; in vhost_scsi_init_inflight()
260 idx = vs->vqs[i].inflight_idx; in vhost_scsi_init_inflight()
262 old_inflight[i] = &vs->vqs[i].inflights[idx]; in vhost_scsi_init_inflight()
265 vs->vqs[i].inflight_idx = idx ^ 1; in vhost_scsi_init_inflight()
266 new_inflight = &vs->vqs[i].inflights[idx ^ 1]; in vhost_scsi_init_inflight()
374 struct vhost_scsi *vs = cmd->tvc_vhost; in vhost_scsi_release_cmd() local
376 llist_add(&cmd->tvc_completion_list, &vs->vs_completion_list); in vhost_scsi_release_cmd()
377 vhost_work_queue(&vs->dev, &vs->vs_completion_work); in vhost_scsi_release_cmd()
429 static void vhost_scsi_free_evt(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_free_evt() argument
431 vs->vs_events_nr--; in vhost_scsi_free_evt()
436 vhost_scsi_allocate_evt(struct vhost_scsi *vs, in vhost_scsi_allocate_evt() argument
439 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_allocate_evt()
442 if (vs->vs_events_nr > VHOST_SCSI_MAX_EVENT) { in vhost_scsi_allocate_evt()
443 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
450 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
456 vs->vs_events_nr++; in vhost_scsi_allocate_evt()
467 vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_do_evt_work() argument
469 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_evt_work()
476 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
481 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_do_evt_work()
486 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
490 if (vhost_enable_notify(&vs->dev, vq)) in vhost_scsi_do_evt_work()
492 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
499 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
503 if (vs->vs_events_missed) { in vhost_scsi_do_evt_work()
505 vs->vs_events_missed = false; in vhost_scsi_do_evt_work()
511 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_do_evt_work()
518 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, in vhost_scsi_evt_work() local
520 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_evt_work()
525 llnode = llist_del_all(&vs->vs_event_list); in vhost_scsi_evt_work()
527 vhost_scsi_do_evt_work(vs, evt); in vhost_scsi_evt_work()
528 vhost_scsi_free_evt(vs, evt); in vhost_scsi_evt_work()
540 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, in vhost_scsi_complete_cmd_work() local
549 bitmap_zero(vs->compl_bitmap, vs->dev.nvqs); in vhost_scsi_complete_cmd_work()
550 llnode = llist_del_all(&vs->vs_completion_list); in vhost_scsi_complete_cmd_work()
573 vq = q - vs->vqs; in vhost_scsi_complete_cmd_work()
574 __set_bit(vq, vs->compl_bitmap); in vhost_scsi_complete_cmd_work()
582 while ((vq = find_next_bit(vs->compl_bitmap, vs->dev.nvqs, vq + 1)) in vhost_scsi_complete_cmd_work()
583 < vs->dev.nvqs) in vhost_scsi_complete_cmd_work()
584 vhost_signal(&vs->dev, &vs->vqs[vq].vq); in vhost_scsi_complete_cmd_work()
809 vhost_scsi_send_bad_target(struct vhost_scsi *vs, in vhost_scsi_send_bad_target() argument
822 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_send_bad_target()
828 vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_get_desc() argument
846 if (unlikely(vhost_enable_notify(&vs->dev, vq))) { in vhost_scsi_get_desc()
847 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_get_desc()
931 vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_handle_vq() argument
959 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_handle_vq()
962 ret = vhost_scsi_get_desc(vs, vq, &vc); in vhost_scsi_handle_vq()
1096 cmd->tvc_vhost = vs; in vhost_scsi_handle_vq()
1134 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); in vhost_scsi_handle_vq()
1141 vhost_scsi_send_tmf_resp(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_send_tmf_resp() argument
1157 vhost_add_used_and_signal(&vs->dev, vq, vq_desc, 0); in vhost_scsi_send_tmf_resp()
1179 vhost_scsi_handle_tmf(struct vhost_scsi *vs, struct vhost_scsi_tpg *tpg, in vhost_scsi_handle_tmf() argument
1210 tmf->vhost = vs; in vhost_scsi_handle_tmf()
1228 vhost_scsi_send_tmf_resp(vs, vq, vc->in, vc->head, &vq->iov[vc->out], in vhost_scsi_handle_tmf()
1233 vhost_scsi_send_an_resp(struct vhost_scsi *vs, in vhost_scsi_send_an_resp() argument
1249 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); in vhost_scsi_send_an_resp()
1255 vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_ctl_handle_vq() argument
1277 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_ctl_handle_vq()
1280 ret = vhost_scsi_get_desc(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1344 vhost_scsi_handle_tmf(vs, tpg, vq, &v_req.tmf, &vc); in vhost_scsi_ctl_handle_vq()
1346 vhost_scsi_send_an_resp(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1357 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); in vhost_scsi_ctl_handle_vq()
1367 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_ctl_handle_kick() local
1370 vhost_scsi_ctl_handle_vq(vs, vq); in vhost_scsi_ctl_handle_kick()
1374 vhost_scsi_send_evt(struct vhost_scsi *vs, in vhost_scsi_send_evt() argument
1382 evt = vhost_scsi_allocate_evt(vs, event, reason); in vhost_scsi_send_evt()
1399 llist_add(&evt->list, &vs->vs_event_list); in vhost_scsi_send_evt()
1400 vhost_work_queue(&vs->dev, &vs->vs_event_work); in vhost_scsi_send_evt()
1407 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_evt_handle_kick() local
1413 if (vs->vs_events_missed) in vhost_scsi_evt_handle_kick()
1414 vhost_scsi_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); in vhost_scsi_evt_handle_kick()
1423 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_handle_kick() local
1425 vhost_scsi_handle_vq(vs, vq); in vhost_scsi_handle_kick()
1429 static void vhost_scsi_flush(struct vhost_scsi *vs) in vhost_scsi_flush() argument
1434 vhost_scsi_init_inflight(vs, vs->old_inflight); in vhost_scsi_flush()
1441 for (i = 0; i < vs->dev.nvqs; i++) in vhost_scsi_flush()
1442 kref_put(&vs->old_inflight[i]->kref, vhost_scsi_done_inflight); in vhost_scsi_flush()
1445 vhost_dev_flush(&vs->dev); in vhost_scsi_flush()
1448 for (i = 0; i < vs->dev.nvqs; i++) in vhost_scsi_flush()
1449 wait_for_completion(&vs->old_inflight[i]->comp); in vhost_scsi_flush()
1546 vhost_scsi_set_endpoint(struct vhost_scsi *vs, in vhost_scsi_set_endpoint() argument
1558 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1561 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_set_endpoint()
1563 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_set_endpoint()
1575 if (vs->vs_tpg) in vhost_scsi_set_endpoint()
1576 memcpy(vs_tpg, vs->vs_tpg, len); in vhost_scsi_set_endpoint()
1591 if (vs->vs_tpg && vs->vs_tpg[tpg->tport_tpgt]) { in vhost_scsi_set_endpoint()
1610 tpg->vhost_scsi = vs; in vhost_scsi_set_endpoint()
1618 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn, in vhost_scsi_set_endpoint()
1619 sizeof(vs->vs_vhost_wwpn)); in vhost_scsi_set_endpoint()
1621 for (i = VHOST_SCSI_VQ_IO; i < vs->dev.nvqs; i++) { in vhost_scsi_set_endpoint()
1622 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1631 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_set_endpoint()
1632 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1647 vhost_scsi_flush(vs); in vhost_scsi_set_endpoint()
1648 kfree(vs->vs_tpg); in vhost_scsi_set_endpoint()
1649 vs->vs_tpg = vs_tpg; in vhost_scsi_set_endpoint()
1654 if (!vhost_vq_get_backend(&vs->vqs[i].vq)) in vhost_scsi_set_endpoint()
1655 vhost_scsi_destroy_vq_cmds(&vs->vqs[i].vq); in vhost_scsi_set_endpoint()
1667 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1673 vhost_scsi_clear_endpoint(struct vhost_scsi *vs, in vhost_scsi_clear_endpoint() argument
1685 mutex_lock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1687 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_clear_endpoint()
1688 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_clear_endpoint()
1694 if (!vs->vs_tpg) { in vhost_scsi_clear_endpoint()
1701 tpg = vs->vs_tpg[target]; in vhost_scsi_clear_endpoint()
1722 vs->vs_tpg[target] = NULL; in vhost_scsi_clear_endpoint()
1733 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_clear_endpoint()
1734 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
1740 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1742 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_clear_endpoint()
1743 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
1751 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1752 kfree(vs->vs_tpg); in vhost_scsi_clear_endpoint()
1753 vs->vs_tpg = NULL; in vhost_scsi_clear_endpoint()
1754 WARN_ON(vs->vs_events_nr); in vhost_scsi_clear_endpoint()
1755 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1762 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1767 static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) in vhost_scsi_set_features() argument
1775 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_features()
1777 !vhost_log_access_ok(&vs->dev)) { in vhost_scsi_set_features()
1778 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1782 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_set_features()
1783 vq = &vs->vqs[i].vq; in vhost_scsi_set_features()
1788 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1794 struct vhost_scsi *vs; in vhost_scsi_open() local
1798 vs = kvzalloc(sizeof(*vs), GFP_KERNEL); in vhost_scsi_open()
1799 if (!vs) in vhost_scsi_open()
1812 vs->compl_bitmap = bitmap_alloc(nvqs, GFP_KERNEL); in vhost_scsi_open()
1813 if (!vs->compl_bitmap) in vhost_scsi_open()
1816 vs->old_inflight = kmalloc_array(nvqs, sizeof(*vs->old_inflight), in vhost_scsi_open()
1818 if (!vs->old_inflight) in vhost_scsi_open()
1821 vs->vqs = kmalloc_array(nvqs, sizeof(*vs->vqs), in vhost_scsi_open()
1823 if (!vs->vqs) in vhost_scsi_open()
1830 vhost_work_init(&vs->vs_completion_work, vhost_scsi_complete_cmd_work); in vhost_scsi_open()
1831 vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); in vhost_scsi_open()
1833 vs->vs_events_nr = 0; in vhost_scsi_open()
1834 vs->vs_events_missed = false; in vhost_scsi_open()
1836 vqs[VHOST_SCSI_VQ_CTL] = &vs->vqs[VHOST_SCSI_VQ_CTL].vq; in vhost_scsi_open()
1837 vqs[VHOST_SCSI_VQ_EVT] = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_open()
1838 vs->vqs[VHOST_SCSI_VQ_CTL].vq.handle_kick = vhost_scsi_ctl_handle_kick; in vhost_scsi_open()
1839 vs->vqs[VHOST_SCSI_VQ_EVT].vq.handle_kick = vhost_scsi_evt_handle_kick; in vhost_scsi_open()
1841 vqs[i] = &vs->vqs[i].vq; in vhost_scsi_open()
1842 vs->vqs[i].vq.handle_kick = vhost_scsi_handle_kick; in vhost_scsi_open()
1844 vhost_dev_init(&vs->dev, vqs, nvqs, UIO_MAXIOV, in vhost_scsi_open()
1847 vhost_scsi_init_inflight(vs, NULL); in vhost_scsi_open()
1849 f->private_data = vs; in vhost_scsi_open()
1853 kfree(vs->vqs); in vhost_scsi_open()
1855 kfree(vs->old_inflight); in vhost_scsi_open()
1857 bitmap_free(vs->compl_bitmap); in vhost_scsi_open()
1859 kvfree(vs); in vhost_scsi_open()
1866 struct vhost_scsi *vs = f->private_data; in vhost_scsi_release() local
1869 mutex_lock(&vs->dev.mutex); in vhost_scsi_release()
1870 memcpy(t.vhost_wwpn, vs->vs_vhost_wwpn, sizeof(t.vhost_wwpn)); in vhost_scsi_release()
1871 mutex_unlock(&vs->dev.mutex); in vhost_scsi_release()
1872 vhost_scsi_clear_endpoint(vs, &t); in vhost_scsi_release()
1873 vhost_dev_stop(&vs->dev); in vhost_scsi_release()
1874 vhost_dev_cleanup(&vs->dev); in vhost_scsi_release()
1875 kfree(vs->dev.vqs); in vhost_scsi_release()
1876 kfree(vs->vqs); in vhost_scsi_release()
1877 kfree(vs->old_inflight); in vhost_scsi_release()
1878 bitmap_free(vs->compl_bitmap); in vhost_scsi_release()
1879 kvfree(vs); in vhost_scsi_release()
1888 struct vhost_scsi *vs = f->private_data; in vhost_scsi_ioctl() local
1896 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_ioctl()
1905 return vhost_scsi_set_endpoint(vs, &backend); in vhost_scsi_ioctl()
1912 return vhost_scsi_clear_endpoint(vs, &backend); in vhost_scsi_ioctl()
1921 vs->vs_events_missed = events_missed; in vhost_scsi_ioctl()
1926 events_missed = vs->vs_events_missed; in vhost_scsi_ioctl()
1939 return vhost_scsi_set_features(vs, features); in vhost_scsi_ioctl()
1941 mutex_lock(&vs->dev.mutex); in vhost_scsi_ioctl()
1942 r = vhost_dev_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
1945 r = vhost_vring_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
1946 mutex_unlock(&vs->dev.mutex); in vhost_scsi_ioctl()
1997 struct vhost_scsi *vs = tpg->vhost_scsi; in vhost_scsi_do_plug() local
2001 if (!vs) in vhost_scsi_do_plug()
2004 mutex_lock(&vs->dev.mutex); in vhost_scsi_do_plug()
2011 vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_plug()
2014 vhost_scsi_send_evt(vs, tpg, lun, in vhost_scsi_do_plug()
2017 mutex_unlock(&vs->dev.mutex); in vhost_scsi_do_plug()