Lines Matching refs:vs

220 static void vhost_scsi_init_inflight(struct vhost_scsi *vs,  in vhost_scsi_init_inflight()  argument
228 vq = &vs->vqs[i].vq; in vhost_scsi_init_inflight()
233 idx = vs->vqs[i].inflight_idx; in vhost_scsi_init_inflight()
235 old_inflight[i] = &vs->vqs[i].inflights[idx]; in vhost_scsi_init_inflight()
238 vs->vqs[i].inflight_idx = idx ^ 1; in vhost_scsi_init_inflight()
239 new_inflight = &vs->vqs[i].inflights[idx ^ 1]; in vhost_scsi_init_inflight()
358 struct vhost_scsi *vs = cmd->tvc_vhost; in vhost_scsi_complete_cmd() local
360 llist_add(&cmd->tvc_completion_list, &vs->vs_completion_list); in vhost_scsi_complete_cmd()
362 vhost_work_queue(&vs->dev, &vs->vs_completion_work); in vhost_scsi_complete_cmd()
391 static void vhost_scsi_free_evt(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_free_evt() argument
393 vs->vs_events_nr--; in vhost_scsi_free_evt()
398 vhost_scsi_allocate_evt(struct vhost_scsi *vs, in vhost_scsi_allocate_evt() argument
401 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_allocate_evt()
404 if (vs->vs_events_nr > VHOST_SCSI_MAX_EVENT) { in vhost_scsi_allocate_evt()
405 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
412 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
418 vs->vs_events_nr++; in vhost_scsi_allocate_evt()
438 vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_do_evt_work() argument
440 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_evt_work()
447 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
452 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_do_evt_work()
457 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
461 if (vhost_enable_notify(&vs->dev, vq)) in vhost_scsi_do_evt_work()
463 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
470 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
474 if (vs->vs_events_missed) { in vhost_scsi_do_evt_work()
476 vs->vs_events_missed = false; in vhost_scsi_do_evt_work()
482 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_do_evt_work()
489 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, in vhost_scsi_evt_work() local
491 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_evt_work()
496 llnode = llist_del_all(&vs->vs_event_list); in vhost_scsi_evt_work()
498 vhost_scsi_do_evt_work(vs, evt); in vhost_scsi_evt_work()
499 vhost_scsi_free_evt(vs, evt); in vhost_scsi_evt_work()
511 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, in vhost_scsi_complete_cmd_work() local
522 llnode = llist_del_all(&vs->vs_completion_list); in vhost_scsi_complete_cmd_work()
545 vq = q - vs->vqs; in vhost_scsi_complete_cmd_work()
556 vhost_signal(&vs->dev, &vs->vqs[vq].vq); in vhost_scsi_complete_cmd_work()
785 vhost_scsi_send_bad_target(struct vhost_scsi *vs, in vhost_scsi_send_bad_target() argument
798 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_send_bad_target()
804 vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_handle_vq() argument
831 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_handle_vq()
844 if (unlikely(vhost_enable_notify(&vs->dev, vq))) { in vhost_scsi_handle_vq()
845 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_handle_vq()
894 vhost_scsi_send_bad_target(vs, vq, head, out); in vhost_scsi_handle_vq()
900 vhost_scsi_send_bad_target(vs, vq, head, out); in vhost_scsi_handle_vq()
907 vhost_scsi_send_bad_target(vs, vq, head, out); in vhost_scsi_handle_vq()
953 vhost_scsi_send_bad_target(vs, vq, head, out); in vhost_scsi_handle_vq()
961 vhost_scsi_send_bad_target(vs, vq, head, out); in vhost_scsi_handle_vq()
999 vhost_scsi_send_bad_target(vs, vq, head, out); in vhost_scsi_handle_vq()
1008 vhost_scsi_send_bad_target(vs, vq, head, out); in vhost_scsi_handle_vq()
1011 cmd->tvc_vhost = vs; in vhost_scsi_handle_vq()
1028 vhost_scsi_send_bad_target(vs, vq, head, out); in vhost_scsi_handle_vq()
1057 vhost_scsi_send_evt(struct vhost_scsi *vs, in vhost_scsi_send_evt() argument
1065 evt = vhost_scsi_allocate_evt(vs, event, reason); in vhost_scsi_send_evt()
1082 llist_add(&evt->list, &vs->vs_event_list); in vhost_scsi_send_evt()
1083 vhost_work_queue(&vs->dev, &vs->vs_event_work); in vhost_scsi_send_evt()
1090 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_evt_handle_kick() local
1096 if (vs->vs_events_missed) in vhost_scsi_evt_handle_kick()
1097 vhost_scsi_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); in vhost_scsi_evt_handle_kick()
1106 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_handle_kick() local
1108 vhost_scsi_handle_vq(vs, vq); in vhost_scsi_handle_kick()
1111 static void vhost_scsi_flush_vq(struct vhost_scsi *vs, int index) in vhost_scsi_flush_vq() argument
1113 vhost_poll_flush(&vs->vqs[index].vq.poll); in vhost_scsi_flush_vq()
1117 static void vhost_scsi_flush(struct vhost_scsi *vs) in vhost_scsi_flush() argument
1123 vhost_scsi_init_inflight(vs, old_inflight); in vhost_scsi_flush()
1135 vhost_scsi_flush_vq(vs, i); in vhost_scsi_flush()
1136 vhost_work_flush(&vs->dev, &vs->vs_completion_work); in vhost_scsi_flush()
1137 vhost_work_flush(&vs->dev, &vs->vs_event_work); in vhost_scsi_flush()
1152 vhost_scsi_set_endpoint(struct vhost_scsi *vs, in vhost_scsi_set_endpoint() argument
1164 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1167 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_set_endpoint()
1169 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_set_endpoint()
1181 if (vs->vs_tpg) in vhost_scsi_set_endpoint()
1182 memcpy(vs_tpg, vs->vs_tpg, len); in vhost_scsi_set_endpoint()
1197 if (vs->vs_tpg && vs->vs_tpg[tpg->tport_tpgt]) { in vhost_scsi_set_endpoint()
1218 tpg->vhost_scsi = vs; in vhost_scsi_set_endpoint()
1227 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn, in vhost_scsi_set_endpoint()
1228 sizeof(vs->vs_vhost_wwpn)); in vhost_scsi_set_endpoint()
1230 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1245 vhost_scsi_flush(vs); in vhost_scsi_set_endpoint()
1246 kfree(vs->vs_tpg); in vhost_scsi_set_endpoint()
1247 vs->vs_tpg = vs_tpg; in vhost_scsi_set_endpoint()
1250 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1256 vhost_scsi_clear_endpoint(struct vhost_scsi *vs, in vhost_scsi_clear_endpoint() argument
1268 mutex_lock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1270 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_clear_endpoint()
1271 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_clear_endpoint()
1277 if (!vs->vs_tpg) { in vhost_scsi_clear_endpoint()
1284 tpg = vs->vs_tpg[target]; in vhost_scsi_clear_endpoint()
1305 vs->vs_tpg[target] = NULL; in vhost_scsi_clear_endpoint()
1317 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
1327 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1328 kfree(vs->vs_tpg); in vhost_scsi_clear_endpoint()
1329 vs->vs_tpg = NULL; in vhost_scsi_clear_endpoint()
1330 WARN_ON(vs->vs_events_nr); in vhost_scsi_clear_endpoint()
1331 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1338 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1343 static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) in vhost_scsi_set_features() argument
1351 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_features()
1353 !vhost_log_access_ok(&vs->dev)) { in vhost_scsi_set_features()
1354 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1359 vq = &vs->vqs[i].vq; in vhost_scsi_set_features()
1364 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1370 struct vhost_scsi *vs; in vhost_scsi_open() local
1374 vs = kzalloc(sizeof(*vs), GFP_KERNEL | __GFP_NOWARN | __GFP_RETRY_MAYFAIL); in vhost_scsi_open()
1375 if (!vs) { in vhost_scsi_open()
1376 vs = vzalloc(sizeof(*vs)); in vhost_scsi_open()
1377 if (!vs) in vhost_scsi_open()
1385 vhost_work_init(&vs->vs_completion_work, vhost_scsi_complete_cmd_work); in vhost_scsi_open()
1386 vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); in vhost_scsi_open()
1388 vs->vs_events_nr = 0; in vhost_scsi_open()
1389 vs->vs_events_missed = false; in vhost_scsi_open()
1391 vqs[VHOST_SCSI_VQ_CTL] = &vs->vqs[VHOST_SCSI_VQ_CTL].vq; in vhost_scsi_open()
1392 vqs[VHOST_SCSI_VQ_EVT] = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_open()
1393 vs->vqs[VHOST_SCSI_VQ_CTL].vq.handle_kick = vhost_scsi_ctl_handle_kick; in vhost_scsi_open()
1394 vs->vqs[VHOST_SCSI_VQ_EVT].vq.handle_kick = vhost_scsi_evt_handle_kick; in vhost_scsi_open()
1396 vqs[i] = &vs->vqs[i].vq; in vhost_scsi_open()
1397 vs->vqs[i].vq.handle_kick = vhost_scsi_handle_kick; in vhost_scsi_open()
1399 vhost_dev_init(&vs->dev, vqs, VHOST_SCSI_MAX_VQ); in vhost_scsi_open()
1401 vhost_scsi_init_inflight(vs, NULL); in vhost_scsi_open()
1403 f->private_data = vs; in vhost_scsi_open()
1407 kvfree(vs); in vhost_scsi_open()
1414 struct vhost_scsi *vs = f->private_data; in vhost_scsi_release() local
1417 mutex_lock(&vs->dev.mutex); in vhost_scsi_release()
1418 memcpy(t.vhost_wwpn, vs->vs_vhost_wwpn, sizeof(t.vhost_wwpn)); in vhost_scsi_release()
1419 mutex_unlock(&vs->dev.mutex); in vhost_scsi_release()
1420 vhost_scsi_clear_endpoint(vs, &t); in vhost_scsi_release()
1421 vhost_dev_stop(&vs->dev); in vhost_scsi_release()
1422 vhost_dev_cleanup(&vs->dev); in vhost_scsi_release()
1424 vhost_scsi_flush(vs); in vhost_scsi_release()
1425 kfree(vs->dev.vqs); in vhost_scsi_release()
1426 kvfree(vs); in vhost_scsi_release()
1435 struct vhost_scsi *vs = f->private_data; in vhost_scsi_ioctl() local
1443 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_ioctl()
1452 return vhost_scsi_set_endpoint(vs, &backend); in vhost_scsi_ioctl()
1459 return vhost_scsi_clear_endpoint(vs, &backend); in vhost_scsi_ioctl()
1468 vs->vs_events_missed = events_missed; in vhost_scsi_ioctl()
1473 events_missed = vs->vs_events_missed; in vhost_scsi_ioctl()
1486 return vhost_scsi_set_features(vs, features); in vhost_scsi_ioctl()
1488 mutex_lock(&vs->dev.mutex); in vhost_scsi_ioctl()
1489 r = vhost_dev_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
1492 r = vhost_vring_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
1493 mutex_unlock(&vs->dev.mutex); in vhost_scsi_ioctl()
1554 struct vhost_scsi *vs = tpg->vhost_scsi; in vhost_scsi_do_plug() local
1558 if (!vs) in vhost_scsi_do_plug()
1561 mutex_lock(&vs->dev.mutex); in vhost_scsi_do_plug()
1568 vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_plug()
1571 vhost_scsi_send_evt(vs, tpg, lun, in vhost_scsi_do_plug()
1574 mutex_unlock(&vs->dev.mutex); in vhost_scsi_do_plug()