Skip to content

Commit e4648b0

Browse files
iliastsiNicholas Bellinger
authored andcommitted
target/user: Add support for bidirectional commands
Enable TCMU to handle bidirectional SCSI commands. In such cases, entries in iov[] cover both the Data-In and the Data-Out buffers. The first iov_cnt entries correspond to the Data-Out buffer, while the remaining iov_bidi_cnt entries correspond to the Data-In buffer. Signed-off-by: Ilias Tsitsimpis <iliastsi@arrikto.com> Signed-off-by: Vangelis Koukis <vkoukis@arrikto.com> Reviewed-by: Andy Grover <agrover@redhat.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent f97ec7d commit e4648b0

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎Documentation/target/tcmu-design.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ overall shared memory region, not the entry. The data in/out buffers
152152
are accessible via tht req.iov[] array. iov_cnt contains the number of
153153
entries in iov[] needed to describe either the Data-In or Data-Out
154154
buffers. For bidirectional commands, iov_cnt specifies how many iovec
155-
entries cover the Data-Out area, and iov_bidi_count specifies how many
155+
entries cover the Data-Out area, and iov_bidi_cnt specifies how many
156156
iovec entries immediately after that in iov[] cover the Data-In
157157
area. Just like other fields, iov.iov_base is an offset from the start
158158
of the region.

‎drivers/target/target_core_user.c‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ static struct tcmu_cmd *tcmu_alloc_cmd(struct se_cmd *se_cmd)
167167
tcmu_cmd->tcmu_dev = udev;
168168
tcmu_cmd->data_length = se_cmd->data_length;
169169

170+
if (se_cmd->se_cmd_flags & SCF_BIDI) {
171+
BUG_ON(!(se_cmd->t_bidi_data_sg && se_cmd->t_bidi_data_nents));
172+
tcmu_cmd->data_length += se_cmd->t_bidi_data_sg->length;
173+
}
174+
170175
tcmu_cmd->deadline = jiffies + msecs_to_jiffies(TCMU_TIME_OUT);
171176

172177
idr_preload(GFP_KERNEL);
@@ -387,7 +392,8 @@ static int tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
387392
* b/c size == offsetof one-past-element.
388393
*/
389394
base_command_size = max(offsetof(struct tcmu_cmd_entry,
390-
req.iov[se_cmd->t_data_nents + 2]),
395+
req.iov[se_cmd->t_bidi_data_nents +
396+
se_cmd->t_data_nents + 2]),
391397
sizeof(struct tcmu_cmd_entry));
392398
command_size = base_command_size
393399
+ round_up(scsi_command_size(se_cmd->t_task_cdb), TCMU_OP_ALIGN_SIZE);
@@ -456,13 +462,19 @@ static int tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
456462
*/
457463
iov = &entry->req.iov[0];
458464
iov_cnt = 0;
459-
copy_to_data_area = (se_cmd->data_direction == DMA_TO_DEVICE);
465+
copy_to_data_area = (se_cmd->data_direction == DMA_TO_DEVICE
466+
|| se_cmd->se_cmd_flags & SCF_BIDI);
460467
alloc_and_scatter_data_area(udev, se_cmd->t_data_sg,
461468
se_cmd->t_data_nents, &iov, &iov_cnt, copy_to_data_area);
462469
entry->req.iov_cnt = iov_cnt;
463-
entry->req.iov_bidi_cnt = 0;
464470
entry->req.iov_dif_cnt = 0;
465471

472+
/* Handle BIDI commands */
473+
iov_cnt = 0;
474+
alloc_and_scatter_data_area(udev, se_cmd->t_bidi_data_sg,
475+
se_cmd->t_bidi_data_nents, &iov, &iov_cnt, false);
476+
entry->req.iov_bidi_cnt = iov_cnt;
477+
466478
/* All offsets relative to mb_addr, not start of entry! */
467479
cdb_off = CMDR_OFF + cmd_head + base_command_size;
468480
memcpy((void *) mb + cdb_off, se_cmd->t_task_cdb, scsi_command_size(se_cmd->t_task_cdb));
@@ -535,8 +547,15 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry *
535547
se_cmd->scsi_sense_length);
536548

537549
UPDATE_HEAD(udev->data_tail, cmd->data_length, udev->data_size);
538-
}
539-
else if (se_cmd->data_direction == DMA_FROM_DEVICE) {
550+
} else if (se_cmd->se_cmd_flags & SCF_BIDI) {
551+
/* Discard data_out buffer */
552+
UPDATE_HEAD(udev->data_tail,
553+
(size_t)se_cmd->t_data_sg->length, udev->data_size);
554+
555+
/* Get Data-In buffer */
556+
gather_and_free_data_area(udev,
557+
se_cmd->t_bidi_data_sg, se_cmd->t_bidi_data_nents);
558+
} else if (se_cmd->data_direction == DMA_FROM_DEVICE) {
540559
gather_and_free_data_area(udev,
541560
se_cmd->t_data_sg, se_cmd->t_data_nents);
542561
} else if (se_cmd->data_direction == DMA_TO_DEVICE) {

0 commit comments

Comments
 (0)