Lines Matching defs:cmd
75 /* The number of scatterlists associated with this cmd */
91 /* Pointer to vhost_virtqueue for the cmd */
103 /* Used to track inflight cmd */
370 struct vhost_scsi_cmd *cmd = container_of(se_cmd,
372 struct vhost_scsi_virtqueue *svq = container_of(cmd->tvc_vq,
375 llist_add(&cmd->tvc_completion_list, &svq->completion_list);
517 static int vhost_scsi_copy_sgl_to_iov(struct vhost_scsi_cmd *cmd)
519 struct iov_iter *iter = &cmd->saved_iter;
520 struct scatterlist *sg = cmd->tvc_sgl;
525 for (i = 0; i < cmd->tvc_sgl_count; i++) {
530 pr_err("Could not copy data while handling misaligned cmd. Error %zu\n",
549 struct vhost_scsi_cmd *cmd, *t;
557 llist_for_each_entry_safe(cmd, t, llnode, tvc_completion_list) {
558 se_cmd = &cmd->tvc_se_cmd;
561 cmd, se_cmd->residual_count, se_cmd->scsi_status);
564 if (cmd->saved_iter_addr && vhost_scsi_copy_sgl_to_iov(cmd)) {
567 v_rsp.resid = cpu_to_vhost32(cmd->tvc_vq,
571 v_rsp.sense_len = cpu_to_vhost32(cmd->tvc_vq,
573 memcpy(v_rsp.sense, cmd->tvc_sense_buf,
577 iov_iter_init(&iov_iter, ITER_DEST, cmd->tvc_resp_iov,
578 cmd->tvc_in_iovs, sizeof(v_rsp));
583 vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0);
601 struct vhost_scsi_cmd *cmd;
620 cmd = &svq->scsi_cmds[tag];
621 sg = cmd->tvc_sgl;
622 prot_sg = cmd->tvc_prot_sgl;
623 pages = cmd->tvc_upages;
624 tvc_resp_iov = cmd->tvc_resp_iov;
625 memset(cmd, 0, sizeof(*cmd));
626 cmd->tvc_sgl = sg;
627 cmd->tvc_prot_sgl = prot_sg;
628 cmd->tvc_upages = pages;
629 cmd->tvc_se_cmd.map_tag = tag;
630 cmd->tvc_tag = scsi_tag;
631 cmd->tvc_lun = lun;
632 cmd->tvc_task_attr = task_attr;
633 cmd->tvc_exp_data_len = exp_data_len;
634 cmd->tvc_data_direction = data_direction;
635 cmd->tvc_nexus = tv_nexus;
636 cmd->inflight = vhost_scsi_get_inflight(vq);
637 cmd->tvc_resp_iov = tvc_resp_iov;
639 memcpy(cmd->tvc_cdb, cdb, VHOST_SCSI_MAX_CDB_SIZE);
641 return cmd;
650 vhost_scsi_map_to_sgl(struct vhost_scsi_cmd *cmd,
655 struct page **pages = cmd->tvc_upages;
676 * sizes if we have to break up a cmd/scatterlist into multiple
681 * greater than the max and if a vec in the cmd has a
686 cmd->tvc_sgl_count > BIO_MAX_VECS) {
737 vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
745 if (cmd->tvc_data_direction == DMA_FROM_DEVICE) {
746 cmd->saved_iter_addr = dup_iter(&cmd->saved_iter, iter,
748 if (!cmd->saved_iter_addr)
762 if (cmd->tvc_data_direction == DMA_TO_DEVICE &&
769 cmd->copied_iov = 1;
773 pr_err("Could not read %u bytes while handling misaligned cmd\n",
778 kfree(cmd->saved_iter_addr);
783 vhost_scsi_map_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter,
791 ret = vhost_scsi_map_to_sgl(cmd, iter, sg, is_prot);
815 vhost_scsi_mapal(struct vhost_scsi_cmd *cmd,
827 sg_init_table(cmd->tvc_prot_sgl, sgl_count);
828 cmd->tvc_prot_sgl_count = sgl_count;
830 cmd->tvc_prot_sgl, cmd->tvc_prot_sgl_count);
832 ret = vhost_scsi_map_iov_to_sgl(cmd, prot_iter,
833 cmd->tvc_prot_sgl,
834 cmd->tvc_prot_sgl_count, true);
836 cmd->tvc_prot_sgl_count = 0;
845 sg_init_table(cmd->tvc_sgl, sgl_count);
846 cmd->tvc_sgl_count = sgl_count;
848 cmd->tvc_sgl, cmd->tvc_sgl_count);
850 ret = vhost_scsi_map_iov_to_sgl(cmd, data_iter, cmd->tvc_sgl,
851 cmd->tvc_sgl_count, false);
853 sg_init_table(cmd->tvc_sgl, cmd->tvc_sgl_count);
854 ret = vhost_scsi_copy_iov_to_sgl(cmd, data_iter, cmd->tvc_sgl,
855 cmd->tvc_sgl_count);
859 cmd->tvc_sgl_count = 0;
882 static void vhost_scsi_target_queue_cmd(struct vhost_scsi_cmd *cmd)
884 struct se_cmd *se_cmd = &cmd->tvc_se_cmd;
889 if (cmd->tvc_sgl_count) {
890 sg_ptr = cmd->tvc_sgl;
892 if (cmd->tvc_prot_sgl_count)
893 sg_prot_ptr = cmd->tvc_prot_sgl;
899 tv_nexus = cmd->tvc_nexus;
902 target_init_cmd(se_cmd, tv_nexus->tvn_se_sess, &cmd->tvc_sense_buf[0],
903 cmd->tvc_lun, cmd->tvc_exp_data_len,
904 vhost_scsi_to_tcm_attr(cmd->tvc_task_attr),
905 cmd->tvc_data_direction, TARGET_SCF_ACK_KREF);
907 if (target_submit_prep(se_cmd, cmd->tvc_cdb, sg_ptr,
908 cmd->tvc_sgl_count, NULL, 0, sg_prot_ptr,
909 cmd->tvc_prot_sgl_count, GFP_KERNEL))
1044 struct vhost_scsi_cmd *cmd;
1185 * cmd descriptor for the new virtio-scsi tag.
1195 cmd = vhost_scsi_get_cmd(vq, tpg, cdb, tag, lun, task_attr,
1198 if (IS_ERR(cmd)) {
1200 PTR_ERR(cmd));
1203 cmd->tvc_vhost = vs;
1204 cmd->tvc_vq = vq;
1206 cmd->tvc_resp_iov[i] = vq->iov[vc.out + i];
1207 cmd->tvc_in_iovs = vc.in;
1210 cmd->tvc_cdb[0], cmd->tvc_lun);
1211 pr_debug("cmd: %p exp_data_len: %d, prot_bytes: %d data_direction:"
1212 " %d\n", cmd, exp_data_len, prot_bytes, data_direction);
1215 if (unlikely(vhost_scsi_mapal(cmd, prot_bytes,
1219 vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd);
1228 cmd->tvc_vq_desc = vc.head;
1229 vhost_scsi_target_queue_cmd(cmd);