aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/target/loopback/tcm_loop.c9
-rw-r--r--drivers/target/target_core_pscsi.c2
-rw-r--r--drivers/target/target_core_transport.c109
-rw-r--r--drivers/target/tcm_fc/tfc_cmd.c2
-rw-r--r--include/target/target_core_base.h35
5 files changed, 56 insertions, 101 deletions
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 38dfac2b0a1c..f65dc9db8596 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -211,12 +211,11 @@ static void tcm_loop_submission_work(struct work_struct *work)
211 /* 211 /*
212 * Because some userspace code via scsi-generic do not memset their 212 * Because some userspace code via scsi-generic do not memset their
213 * associated read buffers, go ahead and do that here for type 213 * associated read buffers, go ahead and do that here for type
214 * SCF_SCSI_CONTROL_SG_IO_CDB. Also note that this is currently 214 * non-data CDBs. Also note that this is currently guaranteed to be a
215 * guaranteed to be a single SGL for SCF_SCSI_CONTROL_SG_IO_CDB 215 * single SGL for this case by target core in
216 * by target core in target_setup_cmd_from_cdb() -> 216 * target_setup_cmd_from_cdb() -> transport_generic_cmd_sequencer().
217 * transport_generic_cmd_sequencer().
218 */ 217 */
219 if (se_cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB && 218 if (!(se_cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) &&
220 se_cmd->data_direction == DMA_FROM_DEVICE) { 219 se_cmd->data_direction == DMA_FROM_DEVICE) {
221 struct scatterlist *sg = scsi_sglist(sc); 220 struct scatterlist *sg = scsi_sglist(sc);
222 unsigned char *buf = kmap(sg_page(sg)) + sg->offset; 221 unsigned char *buf = kmap(sg_page(sg)) + sg->offset;
diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
index 4ce2cf642fce..bfc72327370c 100644
--- a/drivers/target/target_core_pscsi.c
+++ b/drivers/target/target_core_pscsi.c
@@ -1042,7 +1042,7 @@ static int pscsi_execute_cmd(struct se_cmd *cmd, struct scatterlist *sgl,
1042 memcpy(pt->pscsi_cdb, cmd->t_task_cdb, 1042 memcpy(pt->pscsi_cdb, cmd->t_task_cdb,
1043 scsi_command_size(cmd->t_task_cdb)); 1043 scsi_command_size(cmd->t_task_cdb));
1044 1044
1045 if (cmd->se_cmd_flags & SCF_SCSI_NON_DATA_CDB) { 1045 if (!sgl) {
1046 req = blk_get_request(pdv->pdv_sd->request_queue, 1046 req = blk_get_request(pdv->pdv_sd->request_queue,
1047 (data_direction == DMA_TO_DEVICE), 1047 (data_direction == DMA_TO_DEVICE),
1048 GFP_KERNEL); 1048 GFP_KERNEL);
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index bb19223faa46..a181951a7aca 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2446,7 +2446,7 @@ static int transport_generic_cmd_sequencer(
2446 goto out_unsupported_cdb; 2446 goto out_unsupported_cdb;
2447 size = transport_get_size(sectors, cdb, cmd); 2447 size = transport_get_size(sectors, cdb, cmd);
2448 cmd->t_task_lba = transport_lba_21(cdb); 2448 cmd->t_task_lba = transport_lba_21(cdb);
2449 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2449 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2450 break; 2450 break;
2451 case READ_10: 2451 case READ_10:
2452 sectors = transport_get_sectors_10(cdb, cmd, &sector_ret); 2452 sectors = transport_get_sectors_10(cdb, cmd, &sector_ret);
@@ -2454,7 +2454,7 @@ static int transport_generic_cmd_sequencer(
2454 goto out_unsupported_cdb; 2454 goto out_unsupported_cdb;
2455 size = transport_get_size(sectors, cdb, cmd); 2455 size = transport_get_size(sectors, cdb, cmd);
2456 cmd->t_task_lba = transport_lba_32(cdb); 2456 cmd->t_task_lba = transport_lba_32(cdb);
2457 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2457 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2458 break; 2458 break;
2459 case READ_12: 2459 case READ_12:
2460 sectors = transport_get_sectors_12(cdb, cmd, &sector_ret); 2460 sectors = transport_get_sectors_12(cdb, cmd, &sector_ret);
@@ -2462,7 +2462,7 @@ static int transport_generic_cmd_sequencer(
2462 goto out_unsupported_cdb; 2462 goto out_unsupported_cdb;
2463 size = transport_get_size(sectors, cdb, cmd); 2463 size = transport_get_size(sectors, cdb, cmd);
2464 cmd->t_task_lba = transport_lba_32(cdb); 2464 cmd->t_task_lba = transport_lba_32(cdb);
2465 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2465 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2466 break; 2466 break;
2467 case READ_16: 2467 case READ_16:
2468 sectors = transport_get_sectors_16(cdb, cmd, &sector_ret); 2468 sectors = transport_get_sectors_16(cdb, cmd, &sector_ret);
@@ -2470,7 +2470,7 @@ static int transport_generic_cmd_sequencer(
2470 goto out_unsupported_cdb; 2470 goto out_unsupported_cdb;
2471 size = transport_get_size(sectors, cdb, cmd); 2471 size = transport_get_size(sectors, cdb, cmd);
2472 cmd->t_task_lba = transport_lba_64(cdb); 2472 cmd->t_task_lba = transport_lba_64(cdb);
2473 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2473 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2474 break; 2474 break;
2475 case WRITE_6: 2475 case WRITE_6:
2476 sectors = transport_get_sectors_6(cdb, cmd, &sector_ret); 2476 sectors = transport_get_sectors_6(cdb, cmd, &sector_ret);
@@ -2478,7 +2478,7 @@ static int transport_generic_cmd_sequencer(
2478 goto out_unsupported_cdb; 2478 goto out_unsupported_cdb;
2479 size = transport_get_size(sectors, cdb, cmd); 2479 size = transport_get_size(sectors, cdb, cmd);
2480 cmd->t_task_lba = transport_lba_21(cdb); 2480 cmd->t_task_lba = transport_lba_21(cdb);
2481 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2481 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2482 break; 2482 break;
2483 case WRITE_10: 2483 case WRITE_10:
2484 case WRITE_VERIFY: 2484 case WRITE_VERIFY:
@@ -2489,7 +2489,7 @@ static int transport_generic_cmd_sequencer(
2489 cmd->t_task_lba = transport_lba_32(cdb); 2489 cmd->t_task_lba = transport_lba_32(cdb);
2490 if (cdb[1] & 0x8) 2490 if (cdb[1] & 0x8)
2491 cmd->se_cmd_flags |= SCF_FUA; 2491 cmd->se_cmd_flags |= SCF_FUA;
2492 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2492 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2493 break; 2493 break;
2494 case WRITE_12: 2494 case WRITE_12:
2495 sectors = transport_get_sectors_12(cdb, cmd, &sector_ret); 2495 sectors = transport_get_sectors_12(cdb, cmd, &sector_ret);
@@ -2499,7 +2499,7 @@ static int transport_generic_cmd_sequencer(
2499 cmd->t_task_lba = transport_lba_32(cdb); 2499 cmd->t_task_lba = transport_lba_32(cdb);
2500 if (cdb[1] & 0x8) 2500 if (cdb[1] & 0x8)
2501 cmd->se_cmd_flags |= SCF_FUA; 2501 cmd->se_cmd_flags |= SCF_FUA;
2502 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2502 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2503 break; 2503 break;
2504 case WRITE_16: 2504 case WRITE_16:
2505 sectors = transport_get_sectors_16(cdb, cmd, &sector_ret); 2505 sectors = transport_get_sectors_16(cdb, cmd, &sector_ret);
@@ -2509,7 +2509,7 @@ static int transport_generic_cmd_sequencer(
2509 cmd->t_task_lba = transport_lba_64(cdb); 2509 cmd->t_task_lba = transport_lba_64(cdb);
2510 if (cdb[1] & 0x8) 2510 if (cdb[1] & 0x8)
2511 cmd->se_cmd_flags |= SCF_FUA; 2511 cmd->se_cmd_flags |= SCF_FUA;
2512 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2512 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2513 break; 2513 break;
2514 case XDWRITEREAD_10: 2514 case XDWRITEREAD_10:
2515 if ((cmd->data_direction != DMA_TO_DEVICE) || 2515 if ((cmd->data_direction != DMA_TO_DEVICE) ||
@@ -2520,7 +2520,7 @@ static int transport_generic_cmd_sequencer(
2520 goto out_unsupported_cdb; 2520 goto out_unsupported_cdb;
2521 size = transport_get_size(sectors, cdb, cmd); 2521 size = transport_get_size(sectors, cdb, cmd);
2522 cmd->t_task_lba = transport_lba_32(cdb); 2522 cmd->t_task_lba = transport_lba_32(cdb);
2523 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2523 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2524 2524
2525 /* 2525 /*
2526 * Do now allow BIDI commands for passthrough mode. 2526 * Do now allow BIDI commands for passthrough mode.
@@ -2548,7 +2548,7 @@ static int transport_generic_cmd_sequencer(
2548 * XDWRITE_READ_32 logic. 2548 * XDWRITE_READ_32 logic.
2549 */ 2549 */
2550 cmd->t_task_lba = transport_lba_64_ext(cdb); 2550 cmd->t_task_lba = transport_lba_64_ext(cdb);
2551 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2551 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
2552 2552
2553 /* 2553 /*
2554 * Do now allow BIDI commands for passthrough mode. 2554 * Do now allow BIDI commands for passthrough mode.
@@ -2578,7 +2578,6 @@ static int transport_generic_cmd_sequencer(
2578 } 2578 }
2579 2579
2580 cmd->t_task_lba = get_unaligned_be64(&cdb[12]); 2580 cmd->t_task_lba = get_unaligned_be64(&cdb[12]);
2581 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2582 2581
2583 if (target_check_write_same_discard(&cdb[10], dev) < 0) 2582 if (target_check_write_same_discard(&cdb[10], dev) < 0)
2584 goto out_unsupported_cdb; 2583 goto out_unsupported_cdb;
@@ -2608,25 +2607,20 @@ static int transport_generic_cmd_sequencer(
2608 /* GPCMD_SEND_KEY from multi media commands */ 2607 /* GPCMD_SEND_KEY from multi media commands */
2609 size = (cdb[8] << 8) + cdb[9]; 2608 size = (cdb[8] << 8) + cdb[9];
2610 } 2609 }
2611 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2612 break; 2610 break;
2613 case MODE_SELECT: 2611 case MODE_SELECT:
2614 size = cdb[4]; 2612 size = cdb[4];
2615 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2616 break; 2613 break;
2617 case MODE_SELECT_10: 2614 case MODE_SELECT_10:
2618 size = (cdb[7] << 8) + cdb[8]; 2615 size = (cdb[7] << 8) + cdb[8];
2619 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2620 break; 2616 break;
2621 case MODE_SENSE: 2617 case MODE_SENSE:
2622 size = cdb[4]; 2618 size = cdb[4];
2623 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2624 if (!passthrough) 2619 if (!passthrough)
2625 cmd->execute_cmd = target_emulate_modesense; 2620 cmd->execute_cmd = target_emulate_modesense;
2626 break; 2621 break;
2627 case MODE_SENSE_10: 2622 case MODE_SENSE_10:
2628 size = (cdb[7] << 8) + cdb[8]; 2623 size = (cdb[7] << 8) + cdb[8];
2629 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2630 if (!passthrough) 2624 if (!passthrough)
2631 cmd->execute_cmd = target_emulate_modesense; 2625 cmd->execute_cmd = target_emulate_modesense;
2632 break; 2626 break;
@@ -2635,39 +2629,32 @@ static int transport_generic_cmd_sequencer(
2635 case LOG_SELECT: 2629 case LOG_SELECT:
2636 case LOG_SENSE: 2630 case LOG_SENSE:
2637 size = (cdb[7] << 8) + cdb[8]; 2631 size = (cdb[7] << 8) + cdb[8];
2638 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2639 break; 2632 break;
2640 case READ_BLOCK_LIMITS: 2633 case READ_BLOCK_LIMITS:
2641 size = READ_BLOCK_LEN; 2634 size = READ_BLOCK_LEN;
2642 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2643 break; 2635 break;
2644 case GPCMD_GET_CONFIGURATION: 2636 case GPCMD_GET_CONFIGURATION:
2645 case GPCMD_READ_FORMAT_CAPACITIES: 2637 case GPCMD_READ_FORMAT_CAPACITIES:
2646 case GPCMD_READ_DISC_INFO: 2638 case GPCMD_READ_DISC_INFO:
2647 case GPCMD_READ_TRACK_RZONE_INFO: 2639 case GPCMD_READ_TRACK_RZONE_INFO:
2648 size = (cdb[7] << 8) + cdb[8]; 2640 size = (cdb[7] << 8) + cdb[8];
2649 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2650 break; 2641 break;
2651 case PERSISTENT_RESERVE_IN: 2642 case PERSISTENT_RESERVE_IN:
2652 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS) 2643 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
2653 cmd->execute_cmd = target_scsi3_emulate_pr_in; 2644 cmd->execute_cmd = target_scsi3_emulate_pr_in;
2654 size = (cdb[7] << 8) + cdb[8]; 2645 size = (cdb[7] << 8) + cdb[8];
2655 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2656 break; 2646 break;
2657 case PERSISTENT_RESERVE_OUT: 2647 case PERSISTENT_RESERVE_OUT:
2658 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS) 2648 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
2659 cmd->execute_cmd = target_scsi3_emulate_pr_out; 2649 cmd->execute_cmd = target_scsi3_emulate_pr_out;
2660 size = (cdb[7] << 8) + cdb[8]; 2650 size = (cdb[7] << 8) + cdb[8];
2661 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2662 break; 2651 break;
2663 case GPCMD_MECHANISM_STATUS: 2652 case GPCMD_MECHANISM_STATUS:
2664 case GPCMD_READ_DVD_STRUCTURE: 2653 case GPCMD_READ_DVD_STRUCTURE:
2665 size = (cdb[8] << 8) + cdb[9]; 2654 size = (cdb[8] << 8) + cdb[9];
2666 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2667 break; 2655 break;
2668 case READ_POSITION: 2656 case READ_POSITION:
2669 size = READ_POSITION_LEN; 2657 size = READ_POSITION_LEN;
2670 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2671 break; 2658 break;
2672 case MAINTENANCE_OUT: 2659 case MAINTENANCE_OUT:
2673 if (dev->transport->get_device_type(dev) != TYPE_ROM) { 2660 if (dev->transport->get_device_type(dev) != TYPE_ROM) {
@@ -2687,7 +2674,6 @@ static int transport_generic_cmd_sequencer(
2687 /* GPCMD_REPORT_KEY from multi media commands */ 2674 /* GPCMD_REPORT_KEY from multi media commands */
2688 size = (cdb[8] << 8) + cdb[9]; 2675 size = (cdb[8] << 8) + cdb[9];
2689 } 2676 }
2690 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2691 break; 2677 break;
2692 case INQUIRY: 2678 case INQUIRY:
2693 size = (cdb[3] << 8) + cdb[4]; 2679 size = (cdb[3] << 8) + cdb[4];
@@ -2697,17 +2683,14 @@ static int transport_generic_cmd_sequencer(
2697 */ 2683 */
2698 if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED) 2684 if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
2699 cmd->sam_task_attr = MSG_HEAD_TAG; 2685 cmd->sam_task_attr = MSG_HEAD_TAG;
2700 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2701 if (!passthrough) 2686 if (!passthrough)
2702 cmd->execute_cmd = target_emulate_inquiry; 2687 cmd->execute_cmd = target_emulate_inquiry;
2703 break; 2688 break;
2704 case READ_BUFFER: 2689 case READ_BUFFER:
2705 size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8]; 2690 size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
2706 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2707 break; 2691 break;
2708 case READ_CAPACITY: 2692 case READ_CAPACITY:
2709 size = READ_CAP_LEN; 2693 size = READ_CAP_LEN;
2710 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2711 if (!passthrough) 2694 if (!passthrough)
2712 cmd->execute_cmd = target_emulate_readcapacity; 2695 cmd->execute_cmd = target_emulate_readcapacity;
2713 break; 2696 break;
@@ -2715,7 +2698,6 @@ static int transport_generic_cmd_sequencer(
2715 case SECURITY_PROTOCOL_IN: 2698 case SECURITY_PROTOCOL_IN:
2716 case SECURITY_PROTOCOL_OUT: 2699 case SECURITY_PROTOCOL_OUT:
2717 size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9]; 2700 size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
2718 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2719 break; 2701 break;
2720 case SERVICE_ACTION_IN: 2702 case SERVICE_ACTION_IN:
2721 switch (cmd->t_task_cdb[1] & 0x1f) { 2703 switch (cmd->t_task_cdb[1] & 0x1f) {
@@ -2741,38 +2723,31 @@ static int transport_generic_cmd_sequencer(
2741 case WRITE_ATTRIBUTE: 2723 case WRITE_ATTRIBUTE:
2742 size = (cdb[10] << 24) | (cdb[11] << 16) | 2724 size = (cdb[10] << 24) | (cdb[11] << 16) |
2743 (cdb[12] << 8) | cdb[13]; 2725 (cdb[12] << 8) | cdb[13];
2744 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2745 break; 2726 break;
2746 case RECEIVE_DIAGNOSTIC: 2727 case RECEIVE_DIAGNOSTIC:
2747 case SEND_DIAGNOSTIC: 2728 case SEND_DIAGNOSTIC:
2748 size = (cdb[3] << 8) | cdb[4]; 2729 size = (cdb[3] << 8) | cdb[4];
2749 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2750 break; 2730 break;
2751/* #warning FIXME: Figure out correct GPCMD_READ_CD blocksize. */ 2731/* #warning FIXME: Figure out correct GPCMD_READ_CD blocksize. */
2752#if 0 2732#if 0
2753 case GPCMD_READ_CD: 2733 case GPCMD_READ_CD:
2754 sectors = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8]; 2734 sectors = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
2755 size = (2336 * sectors); 2735 size = (2336 * sectors);
2756 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2757 break; 2736 break;
2758#endif 2737#endif
2759 case READ_TOC: 2738 case READ_TOC:
2760 size = cdb[8]; 2739 size = cdb[8];
2761 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2762 break; 2740 break;
2763 case REQUEST_SENSE: 2741 case REQUEST_SENSE:
2764 size = cdb[4]; 2742 size = cdb[4];
2765 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2766 if (!passthrough) 2743 if (!passthrough)
2767 cmd->execute_cmd = target_emulate_request_sense; 2744 cmd->execute_cmd = target_emulate_request_sense;
2768 break; 2745 break;
2769 case READ_ELEMENT_STATUS: 2746 case READ_ELEMENT_STATUS:
2770 size = 65536 * cdb[7] + 256 * cdb[8] + cdb[9]; 2747 size = 65536 * cdb[7] + 256 * cdb[8] + cdb[9];
2771 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2772 break; 2748 break;
2773 case WRITE_BUFFER: 2749 case WRITE_BUFFER:
2774 size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8]; 2750 size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
2775 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2776 break; 2751 break;
2777 case RESERVE: 2752 case RESERVE:
2778 case RESERVE_10: 2753 case RESERVE_10:
@@ -2794,7 +2769,6 @@ static int transport_generic_cmd_sequencer(
2794 */ 2769 */
2795 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH) 2770 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
2796 cmd->execute_cmd = target_scsi2_reservation_reserve; 2771 cmd->execute_cmd = target_scsi2_reservation_reserve;
2797 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
2798 break; 2772 break;
2799 case RELEASE: 2773 case RELEASE:
2800 case RELEASE_10: 2774 case RELEASE_10:
@@ -2809,7 +2783,6 @@ static int transport_generic_cmd_sequencer(
2809 2783
2810 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH) 2784 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
2811 cmd->execute_cmd = target_scsi2_reservation_release; 2785 cmd->execute_cmd = target_scsi2_reservation_release;
2812 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
2813 break; 2786 break;
2814 case SYNCHRONIZE_CACHE: 2787 case SYNCHRONIZE_CACHE:
2815 case SYNCHRONIZE_CACHE_16: 2788 case SYNCHRONIZE_CACHE_16:
@@ -2827,7 +2800,6 @@ static int transport_generic_cmd_sequencer(
2827 goto out_unsupported_cdb; 2800 goto out_unsupported_cdb;
2828 2801
2829 size = transport_get_size(sectors, cdb, cmd); 2802 size = transport_get_size(sectors, cdb, cmd);
2830 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
2831 2803
2832 if (passthrough) 2804 if (passthrough)
2833 break; 2805 break;
@@ -2844,7 +2816,6 @@ static int transport_generic_cmd_sequencer(
2844 break; 2816 break;
2845 case UNMAP: 2817 case UNMAP:
2846 size = get_unaligned_be16(&cdb[7]); 2818 size = get_unaligned_be16(&cdb[7]);
2847 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2848 if (!passthrough) 2819 if (!passthrough)
2849 cmd->execute_cmd = target_emulate_unmap; 2820 cmd->execute_cmd = target_emulate_unmap;
2850 break; 2821 break;
@@ -2861,7 +2832,6 @@ static int transport_generic_cmd_sequencer(
2861 } 2832 }
2862 2833
2863 cmd->t_task_lba = get_unaligned_be64(&cdb[2]); 2834 cmd->t_task_lba = get_unaligned_be64(&cdb[2]);
2864 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2865 2835
2866 if (target_check_write_same_discard(&cdb[1], dev) < 0) 2836 if (target_check_write_same_discard(&cdb[1], dev) < 0)
2867 goto out_unsupported_cdb; 2837 goto out_unsupported_cdb;
@@ -2881,7 +2851,6 @@ static int transport_generic_cmd_sequencer(
2881 } 2851 }
2882 2852
2883 cmd->t_task_lba = get_unaligned_be32(&cdb[2]); 2853 cmd->t_task_lba = get_unaligned_be32(&cdb[2]);
2884 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2885 /* 2854 /*
2886 * Follow sbcr26 with WRITE_SAME (10) and check for the existence 2855 * Follow sbcr26 with WRITE_SAME (10) and check for the existence
2887 * of byte 1 bit 3 UNMAP instead of original reserved field 2856 * of byte 1 bit 3 UNMAP instead of original reserved field
@@ -2900,7 +2869,6 @@ static int transport_generic_cmd_sequencer(
2900 case TEST_UNIT_READY: 2869 case TEST_UNIT_READY:
2901 case VERIFY: 2870 case VERIFY:
2902 case WRITE_FILEMARKS: 2871 case WRITE_FILEMARKS:
2903 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
2904 if (!passthrough) 2872 if (!passthrough)
2905 cmd->execute_cmd = target_emulate_noop; 2873 cmd->execute_cmd = target_emulate_noop;
2906 break; 2874 break;
@@ -2909,7 +2877,6 @@ static int transport_generic_cmd_sequencer(
2909 case GPCMD_LOAD_UNLOAD: 2877 case GPCMD_LOAD_UNLOAD:
2910 case GPCMD_SET_SPEED: 2878 case GPCMD_SET_SPEED:
2911 case MOVE_MEDIUM: 2879 case MOVE_MEDIUM:
2912 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
2913 break; 2880 break;
2914 case REPORT_LUNS: 2881 case REPORT_LUNS:
2915 cmd->execute_cmd = target_report_luns; 2882 cmd->execute_cmd = target_report_luns;
@@ -2920,11 +2887,9 @@ static int transport_generic_cmd_sequencer(
2920 */ 2887 */
2921 if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED) 2888 if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
2922 cmd->sam_task_attr = MSG_HEAD_TAG; 2889 cmd->sam_task_attr = MSG_HEAD_TAG;
2923 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2924 break; 2890 break;
2925 case GET_EVENT_STATUS_NOTIFICATION: 2891 case GET_EVENT_STATUS_NOTIFICATION:
2926 size = (cdb[7] << 8) | cdb[8]; 2892 size = (cdb[7] << 8) | cdb[8];
2927 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2928 break; 2893 break;
2929 case ATA_16: 2894 case ATA_16:
2930 /* Only support ATA passthrough to pSCSI backends.. */ 2895 /* Only support ATA passthrough to pSCSI backends.. */
@@ -2956,7 +2921,6 @@ static int transport_generic_cmd_sequencer(
2956 /* BYTE */ 2921 /* BYTE */
2957 size = sectors; 2922 size = sectors;
2958 } 2923 }
2959 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2960 break; 2924 break;
2961 default: 2925 default:
2962 pr_warn("TARGET_CORE[%s]: Unsupported SCSI Opcode" 2926 pr_warn("TARGET_CORE[%s]: Unsupported SCSI Opcode"
@@ -2983,7 +2947,7 @@ static int transport_generic_cmd_sequencer(
2983 } 2947 }
2984 /* 2948 /*
2985 * Reject READ_* or WRITE_* with overflow/underflow for 2949 * Reject READ_* or WRITE_* with overflow/underflow for
2986 * type SCF_SCSI_DATA_SG_IO_CDB. 2950 * type SCF_SCSI_DATA_CDB.
2987 */ 2951 */
2988 if (dev->se_sub_dev->se_dev_attrib.block_size != 512) { 2952 if (dev->se_sub_dev->se_dev_attrib.block_size != 512) {
2989 pr_err("Failing OVERFLOW/UNDERFLOW for LBA op" 2953 pr_err("Failing OVERFLOW/UNDERFLOW for LBA op"
@@ -3003,7 +2967,7 @@ static int transport_generic_cmd_sequencer(
3003 cmd->data_length = size; 2967 cmd->data_length = size;
3004 } 2968 }
3005 2969
3006 if (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB) { 2970 if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) {
3007 if (sectors > su_dev->se_dev_attrib.fabric_max_sectors) { 2971 if (sectors > su_dev->se_dev_attrib.fabric_max_sectors) {
3008 printk_ratelimited(KERN_ERR "SCSI OP %02xh with too" 2972 printk_ratelimited(KERN_ERR "SCSI OP %02xh with too"
3009 " big sectors %u exceeds fabric_max_sectors:" 2973 " big sectors %u exceeds fabric_max_sectors:"
@@ -3022,7 +2986,7 @@ static int transport_generic_cmd_sequencer(
3022 2986
3023 /* reject any command that we don't have a handler for */ 2987 /* reject any command that we don't have a handler for */
3024 if (!(passthrough || cmd->execute_cmd || 2988 if (!(passthrough || cmd->execute_cmd ||
3025 (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB))) 2989 (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB)))
3026 goto out_unsupported_cdb; 2990 goto out_unsupported_cdb;
3027 2991
3028 return 0; 2992 return 0;
@@ -3357,31 +3321,27 @@ int transport_generic_map_mem_to_cmd(
3357 if (!sgl || !sgl_count) 3321 if (!sgl || !sgl_count)
3358 return 0; 3322 return 0;
3359 3323
3360 if ((cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB) || 3324 /*
3361 (cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB)) { 3325 * Reject SCSI data overflow with map_mem_to_cmd() as incoming
3362 /* 3326 * scatterlists already have been set to follow what the fabric
3363 * Reject SCSI data overflow with map_mem_to_cmd() as incoming 3327 * passes for the original expected data transfer length.
3364 * scatterlists already have been set to follow what the fabric 3328 */
3365 * passes for the original expected data transfer length. 3329 if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
3366 */ 3330 pr_warn("Rejecting SCSI DATA overflow for fabric using"
3367 if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { 3331 " SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC\n");
3368 pr_warn("Rejecting SCSI DATA overflow for fabric using" 3332 cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
3369 " SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC\n"); 3333 cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD;
3370 cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; 3334 return -EINVAL;
3371 cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD; 3335 }
3372 return -EINVAL;
3373 }
3374 3336
3375 cmd->t_data_sg = sgl; 3337 cmd->t_data_sg = sgl;
3376 cmd->t_data_nents = sgl_count; 3338 cmd->t_data_nents = sgl_count;
3377 3339
3378 if (sgl_bidi && sgl_bidi_count) { 3340 if (sgl_bidi && sgl_bidi_count) {
3379 cmd->t_bidi_data_sg = sgl_bidi; 3341 cmd->t_bidi_data_sg = sgl_bidi;
3380 cmd->t_bidi_data_nents = sgl_bidi_count; 3342 cmd->t_bidi_data_nents = sgl_bidi_count;
3381 }
3382 cmd->se_cmd_flags |= SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC;
3383 } 3343 }
3384 3344 cmd->se_cmd_flags |= SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC;
3385 return 0; 3345 return 0;
3386} 3346}
3387EXPORT_SYMBOL(transport_generic_map_mem_to_cmd); 3347EXPORT_SYMBOL(transport_generic_map_mem_to_cmd);
@@ -3453,7 +3413,7 @@ transport_generic_get_mem(struct se_cmd *cmd)
3453 cmd->t_data_nents = nents; 3413 cmd->t_data_nents = nents;
3454 sg_init_table(cmd->t_data_sg, nents); 3414 sg_init_table(cmd->t_data_sg, nents);
3455 3415
3456 zero_flag = cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB ? 0 : __GFP_ZERO; 3416 zero_flag = cmd->se_cmd_flags & SCF_SCSI_DATA_CDB ? 0 : __GFP_ZERO;
3457 3417
3458 while (length) { 3418 while (length) {
3459 u32 page_len = min_t(u32, length, PAGE_SIZE); 3419 u32 page_len = min_t(u32, length, PAGE_SIZE);
@@ -3500,8 +3460,7 @@ int transport_generic_new_cmd(struct se_cmd *cmd)
3500 } 3460 }
3501 3461
3502 /* Workaround for handling zero-length control CDBs */ 3462 /* Workaround for handling zero-length control CDBs */
3503 if ((cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB) && 3463 if (!(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) && !cmd->data_length) {
3504 !cmd->data_length) {
3505 spin_lock_irq(&cmd->t_state_lock); 3464 spin_lock_irq(&cmd->t_state_lock);
3506 cmd->t_state = TRANSPORT_COMPLETE; 3465 cmd->t_state = TRANSPORT_COMPLETE;
3507 cmd->transport_state |= CMD_T_ACTIVE; 3466 cmd->transport_state |= CMD_T_ACTIVE;
@@ -3519,7 +3478,7 @@ int transport_generic_new_cmd(struct se_cmd *cmd)
3519 return 0; 3478 return 0;
3520 } 3479 }
3521 3480
3522 if (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB) { 3481 if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) {
3523 struct se_dev_attrib *attr = &dev->se_sub_dev->se_dev_attrib; 3482 struct se_dev_attrib *attr = &dev->se_sub_dev->se_dev_attrib;
3524 3483
3525 if (transport_cmd_get_valid_sectors(cmd) < 0) 3484 if (transport_cmd_get_valid_sectors(cmd) < 0)
diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
index 5b65f33939a8..4ad58ac823e5 100644
--- a/drivers/target/tcm_fc/tfc_cmd.c
+++ b/drivers/target/tcm_fc/tfc_cmd.c
@@ -215,7 +215,7 @@ int ft_write_pending(struct se_cmd *se_cmd)
215 */ 215 */
216 if ((ep->xid <= lport->lro_xid) && 216 if ((ep->xid <= lport->lro_xid) &&
217 (fh->fh_r_ctl == FC_RCTL_DD_DATA_DESC)) { 217 (fh->fh_r_ctl == FC_RCTL_DD_DATA_DESC)) {
218 if ((se_cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB) && 218 if ((se_cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) &&
219 lport->tt.ddp_target(lport, ep->xid, 219 lport->tt.ddp_target(lport, ep->xid,
220 se_cmd->t_data_sg, 220 se_cmd->t_data_sg,
221 se_cmd->t_data_nents)) 221 se_cmd->t_data_nents))
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index dc35d8660aa6..abda19d6cbd2 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -160,25 +160,22 @@ enum se_cmd_flags_table {
160 SCF_SUPPORTED_SAM_OPCODE = 0x00000001, 160 SCF_SUPPORTED_SAM_OPCODE = 0x00000001,
161 SCF_TRANSPORT_TASK_SENSE = 0x00000002, 161 SCF_TRANSPORT_TASK_SENSE = 0x00000002,
162 SCF_EMULATED_TASK_SENSE = 0x00000004, 162 SCF_EMULATED_TASK_SENSE = 0x00000004,
163 SCF_SCSI_DATA_SG_IO_CDB = 0x00000008, 163 SCF_SCSI_DATA_CDB = 0x00000008,
164 SCF_SCSI_CONTROL_SG_IO_CDB = 0x00000010, 164 SCF_SCSI_TMR_CDB = 0x00000010,
165 SCF_SCSI_NON_DATA_CDB = 0x00000020, 165 SCF_SCSI_CDB_EXCEPTION = 0x00000020,
166 SCF_SCSI_TMR_CDB = 0x00000040, 166 SCF_SCSI_RESERVATION_CONFLICT = 0x00000040,
167 SCF_SCSI_CDB_EXCEPTION = 0x00000080, 167 SCF_FUA = 0x00000080,
168 SCF_SCSI_RESERVATION_CONFLICT = 0x00000100, 168 SCF_SE_LUN_CMD = 0x00000100,
169 SCF_FUA = 0x00000200, 169 SCF_SE_ALLOW_EOO = 0x00000200,
170 SCF_SE_LUN_CMD = 0x00000800, 170 SCF_BIDI = 0x00000400,
171 SCF_SE_ALLOW_EOO = 0x00001000, 171 SCF_SENT_CHECK_CONDITION = 0x00000800,
172 SCF_BIDI = 0x00002000, 172 SCF_OVERFLOW_BIT = 0x00001000,
173 SCF_SENT_CHECK_CONDITION = 0x00004000, 173 SCF_UNDERFLOW_BIT = 0x00002000,
174 SCF_OVERFLOW_BIT = 0x00008000, 174 SCF_SENT_DELAYED_TAS = 0x00004000,
175 SCF_UNDERFLOW_BIT = 0x00010000, 175 SCF_ALUA_NON_OPTIMIZED = 0x00008000,
176 SCF_SENT_DELAYED_TAS = 0x00020000, 176 SCF_DELAYED_CMD_FROM_SAM_ATTR = 0x00010000,
177 SCF_ALUA_NON_OPTIMIZED = 0x00040000, 177 SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000,
178 SCF_DELAYED_CMD_FROM_SAM_ATTR = 0x00080000, 178 SCF_ACK_KREF = 0x00040000,
179 SCF_UNUSED = 0x00100000,
180 SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00200000,
181 SCF_ACK_KREF = 0x00400000,
182}; 179};
183 180
184/* struct se_dev_entry->lun_flags and struct se_lun->lun_access */ 181/* struct se_dev_entry->lun_flags and struct se_lun->lun_access */