Lines Matching +full:5 +full:vs

215 	struct vhost_scsi *vs;  member
302 static void vhost_scsi_init_inflight(struct vhost_scsi *vs, in vhost_scsi_init_inflight() argument
309 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_init_inflight()
310 vq = &vs->vqs[i].vq; in vhost_scsi_init_inflight()
315 idx = vs->vqs[i].inflight_idx; in vhost_scsi_init_inflight()
317 old_inflight[i] = &vs->vqs[i].inflights[idx]; in vhost_scsi_init_inflight()
320 vs->vqs[i].inflight_idx = idx ^ 1; in vhost_scsi_init_inflight()
321 new_inflight = &vs->vqs[i].inflights[idx ^ 1]; in vhost_scsi_init_inflight()
421 struct vhost_scsi *vs = svq->vs; in vhost_scsi_release_cmd_res() local
440 sg_free_table_chained(&tv_cmd->table, vs->inline_sg_cnt); in vhost_scsi_release_cmd_res()
448 sg_free_table_chained(&tv_cmd->prot_table, vs->inline_sg_cnt); in vhost_scsi_release_cmd_res()
531 static void vhost_scsi_free_evt(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_free_evt() argument
533 vs->vs_events_nr--; in vhost_scsi_free_evt()
538 vhost_scsi_allocate_evt(struct vhost_scsi *vs, in vhost_scsi_allocate_evt() argument
541 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_allocate_evt()
544 if (vs->vs_events_nr > VHOST_SCSI_MAX_EVENT) { in vhost_scsi_allocate_evt()
545 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
552 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
558 vs->vs_events_nr++; in vhost_scsi_allocate_evt()
569 vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_do_evt_work() argument
571 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_evt_work()
580 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
585 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_do_evt_work()
600 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
604 if (vhost_enable_notify(&vs->dev, vq)) in vhost_scsi_do_evt_work()
606 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
613 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
617 if (vs->vs_events_missed) { in vhost_scsi_do_evt_work()
619 vs->vs_events_missed = false; in vhost_scsi_do_evt_work()
625 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_do_evt_work()
632 static void vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop) in vhost_scsi_complete_events() argument
634 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_complete_events()
639 llnode = llist_del_all(&vs->vs_event_list); in vhost_scsi_complete_events()
642 vhost_scsi_do_evt_work(vs, evt); in vhost_scsi_complete_events()
643 vhost_scsi_free_evt(vs, evt); in vhost_scsi_complete_events()
650 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, in vhost_scsi_evt_work() local
652 vhost_scsi_complete_events(vs, false); in vhost_scsi_evt_work()
740 vhost_signal(&svq->vs->dev, &svq->vq); in vhost_scsi_complete_cmd_work()
965 vhost_scsi_mapal(struct vhost_scsi *vs, struct vhost_scsi_cmd *cmd, in vhost_scsi_mapal() argument
977 vs->inline_sg_cnt); in vhost_scsi_mapal()
990 vs->inline_sg_cnt); in vhost_scsi_mapal()
1002 vs->inline_sg_cnt); in vhost_scsi_mapal()
1016 sg_free_table_chained(&cmd->table, vs->inline_sg_cnt); in vhost_scsi_mapal()
1075 vhost_scsi_send_status(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_send_status() argument
1091 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); in vhost_scsi_send_status()
1101 vhost_scsi_send_bad_target(struct vhost_scsi *vs, in vhost_scsi_send_bad_target() argument
1133 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); in vhost_scsi_send_bad_target()
1139 vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_get_desc() argument
1161 if (unlikely(vhost_enable_notify(&vs->dev, vq))) { in vhost_scsi_get_desc()
1162 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_get_desc()
1284 vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_handle_vq() argument
1315 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_handle_vq()
1321 ret = vhost_scsi_get_desc(vs, vq, &vc, vq_log, &log_num); in vhost_scsi_handle_vq()
1358 * iovec sizes + incoming iovec sizes vs. virtio-scsi request + in vhost_scsi_handle_vq()
1484 ret = vhost_scsi_mapal(vs, cmd, prot_bytes, &prot_iter, in vhost_scsi_handle_vq()
1514 vhost_scsi_send_bad_target(vs, vq, &vc, TYPE_IO_CMD); in vhost_scsi_handle_vq()
1517 vhost_scsi_send_status(vs, vq, &vc, in vhost_scsi_handle_vq()
1527 vhost_scsi_send_tmf_resp(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_send_tmf_resp() argument
1543 vhost_add_used_and_signal(&vs->dev, vq, vq_desc, 0); in vhost_scsi_send_tmf_resp()
1584 vhost_scsi_handle_tmf(struct vhost_scsi *vs, struct vhost_scsi_tpg *tpg, in vhost_scsi_handle_tmf() argument
1609 tmf->vhost = vs; in vhost_scsi_handle_tmf()
1640 vhost_scsi_send_tmf_resp(vs, vq, vc->in, vc->head, &vq->iov[vc->out], in vhost_scsi_handle_tmf()
1646 vhost_scsi_send_an_resp(struct vhost_scsi *vs, in vhost_scsi_send_an_resp() argument
1662 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); in vhost_scsi_send_an_resp()
1668 vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_ctl_handle_vq() argument
1692 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_ctl_handle_vq()
1698 ret = vhost_scsi_get_desc(vs, vq, &vc, vq_log, &log_num); in vhost_scsi_ctl_handle_vq()
1762 vhost_scsi_handle_tmf(vs, tpg, vq, &v_req.tmf, &vc, in vhost_scsi_ctl_handle_vq()
1765 vhost_scsi_send_an_resp(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1778 vhost_scsi_send_bad_target(vs, vq, &vc, in vhost_scsi_ctl_handle_vq()
1793 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_ctl_handle_kick() local
1796 vhost_scsi_ctl_handle_vq(vs, vq); in vhost_scsi_ctl_handle_kick()
1800 vhost_scsi_send_evt(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_send_evt() argument
1806 evt = vhost_scsi_allocate_evt(vs, event, reason); in vhost_scsi_send_evt()
1823 llist_add(&evt->list, &vs->vs_event_list); in vhost_scsi_send_evt()
1824 if (!vhost_vq_work_queue(vq, &vs->vs_event_work)) in vhost_scsi_send_evt()
1825 vhost_scsi_complete_events(vs, true); in vhost_scsi_send_evt()
1832 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_evt_handle_kick() local
1838 if (vs->vs_events_missed) in vhost_scsi_evt_handle_kick()
1839 vhost_scsi_send_evt(vs, vq, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, in vhost_scsi_evt_handle_kick()
1849 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_handle_kick() local
1851 vhost_scsi_handle_vq(vs, vq); in vhost_scsi_handle_kick()
1855 static void vhost_scsi_flush(struct vhost_scsi *vs) in vhost_scsi_flush() argument
1860 vhost_scsi_init_inflight(vs, vs->old_inflight); in vhost_scsi_flush()
1867 for (i = 0; i < vs->dev.nvqs; i++) in vhost_scsi_flush()
1868 kref_put(&vs->old_inflight[i]->kref, vhost_scsi_done_inflight); in vhost_scsi_flush()
1871 vhost_dev_flush(&vs->dev); in vhost_scsi_flush()
1874 for (i = 0; i < vs->dev.nvqs; i++) in vhost_scsi_flush()
1875 wait_for_completion(&vs->old_inflight[i]->comp); in vhost_scsi_flush()
1924 struct vhost_scsi *vs = svq->vs; in vhost_scsi_setup_vq_cmds() local
1950 if (vs->inline_sg_cnt) { in vhost_scsi_setup_vq_cmds()
1951 tv_cmd->sgl = kcalloc(vs->inline_sg_cnt, in vhost_scsi_setup_vq_cmds()
1961 vs->inline_sg_cnt) { in vhost_scsi_setup_vq_cmds()
1962 tv_cmd->prot_sgl = kcalloc(vs->inline_sg_cnt, in vhost_scsi_setup_vq_cmds()
1982 * vs->dev.mutex -> vhost_scsi_mutex -> tpg->tv_tpg_mutex -> vq->mutex
1985 vhost_scsi_set_endpoint(struct vhost_scsi *vs, in vhost_scsi_set_endpoint() argument
1996 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1999 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_set_endpoint()
2001 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_set_endpoint()
2007 if (vs->vs_tpg) { in vhost_scsi_set_endpoint()
2009 vs->vs_vhost_wwpn); in vhost_scsi_set_endpoint()
2050 tpg->vhost_scsi = vs; in vhost_scsi_set_endpoint()
2059 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn, in vhost_scsi_set_endpoint()
2060 sizeof(vs->vs_vhost_wwpn)); in vhost_scsi_set_endpoint()
2062 for (i = VHOST_SCSI_VQ_IO; i < vs->dev.nvqs; i++) { in vhost_scsi_set_endpoint()
2063 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
2072 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_set_endpoint()
2073 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
2089 vhost_scsi_flush(vs); in vhost_scsi_set_endpoint()
2090 vs->vs_tpg = vs_tpg; in vhost_scsi_set_endpoint()
2095 if (!vhost_vq_get_backend(&vs->vqs[i].vq)) in vhost_scsi_set_endpoint()
2096 vhost_scsi_destroy_vq_cmds(&vs->vqs[i].vq); in vhost_scsi_set_endpoint()
2112 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
2117 vhost_scsi_clear_endpoint(struct vhost_scsi *vs, in vhost_scsi_clear_endpoint() argument
2128 mutex_lock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
2130 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_clear_endpoint()
2131 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_clear_endpoint()
2137 if (!vs->vs_tpg) { in vhost_scsi_clear_endpoint()
2144 tpg = vs->vs_tpg[target]; in vhost_scsi_clear_endpoint()
2168 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_clear_endpoint()
2169 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
2175 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
2177 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_clear_endpoint()
2178 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
2188 tpg = vs->vs_tpg[target]; in vhost_scsi_clear_endpoint()
2196 vs->vs_tpg[target] = NULL; in vhost_scsi_clear_endpoint()
2207 * old vs->vs_tpg is finished. in vhost_scsi_clear_endpoint()
2209 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
2210 kfree(vs->vs_tpg); in vhost_scsi_clear_endpoint()
2211 vs->vs_tpg = NULL; in vhost_scsi_clear_endpoint()
2212 memset(vs->vs_vhost_wwpn, 0, sizeof(vs->vs_vhost_wwpn)); in vhost_scsi_clear_endpoint()
2213 WARN_ON(vs->vs_events_nr); in vhost_scsi_clear_endpoint()
2214 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
2218 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
2222 static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) in vhost_scsi_set_features() argument
2231 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_features()
2233 !vhost_log_access_ok(&vs->dev)) { in vhost_scsi_set_features()
2234 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
2238 if (!vs->dev.nvqs) in vhost_scsi_set_features()
2245 was_log = vhost_has_feature(&vs->vqs[0].vq, VHOST_F_LOG_ALL); in vhost_scsi_set_features()
2247 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_set_features()
2248 vq = &vs->vqs[i].vq; in vhost_scsi_set_features()
2259 for (i = VHOST_SCSI_VQ_IO; i < vs->dev.nvqs; i++) { in vhost_scsi_set_features()
2260 if (!vs->vqs[i].scsi_cmds) in vhost_scsi_set_features()
2263 vq = &vs->vqs[i].vq; in vhost_scsi_set_features()
2271 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
2278 struct vhost_scsi *vs; in vhost_scsi_open() local
2282 vs = kvzalloc(sizeof(*vs), GFP_KERNEL); in vhost_scsi_open()
2283 if (!vs) in vhost_scsi_open()
2285 vs->inline_sg_cnt = vhost_scsi_inline_sg_cnt; in vhost_scsi_open()
2297 vs->old_inflight = kmalloc_array(nvqs, sizeof(*vs->old_inflight), in vhost_scsi_open()
2299 if (!vs->old_inflight) in vhost_scsi_open()
2302 vs->vqs = kmalloc_array(nvqs, sizeof(*vs->vqs), in vhost_scsi_open()
2304 if (!vs->vqs) in vhost_scsi_open()
2311 vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); in vhost_scsi_open()
2313 vs->vs_events_nr = 0; in vhost_scsi_open()
2314 vs->vs_events_missed = false; in vhost_scsi_open()
2316 vqs[VHOST_SCSI_VQ_CTL] = &vs->vqs[VHOST_SCSI_VQ_CTL].vq; in vhost_scsi_open()
2317 vqs[VHOST_SCSI_VQ_EVT] = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_open()
2318 vs->vqs[VHOST_SCSI_VQ_CTL].vq.handle_kick = vhost_scsi_ctl_handle_kick; in vhost_scsi_open()
2319 vs->vqs[VHOST_SCSI_VQ_EVT].vq.handle_kick = vhost_scsi_evt_handle_kick; in vhost_scsi_open()
2321 svq = &vs->vqs[i]; in vhost_scsi_open()
2324 svq->vs = vs; in vhost_scsi_open()
2330 vhost_dev_init(&vs->dev, vqs, nvqs, UIO_MAXIOV, in vhost_scsi_open()
2333 vhost_scsi_init_inflight(vs, NULL); in vhost_scsi_open()
2335 f->private_data = vs; in vhost_scsi_open()
2339 kfree(vs->vqs); in vhost_scsi_open()
2341 kfree(vs->old_inflight); in vhost_scsi_open()
2343 kvfree(vs); in vhost_scsi_open()
2350 struct vhost_scsi *vs = f->private_data; in vhost_scsi_release() local
2353 mutex_lock(&vs->dev.mutex); in vhost_scsi_release()
2354 memcpy(t.vhost_wwpn, vs->vs_vhost_wwpn, sizeof(t.vhost_wwpn)); in vhost_scsi_release()
2355 mutex_unlock(&vs->dev.mutex); in vhost_scsi_release()
2356 vhost_scsi_clear_endpoint(vs, &t); in vhost_scsi_release()
2357 vhost_dev_stop(&vs->dev); in vhost_scsi_release()
2358 vhost_dev_cleanup(&vs->dev); in vhost_scsi_release()
2359 kfree(vs->dev.vqs); in vhost_scsi_release()
2360 kfree(vs->vqs); in vhost_scsi_release()
2361 kfree(vs->old_inflight); in vhost_scsi_release()
2362 kvfree(vs); in vhost_scsi_release()
2371 struct vhost_scsi *vs = f->private_data; in vhost_scsi_ioctl() local
2379 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_ioctl()
2388 return vhost_scsi_set_endpoint(vs, &backend); in vhost_scsi_ioctl()
2395 return vhost_scsi_clear_endpoint(vs, &backend); in vhost_scsi_ioctl()
2404 vs->vs_events_missed = events_missed; in vhost_scsi_ioctl()
2409 events_missed = vs->vs_events_missed; in vhost_scsi_ioctl()
2422 return vhost_scsi_set_features(vs, features); in vhost_scsi_ioctl()
2427 mutex_lock(&vs->dev.mutex); in vhost_scsi_ioctl()
2428 r = vhost_worker_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
2429 mutex_unlock(&vs->dev.mutex); in vhost_scsi_ioctl()
2432 mutex_lock(&vs->dev.mutex); in vhost_scsi_ioctl()
2433 r = vhost_dev_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
2436 r = vhost_vring_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
2437 mutex_unlock(&vs->dev.mutex); in vhost_scsi_ioctl()
2488 struct vhost_scsi *vs = tpg->vhost_scsi; in vhost_scsi_do_plug() local
2492 if (!vs) in vhost_scsi_do_plug()
2500 vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_plug()
2510 vhost_scsi_send_evt(vs, vq, tpg, lun, in vhost_scsi_do_plug()
2795 if (kstrtou16(name + 5, 10, &tpgt) || tpgt >= VHOST_SCSI_MAX_TARGET) in vhost_scsi_make_tpg()