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()
806 vhost_scsi_send_bad_target(struct vhost_scsi *vs, in vhost_scsi_send_bad_target() argument
819 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_send_bad_target()
825 vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_get_desc() argument
843 if (unlikely(vhost_enable_notify(&vs->dev, vq))) { in vhost_scsi_get_desc()
844 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_get_desc()
928 vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_handle_vq() argument
956 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_handle_vq()
959 ret = vhost_scsi_get_desc(vs, vq, &vc); in vhost_scsi_handle_vq()
1093 cmd->tvc_vhost = vs; in vhost_scsi_handle_vq()
1130 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); in vhost_scsi_handle_vq()
1137 vhost_scsi_send_tmf_resp(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_send_tmf_resp() argument
1153 vhost_add_used_and_signal(&vs->dev, vq, vq_desc, 0); in vhost_scsi_send_tmf_resp()
1175 vhost_scsi_handle_tmf(struct vhost_scsi *vs, struct vhost_scsi_tpg *tpg, in vhost_scsi_handle_tmf() argument
1206 tmf->vhost = vs; in vhost_scsi_handle_tmf()
1224 vhost_scsi_send_tmf_resp(vs, vq, vc->in, vc->head, &vq->iov[vc->out], in vhost_scsi_handle_tmf()
1229 vhost_scsi_send_an_resp(struct vhost_scsi *vs, in vhost_scsi_send_an_resp() argument
1245 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); in vhost_scsi_send_an_resp()
1251 vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_ctl_handle_vq() argument
1273 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_ctl_handle_vq()
1276 ret = vhost_scsi_get_desc(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1340 vhost_scsi_handle_tmf(vs, tpg, vq, &v_req.tmf, &vc); in vhost_scsi_ctl_handle_vq()
1342 vhost_scsi_send_an_resp(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1353 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); in vhost_scsi_ctl_handle_vq()
1363 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_ctl_handle_kick() local
1366 vhost_scsi_ctl_handle_vq(vs, vq); in vhost_scsi_ctl_handle_kick()
1370 vhost_scsi_send_evt(struct vhost_scsi *vs, in vhost_scsi_send_evt() argument
1378 evt = vhost_scsi_allocate_evt(vs, event, reason); in vhost_scsi_send_evt()
1395 llist_add(&evt->list, &vs->vs_event_list); in vhost_scsi_send_evt()
1396 vhost_work_queue(&vs->dev, &vs->vs_event_work); in vhost_scsi_send_evt()
1403 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_evt_handle_kick() local
1409 if (vs->vs_events_missed) in vhost_scsi_evt_handle_kick()
1410 vhost_scsi_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); in vhost_scsi_evt_handle_kick()
1419 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_handle_kick() local
1421 vhost_scsi_handle_vq(vs, vq); in vhost_scsi_handle_kick()
1425 static void vhost_scsi_flush(struct vhost_scsi *vs) in vhost_scsi_flush() argument
1430 vhost_scsi_init_inflight(vs, vs->old_inflight); in vhost_scsi_flush()
1437 for (i = 0; i < vs->dev.nvqs; i++) in vhost_scsi_flush()
1438 kref_put(&vs->old_inflight[i]->kref, vhost_scsi_done_inflight); in vhost_scsi_flush()
1441 vhost_dev_flush(&vs->dev); in vhost_scsi_flush()
1444 for (i = 0; i < vs->dev.nvqs; i++) in vhost_scsi_flush()
1445 wait_for_completion(&vs->old_inflight[i]->comp); in vhost_scsi_flush()
1533 vhost_scsi_set_endpoint(struct vhost_scsi *vs, in vhost_scsi_set_endpoint() argument
1545 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1548 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_set_endpoint()
1550 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_set_endpoint()
1562 if (vs->vs_tpg) in vhost_scsi_set_endpoint()
1563 memcpy(vs_tpg, vs->vs_tpg, len); in vhost_scsi_set_endpoint()
1578 if (vs->vs_tpg && vs->vs_tpg[tpg->tport_tpgt]) { in vhost_scsi_set_endpoint()
1597 tpg->vhost_scsi = vs; in vhost_scsi_set_endpoint()
1605 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn, in vhost_scsi_set_endpoint()
1606 sizeof(vs->vs_vhost_wwpn)); in vhost_scsi_set_endpoint()
1608 for (i = VHOST_SCSI_VQ_IO; i < vs->dev.nvqs; i++) { in vhost_scsi_set_endpoint()
1609 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1618 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_set_endpoint()
1619 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1634 vhost_scsi_flush(vs); in vhost_scsi_set_endpoint()
1635 kfree(vs->vs_tpg); in vhost_scsi_set_endpoint()
1636 vs->vs_tpg = vs_tpg; in vhost_scsi_set_endpoint()
1641 if (!vhost_vq_get_backend(&vs->vqs[i].vq)) in vhost_scsi_set_endpoint()
1642 vhost_scsi_destroy_vq_cmds(&vs->vqs[i].vq); in vhost_scsi_set_endpoint()
1654 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1660 vhost_scsi_clear_endpoint(struct vhost_scsi *vs, in vhost_scsi_clear_endpoint() argument
1672 mutex_lock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1674 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_clear_endpoint()
1675 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_clear_endpoint()
1681 if (!vs->vs_tpg) { in vhost_scsi_clear_endpoint()
1688 tpg = vs->vs_tpg[target]; in vhost_scsi_clear_endpoint()
1709 vs->vs_tpg[target] = NULL; in vhost_scsi_clear_endpoint()
1720 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_clear_endpoint()
1721 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
1727 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1729 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_clear_endpoint()
1730 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
1738 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1739 kfree(vs->vs_tpg); in vhost_scsi_clear_endpoint()
1740 vs->vs_tpg = NULL; in vhost_scsi_clear_endpoint()
1741 WARN_ON(vs->vs_events_nr); in vhost_scsi_clear_endpoint()
1742 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1749 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1754 static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) in vhost_scsi_set_features() argument
1762 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_features()
1764 !vhost_log_access_ok(&vs->dev)) { in vhost_scsi_set_features()
1765 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1769 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_set_features()
1770 vq = &vs->vqs[i].vq; in vhost_scsi_set_features()
1775 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1781 struct vhost_scsi *vs; in vhost_scsi_open() local
1785 vs = kvzalloc(sizeof(*vs), GFP_KERNEL); in vhost_scsi_open()
1786 if (!vs) in vhost_scsi_open()
1799 vs->compl_bitmap = bitmap_alloc(nvqs, GFP_KERNEL); in vhost_scsi_open()
1800 if (!vs->compl_bitmap) in vhost_scsi_open()
1803 vs->old_inflight = kmalloc_array(nvqs, sizeof(*vs->old_inflight), in vhost_scsi_open()
1805 if (!vs->old_inflight) in vhost_scsi_open()
1808 vs->vqs = kmalloc_array(nvqs, sizeof(*vs->vqs), in vhost_scsi_open()
1810 if (!vs->vqs) in vhost_scsi_open()
1817 vhost_work_init(&vs->vs_completion_work, vhost_scsi_complete_cmd_work); in vhost_scsi_open()
1818 vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); in vhost_scsi_open()
1820 vs->vs_events_nr = 0; in vhost_scsi_open()
1821 vs->vs_events_missed = false; in vhost_scsi_open()
1823 vqs[VHOST_SCSI_VQ_CTL] = &vs->vqs[VHOST_SCSI_VQ_CTL].vq; in vhost_scsi_open()
1824 vqs[VHOST_SCSI_VQ_EVT] = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_open()
1825 vs->vqs[VHOST_SCSI_VQ_CTL].vq.handle_kick = vhost_scsi_ctl_handle_kick; in vhost_scsi_open()
1826 vs->vqs[VHOST_SCSI_VQ_EVT].vq.handle_kick = vhost_scsi_evt_handle_kick; in vhost_scsi_open()
1828 vqs[i] = &vs->vqs[i].vq; in vhost_scsi_open()
1829 vs->vqs[i].vq.handle_kick = vhost_scsi_handle_kick; in vhost_scsi_open()
1831 vhost_dev_init(&vs->dev, vqs, nvqs, UIO_MAXIOV, in vhost_scsi_open()
1834 vhost_scsi_init_inflight(vs, NULL); in vhost_scsi_open()
1836 f->private_data = vs; in vhost_scsi_open()
1840 kfree(vs->vqs); in vhost_scsi_open()
1842 kfree(vs->old_inflight); in vhost_scsi_open()
1844 bitmap_free(vs->compl_bitmap); in vhost_scsi_open()
1846 kvfree(vs); in vhost_scsi_open()
1853 struct vhost_scsi *vs = f->private_data; in vhost_scsi_release() local
1856 mutex_lock(&vs->dev.mutex); in vhost_scsi_release()
1857 memcpy(t.vhost_wwpn, vs->vs_vhost_wwpn, sizeof(t.vhost_wwpn)); in vhost_scsi_release()
1858 mutex_unlock(&vs->dev.mutex); in vhost_scsi_release()
1859 vhost_scsi_clear_endpoint(vs, &t); in vhost_scsi_release()
1860 vhost_dev_stop(&vs->dev); in vhost_scsi_release()
1861 vhost_dev_cleanup(&vs->dev); in vhost_scsi_release()
1862 kfree(vs->dev.vqs); in vhost_scsi_release()
1863 kfree(vs->vqs); in vhost_scsi_release()
1864 kfree(vs->old_inflight); in vhost_scsi_release()
1865 bitmap_free(vs->compl_bitmap); in vhost_scsi_release()
1866 kvfree(vs); in vhost_scsi_release()
1875 struct vhost_scsi *vs = f->private_data; in vhost_scsi_ioctl() local
1883 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_ioctl()
1892 return vhost_scsi_set_endpoint(vs, &backend); in vhost_scsi_ioctl()
1899 return vhost_scsi_clear_endpoint(vs, &backend); in vhost_scsi_ioctl()
1908 vs->vs_events_missed = events_missed; in vhost_scsi_ioctl()
1913 events_missed = vs->vs_events_missed; in vhost_scsi_ioctl()
1926 return vhost_scsi_set_features(vs, features); in vhost_scsi_ioctl()
1928 mutex_lock(&vs->dev.mutex); in vhost_scsi_ioctl()
1929 r = vhost_dev_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
1932 r = vhost_vring_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
1933 mutex_unlock(&vs->dev.mutex); in vhost_scsi_ioctl()
1984 struct vhost_scsi *vs = tpg->vhost_scsi; in vhost_scsi_do_plug() local
1988 if (!vs) in vhost_scsi_do_plug()
1991 mutex_lock(&vs->dev.mutex); in vhost_scsi_do_plug()
1998 vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_plug()
2001 vhost_scsi_send_evt(vs, tpg, lun, in vhost_scsi_do_plug()
2004 mutex_unlock(&vs->dev.mutex); in vhost_scsi_do_plug()