aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c13
-rw-r--r--drivers/target/iscsi/iscsi_target.c2
-rw-r--r--drivers/target/iscsi/iscsi_target_erl1.c2
-rw-r--r--drivers/target/iscsi/iscsi_target_tmr.c6
-rw-r--r--drivers/target/target_core_tmr.c24
-rw-r--r--drivers/target/target_core_transport.c130
-rw-r--r--include/target/target_core_base.h21
7 files changed, 99 insertions, 99 deletions
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 2b73d43cd691..e1e6b5b03c96 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -1378,7 +1378,9 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx)
1378 break; 1378 break;
1379 case SRPT_STATE_NEED_DATA: 1379 case SRPT_STATE_NEED_DATA:
1380 /* DMA_TO_DEVICE (write) - RDMA read error. */ 1380 /* DMA_TO_DEVICE (write) - RDMA read error. */
1381 atomic_set(&ioctx->cmd.transport_lun_stop, 1); 1381 spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
1382 ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
1383 spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
1382 transport_generic_handle_data(&ioctx->cmd); 1384 transport_generic_handle_data(&ioctx->cmd);
1383 break; 1385 break;
1384 case SRPT_STATE_CMD_RSP_SENT: 1386 case SRPT_STATE_CMD_RSP_SENT:
@@ -1387,7 +1389,9 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx)
1387 * not been received in time. 1389 * not been received in time.
1388 */ 1390 */
1389 srpt_unmap_sg_to_ib_sge(ioctx->ch, ioctx); 1391 srpt_unmap_sg_to_ib_sge(ioctx->ch, ioctx);
1390 atomic_set(&ioctx->cmd.transport_lun_stop, 1); 1392 spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
1393 ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
1394 spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
1391 kref_put(&ioctx->kref, srpt_put_send_ioctx_kref); 1395 kref_put(&ioctx->kref, srpt_put_send_ioctx_kref);
1392 break; 1396 break;
1393 case SRPT_STATE_MGMT_RSP_SENT: 1397 case SRPT_STATE_MGMT_RSP_SENT:
@@ -1494,6 +1498,7 @@ static void srpt_handle_rdma_err_comp(struct srpt_rdma_ch *ch,
1494{ 1498{
1495 struct se_cmd *cmd; 1499 struct se_cmd *cmd;
1496 enum srpt_command_state state; 1500 enum srpt_command_state state;
1501 unsigned long flags;
1497 1502
1498 cmd = &ioctx->cmd; 1503 cmd = &ioctx->cmd;
1499 state = srpt_get_cmd_state(ioctx); 1504 state = srpt_get_cmd_state(ioctx);
@@ -1513,7 +1518,9 @@ static void srpt_handle_rdma_err_comp(struct srpt_rdma_ch *ch,
1513 __func__, __LINE__, state); 1518 __func__, __LINE__, state);
1514 break; 1519 break;
1515 case SRPT_RDMA_WRITE_LAST: 1520 case SRPT_RDMA_WRITE_LAST:
1516 atomic_set(&ioctx->cmd.transport_lun_stop, 1); 1521 spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
1522 ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
1523 spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
1517 break; 1524 break;
1518 default: 1525 default:
1519 printk(KERN_ERR "%s[%d]: opcode = %u\n", __func__, 1526 printk(KERN_ERR "%s[%d]: opcode = %u\n", __func__,
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 44262908def5..bf0e8e75a272 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -1363,7 +1363,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
1363 * outstanding_r2ts reaches zero, go ahead and send the delayed 1363 * outstanding_r2ts reaches zero, go ahead and send the delayed
1364 * TASK_ABORTED status. 1364 * TASK_ABORTED status.
1365 */ 1365 */
1366 if (atomic_read(&se_cmd->t_transport_aborted) != 0) { 1366 if (se_cmd->transport_state & CMD_T_ABORTED) {
1367 if (hdr->flags & ISCSI_FLAG_CMD_FINAL) 1367 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
1368 if (--cmd->outstanding_r2ts < 1) { 1368 if (--cmd->outstanding_r2ts < 1) {
1369 iscsit_stop_dataout_timer(cmd); 1369 iscsit_stop_dataout_timer(cmd);
diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
index 27901e37c125..006f605edb08 100644
--- a/drivers/target/iscsi/iscsi_target_erl1.c
+++ b/drivers/target/iscsi/iscsi_target_erl1.c
@@ -416,7 +416,7 @@ static int iscsit_handle_recovery_datain(
416 struct iscsi_datain_req *dr; 416 struct iscsi_datain_req *dr;
417 struct se_cmd *se_cmd = &cmd->se_cmd; 417 struct se_cmd *se_cmd = &cmd->se_cmd;
418 418
419 if (!atomic_read(&se_cmd->t_transport_complete)) { 419 if (!(se_cmd->transport_state & CMD_T_COMPLETE)) {
420 pr_err("Ignoring ITT: 0x%08x Data SNACK\n", 420 pr_err("Ignoring ITT: 0x%08x Data SNACK\n",
421 cmd->init_task_tag); 421 cmd->init_task_tag);
422 return 0; 422 return 0;
diff --git a/drivers/target/iscsi/iscsi_target_tmr.c b/drivers/target/iscsi/iscsi_target_tmr.c
index 255ed35da815..e01da9d2b37e 100644
--- a/drivers/target/iscsi/iscsi_target_tmr.c
+++ b/drivers/target/iscsi/iscsi_target_tmr.c
@@ -250,7 +250,7 @@ static int iscsit_task_reassign_complete_write(
250 * so if we have received all DataOUT we can safety ignore Initiator. 250 * so if we have received all DataOUT we can safety ignore Initiator.
251 */ 251 */
252 if (cmd->cmd_flags & ICF_GOT_LAST_DATAOUT) { 252 if (cmd->cmd_flags & ICF_GOT_LAST_DATAOUT) {
253 if (!atomic_read(&cmd->se_cmd.t_transport_sent)) { 253 if (!(cmd->se_cmd.transport_state & CMD_T_SENT)) {
254 pr_debug("WRITE ITT: 0x%08x: t_state: %d" 254 pr_debug("WRITE ITT: 0x%08x: t_state: %d"
255 " never sent to transport\n", 255 " never sent to transport\n",
256 cmd->init_task_tag, cmd->se_cmd.t_state); 256 cmd->init_task_tag, cmd->se_cmd.t_state);
@@ -314,7 +314,7 @@ static int iscsit_task_reassign_complete_read(
314 cmd->acked_data_sn = (tmr_req->exp_data_sn - 1); 314 cmd->acked_data_sn = (tmr_req->exp_data_sn - 1);
315 } 315 }
316 316
317 if (!atomic_read(&cmd->se_cmd.t_transport_sent)) { 317 if (!(cmd->se_cmd.transport_state & CMD_T_SENT)) {
318 pr_debug("READ ITT: 0x%08x: t_state: %d never sent to" 318 pr_debug("READ ITT: 0x%08x: t_state: %d never sent to"
319 " transport\n", cmd->init_task_tag, 319 " transport\n", cmd->init_task_tag,
320 cmd->se_cmd.t_state); 320 cmd->se_cmd.t_state);
@@ -322,7 +322,7 @@ static int iscsit_task_reassign_complete_read(
322 return 0; 322 return 0;
323 } 323 }
324 324
325 if (!atomic_read(&se_cmd->t_transport_complete)) { 325 if (!(se_cmd->transport_state & CMD_T_COMPLETE)) {
326 pr_err("READ ITT: 0x%08x: t_state: %d, never returned" 326 pr_err("READ ITT: 0x%08x: t_state: %d, never returned"
327 " from transport\n", cmd->init_task_tag, 327 " from transport\n", cmd->init_task_tag,
328 cmd->se_cmd.t_state); 328 cmd->se_cmd.t_state);
diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
index dcb0618c9388..a5c2e41debf8 100644
--- a/drivers/target/target_core_tmr.c
+++ b/drivers/target/target_core_tmr.c
@@ -150,7 +150,7 @@ static void core_tmr_drain_tmr_list(
150 continue; 150 continue;
151 151
152 spin_lock(&cmd->t_state_lock); 152 spin_lock(&cmd->t_state_lock);
153 if (!atomic_read(&cmd->t_transport_active)) { 153 if (!(cmd->transport_state & CMD_T_ACTIVE)) {
154 spin_unlock(&cmd->t_state_lock); 154 spin_unlock(&cmd->t_state_lock);
155 continue; 155 continue;
156 } 156 }
@@ -255,15 +255,15 @@ static void core_tmr_drain_task_list(
255 cmd->t_task_cdb[0]); 255 cmd->t_task_cdb[0]);
256 pr_debug("LUN_RESET: ITT[0x%08x] - pr_res_key: 0x%016Lx" 256 pr_debug("LUN_RESET: ITT[0x%08x] - pr_res_key: 0x%016Lx"
257 " t_task_cdbs: %d t_task_cdbs_left: %d" 257 " t_task_cdbs: %d t_task_cdbs_left: %d"
258 " t_task_cdbs_sent: %d -- t_transport_active: %d" 258 " t_task_cdbs_sent: %d -- CMD_T_ACTIVE: %d"
259 " t_transport_stop: %d t_transport_sent: %d\n", 259 " CMD_T_STOP: %d CMD_T_SENT: %d\n",
260 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key, 260 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
261 cmd->t_task_list_num, 261 cmd->t_task_list_num,
262 atomic_read(&cmd->t_task_cdbs_left), 262 atomic_read(&cmd->t_task_cdbs_left),
263 atomic_read(&cmd->t_task_cdbs_sent), 263 atomic_read(&cmd->t_task_cdbs_sent),
264 atomic_read(&cmd->t_transport_active), 264 (cmd->transport_state & CMD_T_ACTIVE) != 0,
265 atomic_read(&cmd->t_transport_stop), 265 (cmd->transport_state & CMD_T_STOP) != 0,
266 atomic_read(&cmd->t_transport_sent)); 266 (cmd->transport_state & CMD_T_SENT) != 0);
267 267
268 /* 268 /*
269 * If the command may be queued onto a workqueue cancel it now. 269 * If the command may be queued onto a workqueue cancel it now.
@@ -287,19 +287,19 @@ static void core_tmr_drain_task_list(
287 } 287 }
288 fe_count = atomic_read(&cmd->t_fe_count); 288 fe_count = atomic_read(&cmd->t_fe_count);
289 289
290 if (atomic_read(&cmd->t_transport_active)) { 290 if (!(cmd->transport_state & CMD_T_ACTIVE)) {
291 pr_debug("LUN_RESET: got t_transport_active = 1 for" 291 pr_debug("LUN_RESET: got CMD_T_ACTIVE for"
292 " task: %p, t_fe_count: %d dev: %p\n", task, 292 " task: %p, t_fe_count: %d dev: %p\n", task,
293 fe_count, dev); 293 fe_count, dev);
294 atomic_set(&cmd->t_transport_aborted, 1); 294 cmd->transport_state |= CMD_T_ABORTED;
295 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 295 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
296 296
297 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count); 297 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
298 continue; 298 continue;
299 } 299 }
300 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p," 300 pr_debug("LUN_RESET: Got !CMD_T_ACTIVE for task: %p,"
301 " t_fe_count: %d dev: %p\n", task, fe_count, dev); 301 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
302 atomic_set(&cmd->t_transport_aborted, 1); 302 cmd->transport_state |= CMD_T_ABORTED;
303 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 303 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
304 304
305 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count); 305 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
@@ -339,7 +339,7 @@ static void core_tmr_drain_cmd_list(
339 if (prout_cmd == cmd) 339 if (prout_cmd == cmd)
340 continue; 340 continue;
341 341
342 atomic_set(&cmd->t_transport_queue_active, 0); 342 cmd->transport_state &= ~CMD_T_QUEUED;
343 atomic_dec(&qobj->queue_cnt); 343 atomic_dec(&qobj->queue_cnt);
344 list_move_tail(&cmd->se_queue_node, &drain_cmd_list); 344 list_move_tail(&cmd->se_queue_node, &drain_cmd_list);
345 } 345 }
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 58cea07b12fb..f704123752c3 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -437,7 +437,7 @@ static void transport_all_task_dev_remove_state(struct se_cmd *cmd)
437 437
438/* transport_cmd_check_stop(): 438/* transport_cmd_check_stop():
439 * 439 *
440 * 'transport_off = 1' determines if t_transport_active should be cleared. 440 * 'transport_off = 1' determines if CMD_T_ACTIVE should be cleared.
441 * 'transport_off = 2' determines if task_dev_state should be removed. 441 * 'transport_off = 2' determines if task_dev_state should be removed.
442 * 442 *
443 * A non-zero u8 t_state sets cmd->t_state. 443 * A non-zero u8 t_state sets cmd->t_state.
@@ -455,12 +455,11 @@ static int transport_cmd_check_stop(
455 * Determine if IOCTL context caller in requesting the stopping of this 455 * Determine if IOCTL context caller in requesting the stopping of this
456 * command for LUN shutdown purposes. 456 * command for LUN shutdown purposes.
457 */ 457 */
458 if (atomic_read(&cmd->transport_lun_stop)) { 458 if (cmd->transport_state & CMD_T_LUN_STOP) {
459 pr_debug("%s:%d atomic_read(&cmd->transport_lun_stop)" 459 pr_debug("%s:%d CMD_T_LUN_STOP for ITT: 0x%08x\n",
460 " == TRUE for ITT: 0x%08x\n", __func__, __LINE__, 460 __func__, __LINE__, cmd->se_tfo->get_task_tag(cmd));
461 cmd->se_tfo->get_task_tag(cmd));
462 461
463 atomic_set(&cmd->t_transport_active, 0); 462 cmd->transport_state &= ~CMD_T_ACTIVE;
464 if (transport_off == 2) 463 if (transport_off == 2)
465 transport_all_task_dev_remove_state(cmd); 464 transport_all_task_dev_remove_state(cmd);
466 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 465 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
@@ -472,9 +471,9 @@ static int transport_cmd_check_stop(
472 * Determine if frontend context caller is requesting the stopping of 471 * Determine if frontend context caller is requesting the stopping of
473 * this command for frontend exceptions. 472 * this command for frontend exceptions.
474 */ 473 */
475 if (atomic_read(&cmd->t_transport_stop)) { 474 if (cmd->transport_state & CMD_T_STOP) {
476 pr_debug("%s:%d atomic_read(&cmd->t_transport_stop) ==" 475 pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08x\n",
477 " TRUE for ITT: 0x%08x\n", __func__, __LINE__, 476 __func__, __LINE__,
478 cmd->se_tfo->get_task_tag(cmd)); 477 cmd->se_tfo->get_task_tag(cmd));
479 478
480 if (transport_off == 2) 479 if (transport_off == 2)
@@ -492,7 +491,7 @@ static int transport_cmd_check_stop(
492 return 1; 491 return 1;
493 } 492 }
494 if (transport_off) { 493 if (transport_off) {
495 atomic_set(&cmd->t_transport_active, 0); 494 cmd->transport_state &= ~CMD_T_ACTIVE;
496 if (transport_off == 2) { 495 if (transport_off == 2) {
497 transport_all_task_dev_remove_state(cmd); 496 transport_all_task_dev_remove_state(cmd);
498 /* 497 /*
@@ -540,16 +539,12 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd)
540 return; 539 return;
541 540
542 spin_lock_irqsave(&cmd->t_state_lock, flags); 541 spin_lock_irqsave(&cmd->t_state_lock, flags);
543 if (!atomic_read(&cmd->transport_dev_active)) { 542 if (cmd->transport_state & CMD_T_DEV_ACTIVE) {
544 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 543 cmd->transport_state &= ~CMD_T_DEV_ACTIVE;
545 goto check_lun; 544 transport_all_task_dev_remove_state(cmd);
546 } 545 }
547 atomic_set(&cmd->transport_dev_active, 0);
548 transport_all_task_dev_remove_state(cmd);
549 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 546 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
550 547
551
552check_lun:
553 spin_lock_irqsave(&lun->lun_cmd_lock, flags); 548 spin_lock_irqsave(&lun->lun_cmd_lock, flags);
554 if (atomic_read(&cmd->transport_lun_active)) { 549 if (atomic_read(&cmd->transport_lun_active)) {
555 list_del(&cmd->se_lun_node); 550 list_del(&cmd->se_lun_node);
@@ -585,7 +580,7 @@ static void transport_add_cmd_to_queue(struct se_cmd *cmd, int t_state,
585 if (t_state) { 580 if (t_state) {
586 spin_lock_irqsave(&cmd->t_state_lock, flags); 581 spin_lock_irqsave(&cmd->t_state_lock, flags);
587 cmd->t_state = t_state; 582 cmd->t_state = t_state;
588 atomic_set(&cmd->t_transport_active, 1); 583 cmd->transport_state |= CMD_T_ACTIVE;
589 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 584 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
590 } 585 }
591 586
@@ -601,7 +596,7 @@ static void transport_add_cmd_to_queue(struct se_cmd *cmd, int t_state,
601 list_add(&cmd->se_queue_node, &qobj->qobj_list); 596 list_add(&cmd->se_queue_node, &qobj->qobj_list);
602 else 597 else
603 list_add_tail(&cmd->se_queue_node, &qobj->qobj_list); 598 list_add_tail(&cmd->se_queue_node, &qobj->qobj_list);
604 atomic_set(&cmd->t_transport_queue_active, 1); 599 cmd->transport_state |= CMD_T_QUEUED;
605 spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); 600 spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags);
606 601
607 wake_up_interruptible(&qobj->thread_wq); 602 wake_up_interruptible(&qobj->thread_wq);
@@ -620,8 +615,7 @@ transport_get_cmd_from_queue(struct se_queue_obj *qobj)
620 } 615 }
621 cmd = list_first_entry(&qobj->qobj_list, struct se_cmd, se_queue_node); 616 cmd = list_first_entry(&qobj->qobj_list, struct se_cmd, se_queue_node);
622 617
623 atomic_set(&cmd->t_transport_queue_active, 0); 618 cmd->transport_state &= ~CMD_T_QUEUED;
624
625 list_del_init(&cmd->se_queue_node); 619 list_del_init(&cmd->se_queue_node);
626 atomic_dec(&qobj->queue_cnt); 620 atomic_dec(&qobj->queue_cnt);
627 spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); 621 spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags);
@@ -635,20 +629,14 @@ static void transport_remove_cmd_from_queue(struct se_cmd *cmd)
635 unsigned long flags; 629 unsigned long flags;
636 630
637 spin_lock_irqsave(&qobj->cmd_queue_lock, flags); 631 spin_lock_irqsave(&qobj->cmd_queue_lock, flags);
638 if (!atomic_read(&cmd->t_transport_queue_active)) { 632 if (!(cmd->transport_state & CMD_T_QUEUED)) {
639 spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); 633 spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags);
640 return; 634 return;
641 } 635 }
642 atomic_set(&cmd->t_transport_queue_active, 0); 636 cmd->transport_state &= ~CMD_T_QUEUED;
643 atomic_dec(&qobj->queue_cnt); 637 atomic_dec(&qobj->queue_cnt);
644 list_del_init(&cmd->se_queue_node); 638 list_del_init(&cmd->se_queue_node);
645 spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags); 639 spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags);
646
647 if (atomic_read(&cmd->t_transport_queue_active)) {
648 pr_err("ITT: 0x%08x t_transport_queue_active: %d\n",
649 cmd->se_tfo->get_task_tag(cmd),
650 atomic_read(&cmd->t_transport_queue_active));
651 }
652} 640}
653 641
654/* 642/*
@@ -719,7 +707,7 @@ void transport_complete_task(struct se_task *task, int success)
719 } 707 }
720 708
721 if (!success) 709 if (!success)
722 cmd->t_tasks_failed = 1; 710 cmd->transport_state |= CMD_T_FAILED;
723 711
724 /* 712 /*
725 * Decrement the outstanding t_task_cdbs_left count. The last 713 * Decrement the outstanding t_task_cdbs_left count. The last
@@ -731,16 +719,16 @@ void transport_complete_task(struct se_task *task, int success)
731 return; 719 return;
732 } 720 }
733 721
734 if (cmd->t_tasks_failed) { 722 if (cmd->transport_state & CMD_T_FAILED) {
735 cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 723 cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
736 INIT_WORK(&cmd->work, target_complete_failure_work); 724 INIT_WORK(&cmd->work, target_complete_failure_work);
737 } else { 725 } else {
738 atomic_set(&cmd->t_transport_complete, 1); 726 cmd->transport_state |= CMD_T_COMPLETE;
739 INIT_WORK(&cmd->work, target_complete_ok_work); 727 INIT_WORK(&cmd->work, target_complete_ok_work);
740 } 728 }
741 729
742 cmd->t_state = TRANSPORT_COMPLETE; 730 cmd->t_state = TRANSPORT_COMPLETE;
743 atomic_set(&cmd->t_transport_active, 1); 731 cmd->transport_state |= CMD_T_ACTIVE;
744 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 732 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
745 733
746 queue_work(target_completion_wq, &cmd->work); 734 queue_work(target_completion_wq, &cmd->work);
@@ -1488,7 +1476,7 @@ void transport_init_se_cmd(
1488 init_completion(&cmd->t_transport_stop_comp); 1476 init_completion(&cmd->t_transport_stop_comp);
1489 init_completion(&cmd->cmd_wait_comp); 1477 init_completion(&cmd->cmd_wait_comp);
1490 spin_lock_init(&cmd->t_state_lock); 1478 spin_lock_init(&cmd->t_state_lock);
1491 atomic_set(&cmd->transport_dev_active, 1); 1479 cmd->transport_state = CMD_T_DEV_ACTIVE;
1492 1480
1493 cmd->se_tfo = tfo; 1481 cmd->se_tfo = tfo;
1494 cmd->se_sess = se_sess; 1482 cmd->se_sess = se_sess;
@@ -1618,7 +1606,7 @@ int transport_handle_cdb_direct(
1618 return -EINVAL; 1606 return -EINVAL;
1619 } 1607 }
1620 /* 1608 /*
1621 * Set TRANSPORT_NEW_CMD state and cmd->t_transport_active=1 following 1609 * Set TRANSPORT_NEW_CMD state and CMD_T_ACTIVE following
1622 * transport_generic_handle_cdb*() -> transport_add_cmd_to_queue() 1610 * transport_generic_handle_cdb*() -> transport_add_cmd_to_queue()
1623 * in existing usage to ensure that outstanding descriptors are handled 1611 * in existing usage to ensure that outstanding descriptors are handled
1624 * correctly during shutdown via transport_wait_for_tasks() 1612 * correctly during shutdown via transport_wait_for_tasks()
@@ -1627,7 +1615,8 @@ int transport_handle_cdb_direct(
1627 * this to be called for initial descriptor submission. 1615 * this to be called for initial descriptor submission.
1628 */ 1616 */
1629 cmd->t_state = TRANSPORT_NEW_CMD; 1617 cmd->t_state = TRANSPORT_NEW_CMD;
1630 atomic_set(&cmd->t_transport_active, 1); 1618 cmd->transport_state |= CMD_T_ACTIVE;
1619
1631 /* 1620 /*
1632 * transport_generic_new_cmd() is already handling QUEUE_FULL, 1621 * transport_generic_new_cmd() is already handling QUEUE_FULL,
1633 * so follow TRANSPORT_NEW_CMD processing thread context usage 1622 * so follow TRANSPORT_NEW_CMD processing thread context usage
@@ -1859,14 +1848,14 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
1859 cmd->t_state, cmd->scsi_sense_reason); 1848 cmd->t_state, cmd->scsi_sense_reason);
1860 pr_debug("-----[ t_tasks: %d t_task_cdbs_left: %d" 1849 pr_debug("-----[ t_tasks: %d t_task_cdbs_left: %d"
1861 " t_task_cdbs_sent: %d t_task_cdbs_ex_left: %d --" 1850 " t_task_cdbs_sent: %d t_task_cdbs_ex_left: %d --"
1862 " t_transport_active: %d t_transport_stop: %d" 1851 " CMD_T_ACTIVE: %d CMD_T_STOP: %d CMD_T_SENT: %d\n",
1863 " t_transport_sent: %d\n", cmd->t_task_list_num, 1852 cmd->t_task_list_num,
1864 atomic_read(&cmd->t_task_cdbs_left), 1853 atomic_read(&cmd->t_task_cdbs_left),
1865 atomic_read(&cmd->t_task_cdbs_sent), 1854 atomic_read(&cmd->t_task_cdbs_sent),
1866 atomic_read(&cmd->t_task_cdbs_ex_left), 1855 atomic_read(&cmd->t_task_cdbs_ex_left),
1867 atomic_read(&cmd->t_transport_active), 1856 (cmd->transport_state & CMD_T_ACTIVE) != 0,
1868 atomic_read(&cmd->t_transport_stop), 1857 (cmd->transport_state & CMD_T_STOP) != 0,
1869 atomic_read(&cmd->t_transport_sent)); 1858 (cmd->transport_state & CMD_T_SENT) != 0);
1870 1859
1871 /* 1860 /*
1872 * For SAM Task Attribute emulation for failed struct se_cmd 1861 * For SAM Task Attribute emulation for failed struct se_cmd
@@ -2125,7 +2114,7 @@ check_depth:
2125 2114
2126 if (atomic_read(&cmd->t_task_cdbs_sent) == 2115 if (atomic_read(&cmd->t_task_cdbs_sent) ==
2127 cmd->t_task_list_num) 2116 cmd->t_task_list_num)
2128 atomic_set(&cmd->t_transport_sent, 1); 2117 cmd->transport_state |= CMD_T_SENT;
2129 2118
2130 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2119 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2131 2120
@@ -2136,8 +2125,9 @@ check_depth:
2136 if (error != 0) { 2125 if (error != 0) {
2137 spin_lock_irqsave(&cmd->t_state_lock, flags); 2126 spin_lock_irqsave(&cmd->t_state_lock, flags);
2138 task->task_flags &= ~TF_ACTIVE; 2127 task->task_flags &= ~TF_ACTIVE;
2128 cmd->transport_state &= ~CMD_T_SENT;
2139 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2129 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2140 atomic_set(&cmd->t_transport_sent, 0); 2130
2141 transport_stop_tasks_for_cmd(cmd); 2131 transport_stop_tasks_for_cmd(cmd);
2142 transport_generic_request_failure(cmd); 2132 transport_generic_request_failure(cmd);
2143 } 2133 }
@@ -3420,8 +3410,8 @@ static void transport_put_cmd(struct se_cmd *cmd)
3420 goto out_busy; 3410 goto out_busy;
3421 } 3411 }
3422 3412
3423 if (atomic_read(&cmd->transport_dev_active)) { 3413 if (cmd->transport_state & CMD_T_DEV_ACTIVE) {
3424 atomic_set(&cmd->transport_dev_active, 0); 3414 cmd->transport_state &= ~CMD_T_DEV_ACTIVE;
3425 transport_all_task_dev_remove_state(cmd); 3415 transport_all_task_dev_remove_state(cmd);
3426 free_tasks = 1; 3416 free_tasks = 1;
3427 } 3417 }
@@ -3859,8 +3849,10 @@ int transport_generic_new_cmd(struct se_cmd *cmd)
3859 if (task_cdbs < 0) 3849 if (task_cdbs < 0)
3860 goto out_fail; 3850 goto out_fail;
3861 else if (!task_cdbs && (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB)) { 3851 else if (!task_cdbs && (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB)) {
3852 spin_lock_irq(&cmd->t_state_lock);
3862 cmd->t_state = TRANSPORT_COMPLETE; 3853 cmd->t_state = TRANSPORT_COMPLETE;
3863 atomic_set(&cmd->t_transport_active, 1); 3854 cmd->transport_state |= CMD_T_ACTIVE;
3855 spin_unlock_irq(&cmd->t_state_lock);
3864 3856
3865 if (cmd->t_task_cdb[0] == REQUEST_SENSE) { 3857 if (cmd->t_task_cdb[0] == REQUEST_SENSE) {
3866 u8 ua_asc = 0, ua_ascq = 0; 3858 u8 ua_asc = 0, ua_ascq = 0;
@@ -3941,9 +3933,9 @@ static int transport_generic_write_pending(struct se_cmd *cmd)
3941 3933
3942 /* 3934 /*
3943 * Clear the se_cmd for WRITE_PENDING status in order to set 3935 * Clear the se_cmd for WRITE_PENDING status in order to set
3944 * cmd->t_transport_active=0 so that transport_generic_handle_data 3936 * CMD_T_ACTIVE so that transport_generic_handle_data can be called
3945 * can be called from HW target mode interrupt code. This is safe 3937 * from HW target mode interrupt code. This is safe to be called
3946 * to be called with transport_off=1 before the cmd->se_tfo->write_pending 3938 * with transport_off=1 before the cmd->se_tfo->write_pending
3947 * because the se_cmd->se_lun pointer is not being cleared. 3939 * because the se_cmd->se_lun pointer is not being cleared.
3948 */ 3940 */
3949 transport_cmd_check_stop(cmd, 1, 0); 3941 transport_cmd_check_stop(cmd, 1, 0);
@@ -4129,15 +4121,16 @@ static int transport_lun_wait_for_tasks(struct se_cmd *cmd, struct se_lun *lun)
4129 * be stopped, we can safely ignore this struct se_cmd. 4121 * be stopped, we can safely ignore this struct se_cmd.
4130 */ 4122 */
4131 spin_lock_irqsave(&cmd->t_state_lock, flags); 4123 spin_lock_irqsave(&cmd->t_state_lock, flags);
4132 if (atomic_read(&cmd->t_transport_stop)) { 4124 if (cmd->transport_state & CMD_T_STOP) {
4133 atomic_set(&cmd->transport_lun_stop, 0); 4125 cmd->transport_state &= ~CMD_T_LUN_STOP;
4134 pr_debug("ConfigFS ITT[0x%08x] - t_transport_stop ==" 4126
4135 " TRUE, skipping\n", cmd->se_tfo->get_task_tag(cmd)); 4127 pr_debug("ConfigFS ITT[0x%08x] - CMD_T_STOP, skipping\n",
4128 cmd->se_tfo->get_task_tag(cmd));
4136 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 4129 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
4137 transport_cmd_check_stop(cmd, 1, 0); 4130 transport_cmd_check_stop(cmd, 1, 0);
4138 return -EPERM; 4131 return -EPERM;
4139 } 4132 }
4140 atomic_set(&cmd->transport_lun_fe_stop, 1); 4133 cmd->transport_state |= CMD_T_LUN_FE_STOP;
4141 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 4134 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
4142 4135
4143 wake_up_interruptible(&cmd->se_dev->dev_queue_obj.thread_wq); 4136 wake_up_interruptible(&cmd->se_dev->dev_queue_obj.thread_wq);
@@ -4183,7 +4176,7 @@ static void __transport_clear_lun_from_sessions(struct se_lun *lun)
4183 "_lun_stop for ITT: 0x%08x\n", 4176 "_lun_stop for ITT: 0x%08x\n",
4184 cmd->se_lun->unpacked_lun, 4177 cmd->se_lun->unpacked_lun,
4185 cmd->se_tfo->get_task_tag(cmd)); 4178 cmd->se_tfo->get_task_tag(cmd));
4186 atomic_set(&cmd->transport_lun_stop, 1); 4179 cmd->transport_state |= CMD_T_LUN_STOP;
4187 spin_unlock(&cmd->t_state_lock); 4180 spin_unlock(&cmd->t_state_lock);
4188 4181
4189 spin_unlock_irqrestore(&lun->lun_cmd_lock, lun_flags); 4182 spin_unlock_irqrestore(&lun->lun_cmd_lock, lun_flags);
@@ -4213,11 +4206,11 @@ static void __transport_clear_lun_from_sessions(struct se_lun *lun)
4213 cmd->se_tfo->get_task_tag(cmd)); 4206 cmd->se_tfo->get_task_tag(cmd));
4214 4207
4215 spin_lock_irqsave(&cmd->t_state_lock, cmd_flags); 4208 spin_lock_irqsave(&cmd->t_state_lock, cmd_flags);
4216 if (!atomic_read(&cmd->transport_dev_active)) { 4209 if (!(cmd->transport_state & CMD_T_DEV_ACTIVE)) {
4217 spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags); 4210 spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags);
4218 goto check_cond; 4211 goto check_cond;
4219 } 4212 }
4220 atomic_set(&cmd->transport_dev_active, 0); 4213 cmd->transport_state &= ~CMD_T_DEV_ACTIVE;
4221 transport_all_task_dev_remove_state(cmd); 4214 transport_all_task_dev_remove_state(cmd);
4222 spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags); 4215 spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags);
4223 4216
@@ -4237,7 +4230,7 @@ check_cond:
4237 * finished accessing it. 4230 * finished accessing it.
4238 */ 4231 */
4239 spin_lock_irqsave(&cmd->t_state_lock, cmd_flags); 4232 spin_lock_irqsave(&cmd->t_state_lock, cmd_flags);
4240 if (atomic_read(&cmd->transport_lun_fe_stop)) { 4233 if (cmd->transport_state & CMD_T_LUN_FE_STOP) {
4241 pr_debug("SE_LUN[%d] - Detected FE stop for" 4234 pr_debug("SE_LUN[%d] - Detected FE stop for"
4242 " struct se_cmd: %p ITT: 0x%08x\n", 4235 " struct se_cmd: %p ITT: 0x%08x\n",
4243 lun->unpacked_lun, 4236 lun->unpacked_lun,
@@ -4315,8 +4308,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
4315 * transport_clear_lun_from_sessions() once the ConfigFS context caller 4308 * transport_clear_lun_from_sessions() once the ConfigFS context caller
4316 * has completed its operation on the struct se_cmd. 4309 * has completed its operation on the struct se_cmd.
4317 */ 4310 */
4318 if (atomic_read(&cmd->transport_lun_stop)) { 4311 if (cmd->transport_state & CMD_T_LUN_STOP) {
4319
4320 pr_debug("wait_for_tasks: Stopping" 4312 pr_debug("wait_for_tasks: Stopping"
4321 " wait_for_completion(&cmd->t_tasktransport_lun_fe" 4313 " wait_for_completion(&cmd->t_tasktransport_lun_fe"
4322 "_stop_comp); for ITT: 0x%08x\n", 4314 "_stop_comp); for ITT: 0x%08x\n",
@@ -4344,18 +4336,19 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
4344 "stop_comp); for ITT: 0x%08x\n", 4336 "stop_comp); for ITT: 0x%08x\n",
4345 cmd->se_tfo->get_task_tag(cmd)); 4337 cmd->se_tfo->get_task_tag(cmd));
4346 4338
4347 atomic_set(&cmd->transport_lun_stop, 0); 4339 cmd->transport_state &= ~CMD_T_LUN_STOP;
4348 } 4340 }
4349 if (!atomic_read(&cmd->t_transport_active) || 4341
4350 atomic_read(&cmd->t_transport_aborted)) { 4342 if (!(cmd->transport_state & CMD_T_ACTIVE) ||
4343 (cmd->transport_state & CMD_T_ABORTED)) {
4351 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 4344 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
4352 return false; 4345 return false;
4353 } 4346 }
4354 4347
4355 atomic_set(&cmd->t_transport_stop, 1); 4348 cmd->transport_state |= CMD_T_STOP;
4356 4349
4357 pr_debug("wait_for_tasks: Stopping %p ITT: 0x%08x" 4350 pr_debug("wait_for_tasks: Stopping %p ITT: 0x%08x"
4358 " i_state: %d, t_state: %d, t_transport_stop = TRUE\n", 4351 " i_state: %d, t_state: %d, CMD_T_STOP\n",
4359 cmd, cmd->se_tfo->get_task_tag(cmd), 4352 cmd, cmd->se_tfo->get_task_tag(cmd),
4360 cmd->se_tfo->get_cmd_state(cmd), cmd->t_state); 4353 cmd->se_tfo->get_cmd_state(cmd), cmd->t_state);
4361 4354
@@ -4366,8 +4359,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
4366 wait_for_completion(&cmd->t_transport_stop_comp); 4359 wait_for_completion(&cmd->t_transport_stop_comp);
4367 4360
4368 spin_lock_irqsave(&cmd->t_state_lock, flags); 4361 spin_lock_irqsave(&cmd->t_state_lock, flags);
4369 atomic_set(&cmd->t_transport_active, 0); 4362 cmd->transport_state &= ~(CMD_T_ACTIVE | CMD_T_STOP);
4370 atomic_set(&cmd->t_transport_stop, 0);
4371 4363
4372 pr_debug("wait_for_tasks: Stopped wait_for_compltion(" 4364 pr_debug("wait_for_tasks: Stopped wait_for_compltion("
4373 "&cmd->t_transport_stop_comp) for ITT: 0x%08x\n", 4365 "&cmd->t_transport_stop_comp) for ITT: 0x%08x\n",
@@ -4596,7 +4588,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
4596{ 4588{
4597 int ret = 0; 4589 int ret = 0;
4598 4590
4599 if (atomic_read(&cmd->t_transport_aborted) != 0) { 4591 if (cmd->transport_state & CMD_T_ABORTED) {
4600 if (!send_status || 4592 if (!send_status ||
4601 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS)) 4593 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
4602 return 1; 4594 return 1;
@@ -4633,7 +4625,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
4633 */ 4625 */
4634 if (cmd->data_direction == DMA_TO_DEVICE) { 4626 if (cmd->data_direction == DMA_TO_DEVICE) {
4635 if (cmd->se_tfo->write_pending_status(cmd) != 0) { 4627 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
4636 atomic_inc(&cmd->t_transport_aborted); 4628 cmd->transport_state |= CMD_T_ABORTED;
4637 smp_mb__after_atomic_inc(); 4629 smp_mb__after_atomic_inc();
4638 } 4630 }
4639 } 4631 }
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index dc4e345a0163..9e7a6a5451c2 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -555,23 +555,24 @@ struct se_cmd {
555 unsigned char *t_task_cdb; 555 unsigned char *t_task_cdb;
556 unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE]; 556 unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE];
557 unsigned long long t_task_lba; 557 unsigned long long t_task_lba;
558 int t_tasks_failed;
559 u32 t_tasks_sg_chained_no; 558 u32 t_tasks_sg_chained_no;
560 atomic_t t_fe_count; 559 atomic_t t_fe_count;
561 atomic_t t_se_count; 560 atomic_t t_se_count;
562 atomic_t t_task_cdbs_left; 561 atomic_t t_task_cdbs_left;
563 atomic_t t_task_cdbs_ex_left; 562 atomic_t t_task_cdbs_ex_left;
564 atomic_t t_task_cdbs_sent; 563 atomic_t t_task_cdbs_sent;
565 atomic_t t_transport_aborted; 564 unsigned int transport_state;
566 atomic_t t_transport_active; 565#define CMD_T_ABORTED (1 << 0)
567 atomic_t t_transport_complete; 566#define CMD_T_ACTIVE (1 << 1)
568 atomic_t t_transport_queue_active; 567#define CMD_T_COMPLETE (1 << 2)
569 atomic_t t_transport_sent; 568#define CMD_T_QUEUED (1 << 3)
570 atomic_t t_transport_stop; 569#define CMD_T_SENT (1 << 4)
571 atomic_t transport_dev_active; 570#define CMD_T_STOP (1 << 5)
571#define CMD_T_FAILED (1 << 6)
572#define CMD_T_LUN_STOP (1 << 7)
573#define CMD_T_LUN_FE_STOP (1 << 8)
574#define CMD_T_DEV_ACTIVE (1 << 9)
572 atomic_t transport_lun_active; 575 atomic_t transport_lun_active;
573 atomic_t transport_lun_fe_stop;
574 atomic_t transport_lun_stop;
575 spinlock_t t_state_lock; 576 spinlock_t t_state_lock;
576 struct completion t_transport_stop_comp; 577 struct completion t_transport_stop_comp;
577 struct completion transport_lun_fe_stop_comp; 578 struct completion transport_lun_fe_stop_comp;