aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2016-04-25 12:16:34 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2016-04-29 19:44:23 -0400
commitf46eb0e9fc763b7b66c325eb94e6aefa960146d2 (patch)
tree19ab8555c08d7ab0a7c9ed4a71a388483fdadc0a /drivers/scsi
parentfd32119b0deac1af90ca3bed145f17d5ad68d5a7 (diff)
scsi_debug: use likely hints on fast path
The most common commands in normal use are the READ and WRITE SCSI commands. Use likely and unlikely hints along the path taken by these commands. Rename check_readiness() to make_ua() and remove associated dead code. Rename devInfoReg() to find_build_dev_info(). Signed-off-by: Douglas Gilbert <dgilbert@interlog.com> Reviewed-by: Hannes Reinicke <hare@suse.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/scsi_debug.c219
1 files changed, 105 insertions, 114 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index f952803ea966..6b2d00675ee2 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -190,10 +190,6 @@ static const char *sdebug_version_date = "20160422";
190#define SDEBUG_UA_MICROCODE_CHANGED_WO_RESET 6 190#define SDEBUG_UA_MICROCODE_CHANGED_WO_RESET 6
191#define SDEBUG_NUM_UAS 7 191#define SDEBUG_NUM_UAS 7
192 192
193/* for check_readiness() */
194#define UAS_ONLY 1 /* check for UAs only */
195#define UAS_TUR 0 /* if no UAs then check if media access possible */
196
197/* when 1==SDEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this 193/* when 1==SDEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this
198 * sector on read commands: */ 194 * sector on read commands: */
199#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */ 195#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */
@@ -595,6 +591,7 @@ static bool sdebug_host_lock = DEF_HOST_LOCK;
595static bool sdebug_strict = DEF_STRICT; 591static bool sdebug_strict = DEF_STRICT;
596static bool sdebug_any_injecting_opt; 592static bool sdebug_any_injecting_opt;
597static bool sdebug_verbose; 593static bool sdebug_verbose;
594static bool have_dif_prot;
598 595
599static atomic_t sdebug_cmnd_count; 596static atomic_t sdebug_cmnd_count;
600static atomic_t sdebug_completions; 597static atomic_t sdebug_completions;
@@ -793,8 +790,7 @@ static void clear_luns_changed_on_target(struct sdebug_dev_info *devip)
793 spin_unlock(&sdebug_host_list_lock); 790 spin_unlock(&sdebug_host_list_lock);
794} 791}
795 792
796static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only, 793static int make_ua(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
797 struct sdebug_dev_info * devip)
798{ 794{
799 int k; 795 int k;
800 796
@@ -804,37 +800,37 @@ static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only,
804 800
805 switch (k) { 801 switch (k) {
806 case SDEBUG_UA_POR: 802 case SDEBUG_UA_POR:
807 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 803 mk_sense_buffer(scp, UNIT_ATTENTION, UA_RESET_ASC,
808 UA_RESET_ASC, POWER_ON_RESET_ASCQ); 804 POWER_ON_RESET_ASCQ);
809 if (sdebug_verbose) 805 if (sdebug_verbose)
810 cp = "power on reset"; 806 cp = "power on reset";
811 break; 807 break;
812 case SDEBUG_UA_BUS_RESET: 808 case SDEBUG_UA_BUS_RESET:
813 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 809 mk_sense_buffer(scp, UNIT_ATTENTION, UA_RESET_ASC,
814 UA_RESET_ASC, BUS_RESET_ASCQ); 810 BUS_RESET_ASCQ);
815 if (sdebug_verbose) 811 if (sdebug_verbose)
816 cp = "bus reset"; 812 cp = "bus reset";
817 break; 813 break;
818 case SDEBUG_UA_MODE_CHANGED: 814 case SDEBUG_UA_MODE_CHANGED:
819 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 815 mk_sense_buffer(scp, UNIT_ATTENTION, UA_CHANGED_ASC,
820 UA_CHANGED_ASC, MODE_CHANGED_ASCQ); 816 MODE_CHANGED_ASCQ);
821 if (sdebug_verbose) 817 if (sdebug_verbose)
822 cp = "mode parameters changed"; 818 cp = "mode parameters changed";
823 break; 819 break;
824 case SDEBUG_UA_CAPACITY_CHANGED: 820 case SDEBUG_UA_CAPACITY_CHANGED:
825 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 821 mk_sense_buffer(scp, UNIT_ATTENTION, UA_CHANGED_ASC,
826 UA_CHANGED_ASC, CAPACITY_CHANGED_ASCQ); 822 CAPACITY_CHANGED_ASCQ);
827 if (sdebug_verbose) 823 if (sdebug_verbose)
828 cp = "capacity data changed"; 824 cp = "capacity data changed";
829 break; 825 break;
830 case SDEBUG_UA_MICROCODE_CHANGED: 826 case SDEBUG_UA_MICROCODE_CHANGED:
831 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 827 mk_sense_buffer(scp, UNIT_ATTENTION,
832 TARGET_CHANGED_ASC, MICROCODE_CHANGED_ASCQ); 828 TARGET_CHANGED_ASC, MICROCODE_CHANGED_ASCQ);
833 if (sdebug_verbose) 829 if (sdebug_verbose)
834 cp = "microcode has been changed"; 830 cp = "microcode has been changed";
835 break; 831 break;
836 case SDEBUG_UA_MICROCODE_CHANGED_WO_RESET: 832 case SDEBUG_UA_MICROCODE_CHANGED_WO_RESET:
837 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 833 mk_sense_buffer(scp, UNIT_ATTENTION,
838 TARGET_CHANGED_ASC, 834 TARGET_CHANGED_ASC,
839 MICROCODE_CHANGED_WO_RESET_ASCQ); 835 MICROCODE_CHANGED_WO_RESET_ASCQ);
840 if (sdebug_verbose) 836 if (sdebug_verbose)
@@ -851,7 +847,7 @@ static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only,
851 */ 847 */
852 if (sdebug_scsi_level >= 6) /* SPC-4 and above */ 848 if (sdebug_scsi_level >= 6) /* SPC-4 and above */
853 clear_luns_changed_on_target(devip); 849 clear_luns_changed_on_target(devip);
854 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 850 mk_sense_buffer(scp, UNIT_ATTENTION,
855 TARGET_CHANGED_ASC, 851 TARGET_CHANGED_ASC,
856 LUNS_CHANGED_ASCQ); 852 LUNS_CHANGED_ASCQ);
857 if (sdebug_verbose) 853 if (sdebug_verbose)
@@ -865,20 +861,11 @@ static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only,
865 } 861 }
866 clear_bit(k, devip->uas_bm); 862 clear_bit(k, devip->uas_bm);
867 if (sdebug_verbose) 863 if (sdebug_verbose)
868 sdev_printk(KERN_INFO, SCpnt->device, 864 sdev_printk(KERN_INFO, scp->device,
869 "%s reports: Unit attention: %s\n", 865 "%s reports: Unit attention: %s\n",
870 my_name, cp); 866 my_name, cp);
871 return check_condition_result; 867 return check_condition_result;
872 } 868 }
873 if ((UAS_TUR == uas_only) && devip->stopped) {
874 mk_sense_buffer(SCpnt, NOT_READY, LOGICAL_UNIT_NOT_READY,
875 0x2);
876 if (sdebug_verbose)
877 sdev_printk(KERN_INFO, SCpnt->device,
878 "%s reports: Not ready: %s\n", my_name,
879 "initializing command required");
880 return check_condition_result;
881 }
882 return 0; 869 return 0;
883} 870}
884 871
@@ -1345,7 +1332,7 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1345 arr[2] = sdebug_scsi_level; 1332 arr[2] = sdebug_scsi_level;
1346 arr[3] = 2; /* response_data_format==2 */ 1333 arr[3] = 2; /* response_data_format==2 */
1347 arr[4] = SDEBUG_LONG_INQ_SZ - 5; 1334 arr[4] = SDEBUG_LONG_INQ_SZ - 5;
1348 arr[5] = sdebug_dif ? 1 : 0; /* PROTECT bit */ 1335 arr[5] = (int)have_dif_prot; /* PROTECT bit */
1349 if (0 == sdebug_vpd_use_hostno) 1336 if (0 == sdebug_vpd_use_hostno)
1350 arr[5] = 0x10; /* claim: implicit TGPS */ 1337 arr[5] = 0x10; /* claim: implicit TGPS */
1351 arr[6] = 0x10; /* claim: MultiP */ 1338 arr[6] = 0x10; /* claim: MultiP */
@@ -2506,7 +2493,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2506 check_prot = false; 2493 check_prot = false;
2507 break; 2494 break;
2508 } 2495 }
2509 if (check_prot) { 2496 if (unlikely(have_dif_prot && check_prot)) {
2510 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION && 2497 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION &&
2511 (cmd[1] & 0xe0)) { 2498 (cmd[1] & 0xe0)) {
2512 mk_sense_invalid_opcode(scp); 2499 mk_sense_invalid_opcode(scp);
@@ -2518,7 +2505,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2518 sdev_printk(KERN_ERR, scp->device, "Unprotected RD " 2505 sdev_printk(KERN_ERR, scp->device, "Unprotected RD "
2519 "to DIF device\n"); 2506 "to DIF device\n");
2520 } 2507 }
2521 if (sdebug_any_injecting_opt) { 2508 if (unlikely(sdebug_any_injecting_opt)) {
2522 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp); 2509 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
2523 2510
2524 if (ep->inj_short) 2511 if (ep->inj_short)
@@ -2526,20 +2513,20 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2526 } 2513 }
2527 2514
2528 /* inline check_device_access_params() */ 2515 /* inline check_device_access_params() */
2529 if (lba + num > sdebug_capacity) { 2516 if (unlikely(lba + num > sdebug_capacity)) {
2530 mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 0); 2517 mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 0);
2531 return check_condition_result; 2518 return check_condition_result;
2532 } 2519 }
2533 /* transfer length excessive (tie in to block limits VPD page) */ 2520 /* transfer length excessive (tie in to block limits VPD page) */
2534 if (num > sdebug_store_sectors) { 2521 if (unlikely(num > sdebug_store_sectors)) {
2535 /* needs work to find which cdb byte 'num' comes from */ 2522 /* needs work to find which cdb byte 'num' comes from */
2536 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); 2523 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
2537 return check_condition_result; 2524 return check_condition_result;
2538 } 2525 }
2539 2526
2540 if ((SDEBUG_OPT_MEDIUM_ERR & sdebug_opts) && 2527 if (unlikely((SDEBUG_OPT_MEDIUM_ERR & sdebug_opts) &&
2541 (lba <= (OPT_MEDIUM_ERR_ADDR + OPT_MEDIUM_ERR_NUM - 1)) && 2528 (lba <= (OPT_MEDIUM_ERR_ADDR + OPT_MEDIUM_ERR_NUM - 1)) &&
2542 ((lba + num) > OPT_MEDIUM_ERR_ADDR)) { 2529 ((lba + num) > OPT_MEDIUM_ERR_ADDR))) {
2543 /* claim unrecoverable read error */ 2530 /* claim unrecoverable read error */
2544 mk_sense_buffer(scp, MEDIUM_ERROR, UNRECOVERED_READ_ERR, 0); 2531 mk_sense_buffer(scp, MEDIUM_ERROR, UNRECOVERED_READ_ERR, 0);
2545 /* set info field and valid bit for fixed descriptor */ 2532 /* set info field and valid bit for fixed descriptor */
@@ -2556,7 +2543,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2556 read_lock_irqsave(&atomic_rw, iflags); 2543 read_lock_irqsave(&atomic_rw, iflags);
2557 2544
2558 /* DIX + T10 DIF */ 2545 /* DIX + T10 DIF */
2559 if (sdebug_dix && scsi_prot_sg_count(scp)) { 2546 if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) {
2560 int prot_ret = prot_verify_read(scp, lba, num, ei_lba); 2547 int prot_ret = prot_verify_read(scp, lba, num, ei_lba);
2561 2548
2562 if (prot_ret) { 2549 if (prot_ret) {
@@ -2568,12 +2555,12 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2568 2555
2569 ret = do_device_access(scp, lba, num, false); 2556 ret = do_device_access(scp, lba, num, false);
2570 read_unlock_irqrestore(&atomic_rw, iflags); 2557 read_unlock_irqrestore(&atomic_rw, iflags);
2571 if (ret == -1) 2558 if (unlikely(ret == -1))
2572 return DID_ERROR << 16; 2559 return DID_ERROR << 16;
2573 2560
2574 scsi_in(scp)->resid = scsi_bufflen(scp) - ret; 2561 scsi_in(scp)->resid = scsi_bufflen(scp) - ret;
2575 2562
2576 if (sdebug_any_injecting_opt) { 2563 if (unlikely(sdebug_any_injecting_opt)) {
2577 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp); 2564 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
2578 2565
2579 if (ep->inj_recovered) { 2566 if (ep->inj_recovered) {
@@ -2817,7 +2804,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2817 check_prot = false; 2804 check_prot = false;
2818 break; 2805 break;
2819 } 2806 }
2820 if (check_prot) { 2807 if (unlikely(have_dif_prot && check_prot)) {
2821 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION && 2808 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION &&
2822 (cmd[1] & 0xe0)) { 2809 (cmd[1] & 0xe0)) {
2823 mk_sense_invalid_opcode(scp); 2810 mk_sense_invalid_opcode(scp);
@@ -2831,12 +2818,12 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2831 } 2818 }
2832 2819
2833 /* inline check_device_access_params() */ 2820 /* inline check_device_access_params() */
2834 if (lba + num > sdebug_capacity) { 2821 if (unlikely(lba + num > sdebug_capacity)) {
2835 mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 0); 2822 mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 0);
2836 return check_condition_result; 2823 return check_condition_result;
2837 } 2824 }
2838 /* transfer length excessive (tie in to block limits VPD page) */ 2825 /* transfer length excessive (tie in to block limits VPD page) */
2839 if (num > sdebug_store_sectors) { 2826 if (unlikely(num > sdebug_store_sectors)) {
2840 /* needs work to find which cdb byte 'num' comes from */ 2827 /* needs work to find which cdb byte 'num' comes from */
2841 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); 2828 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
2842 return check_condition_result; 2829 return check_condition_result;
@@ -2845,7 +2832,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2845 write_lock_irqsave(&atomic_rw, iflags); 2832 write_lock_irqsave(&atomic_rw, iflags);
2846 2833
2847 /* DIX + T10 DIF */ 2834 /* DIX + T10 DIF */
2848 if (sdebug_dix && scsi_prot_sg_count(scp)) { 2835 if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) {
2849 int prot_ret = prot_verify_write(scp, lba, num, ei_lba); 2836 int prot_ret = prot_verify_write(scp, lba, num, ei_lba);
2850 2837
2851 if (prot_ret) { 2838 if (prot_ret) {
@@ -2856,17 +2843,17 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2856 } 2843 }
2857 2844
2858 ret = do_device_access(scp, lba, num, true); 2845 ret = do_device_access(scp, lba, num, true);
2859 if (scsi_debug_lbp()) 2846 if (unlikely(scsi_debug_lbp()))
2860 map_region(lba, num); 2847 map_region(lba, num);
2861 write_unlock_irqrestore(&atomic_rw, iflags); 2848 write_unlock_irqrestore(&atomic_rw, iflags);
2862 if (-1 == ret) 2849 if (unlikely(-1 == ret))
2863 return DID_ERROR << 16; 2850 return DID_ERROR << 16;
2864 else if (sdebug_verbose && (ret < (num * sdebug_sector_size))) 2851 else if (sdebug_verbose && (ret < (num * sdebug_sector_size)))
2865 sdev_printk(KERN_INFO, scp->device, 2852 sdev_printk(KERN_INFO, scp->device,
2866 "%s: write: cdb indicated=%u, IO sent=%d bytes\n", 2853 "%s: write: cdb indicated=%u, IO sent=%d bytes\n",
2867 my_name, num * sdebug_sector_size, ret); 2854 my_name, num * sdebug_sector_size, ret);
2868 2855
2869 if (sdebug_any_injecting_opt) { 2856 if (unlikely(sdebug_any_injecting_opt)) {
2870 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp); 2857 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
2871 2858
2872 if (ep->inj_recovered) { 2859 if (ep->inj_recovered) {
@@ -3351,28 +3338,28 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp)
3351 3338
3352 atomic_inc(&sdebug_completions); 3339 atomic_inc(&sdebug_completions);
3353 qa_indx = sd_dp->qa_indx; 3340 qa_indx = sd_dp->qa_indx;
3354 if ((qa_indx < 0) || (qa_indx >= SCSI_DEBUG_CANQUEUE)) { 3341 if (unlikely((qa_indx < 0) || (qa_indx >= SCSI_DEBUG_CANQUEUE))) {
3355 pr_err("wild qa_indx=%d\n", qa_indx); 3342 pr_err("wild qa_indx=%d\n", qa_indx);
3356 return; 3343 return;
3357 } 3344 }
3358 spin_lock_irqsave(&queued_arr_lock, iflags); 3345 spin_lock_irqsave(&queued_arr_lock, iflags);
3359 sqcp = &queued_arr[qa_indx]; 3346 sqcp = &queued_arr[qa_indx];
3360 scp = sqcp->a_cmnd; 3347 scp = sqcp->a_cmnd;
3361 if (NULL == scp) { 3348 if (unlikely(NULL == scp)) {
3362 spin_unlock_irqrestore(&queued_arr_lock, iflags); 3349 spin_unlock_irqrestore(&queued_arr_lock, iflags);
3363 pr_err("scp is NULL\n"); 3350 pr_err("scp is NULL\n");
3364 return; 3351 return;
3365 } 3352 }
3366 devip = (struct sdebug_dev_info *)scp->device->hostdata; 3353 devip = (struct sdebug_dev_info *)scp->device->hostdata;
3367 if (devip) 3354 if (likely(devip))
3368 atomic_dec(&devip->num_in_q); 3355 atomic_dec(&devip->num_in_q);
3369 else 3356 else
3370 pr_err("devip=NULL\n"); 3357 pr_err("devip=NULL\n");
3371 if (atomic_read(&retired_max_queue) > 0) 3358 if (unlikely(atomic_read(&retired_max_queue) > 0))
3372 retiring = 1; 3359 retiring = 1;
3373 3360
3374 sqcp->a_cmnd = NULL; 3361 sqcp->a_cmnd = NULL;
3375 if (!test_and_clear_bit(qa_indx, queued_in_use_bm)) { 3362 if (unlikely(!test_and_clear_bit(qa_indx, queued_in_use_bm))) {
3376 spin_unlock_irqrestore(&queued_arr_lock, iflags); 3363 spin_unlock_irqrestore(&queued_arr_lock, iflags);
3377 pr_err("Unexpected completion\n"); 3364 pr_err("Unexpected completion\n");
3378 return; 3365 return;
@@ -3427,15 +3414,12 @@ static struct sdebug_dev_info *sdebug_device_create(
3427 return devip; 3414 return devip;
3428} 3415}
3429 3416
3430static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev) 3417static struct sdebug_dev_info *find_build_dev_info(struct scsi_device *sdev)
3431{ 3418{
3432 struct sdebug_host_info * sdbg_host; 3419 struct sdebug_host_info *sdbg_host;
3433 struct sdebug_dev_info * open_devip = NULL; 3420 struct sdebug_dev_info *open_devip = NULL;
3434 struct sdebug_dev_info * devip = 3421 struct sdebug_dev_info *devip;
3435 (struct sdebug_dev_info *)sdev->hostdata;
3436 3422
3437 if (devip)
3438 return devip;
3439 sdbg_host = *(struct sdebug_host_info **)shost_priv(sdev->host); 3423 sdbg_host = *(struct sdebug_host_info **)shost_priv(sdev->host);
3440 if (!sdbg_host) { 3424 if (!sdbg_host) {
3441 pr_err("Host info NULL\n"); 3425 pr_err("Host info NULL\n");
@@ -3480,16 +3464,19 @@ static int scsi_debug_slave_alloc(struct scsi_device *sdp)
3480 3464
3481static int scsi_debug_slave_configure(struct scsi_device *sdp) 3465static int scsi_debug_slave_configure(struct scsi_device *sdp)
3482{ 3466{
3483 struct sdebug_dev_info *devip; 3467 struct sdebug_dev_info *devip =
3468 (struct sdebug_dev_info *)sdp->hostdata;
3484 3469
3485 if (sdebug_verbose) 3470 if (sdebug_verbose)
3486 pr_info("slave_configure <%u %u %u %llu>\n", 3471 pr_info("slave_configure <%u %u %u %llu>\n",
3487 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); 3472 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
3488 if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) 3473 if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN)
3489 sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN; 3474 sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN;
3490 devip = devInfoReg(sdp); 3475 if (NULL == devip) {
3491 if (NULL == devip) 3476 devip = find_build_dev_info(sdp);
3492 return 1; /* no resources, will be marked offline */ 3477 if (NULL == devip)
3478 return 1; /* no resources, will be marked offline */
3479 }
3493 sdp->hostdata = devip; 3480 sdp->hostdata = devip;
3494 blk_queue_max_segment_size(sdp->request_queue, -1U); 3481 blk_queue_max_segment_size(sdp->request_queue, -1U);
3495 if (sdebug_no_uld) 3482 if (sdebug_no_uld)
@@ -3622,15 +3609,14 @@ static int scsi_debug_abort(struct scsi_cmnd *SCpnt)
3622 3609
3623static int scsi_debug_device_reset(struct scsi_cmnd * SCpnt) 3610static int scsi_debug_device_reset(struct scsi_cmnd * SCpnt)
3624{ 3611{
3625 struct sdebug_dev_info * devip;
3626
3627 ++num_dev_resets; 3612 ++num_dev_resets;
3628 if (SCpnt && SCpnt->device) { 3613 if (SCpnt && SCpnt->device) {
3629 struct scsi_device *sdp = SCpnt->device; 3614 struct scsi_device *sdp = SCpnt->device;
3615 struct sdebug_dev_info *devip =
3616 (struct sdebug_dev_info *)sdp->hostdata;
3630 3617
3631 if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) 3618 if (SDEBUG_OPT_ALL_NOISE & sdebug_opts)
3632 sdev_printk(KERN_INFO, sdp, "%s\n", __func__); 3619 sdev_printk(KERN_INFO, sdp, "%s\n", __func__);
3633 devip = devInfoReg(sdp);
3634 if (devip) 3620 if (devip)
3635 set_bit(SDEBUG_UA_POR, devip->uas_bm); 3621 set_bit(SDEBUG_UA_POR, devip->uas_bm);
3636 } 3622 }
@@ -3790,19 +3776,18 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
3790 struct scsi_device *sdp; 3776 struct scsi_device *sdp;
3791 struct sdebug_defer *sd_dp; 3777 struct sdebug_defer *sd_dp;
3792 3778
3793 /* this should never happen */ 3779 if (unlikely(WARN_ON(!cmnd)))
3794 if (WARN_ON(!cmnd))
3795 return SCSI_MLQUEUE_HOST_BUSY; 3780 return SCSI_MLQUEUE_HOST_BUSY;
3796 3781
3797 if (NULL == devip) { 3782 if (unlikely(NULL == devip)) {
3798 pr_warn("called devip == NULL\n"); 3783 if (0 == scsi_result)
3799 /* no particularly good error to report back */ 3784 scsi_result = DID_NO_CONNECT << 16;
3800 return SCSI_MLQUEUE_HOST_BUSY; 3785 goto respond_in_thread;
3801 } 3786 }
3802 3787
3803 sdp = cmnd->device; 3788 sdp = cmnd->device;
3804 3789
3805 if (sdebug_verbose && scsi_result) 3790 if (unlikely(sdebug_verbose && scsi_result))
3806 sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n", 3791 sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n",
3807 __func__, scsi_result); 3792 __func__, scsi_result);
3808 if (delta_jiff == 0) 3793 if (delta_jiff == 0)
@@ -3813,15 +3798,15 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
3813 num_in_q = atomic_read(&devip->num_in_q); 3798 num_in_q = atomic_read(&devip->num_in_q);
3814 qdepth = cmnd->device->queue_depth; 3799 qdepth = cmnd->device->queue_depth;
3815 inject = 0; 3800 inject = 0;
3816 if ((qdepth > 0) && (num_in_q >= qdepth)) { 3801 if (unlikely((qdepth > 0) && (num_in_q >= qdepth))) {
3817 if (scsi_result) { 3802 if (scsi_result) {
3818 spin_unlock_irqrestore(&queued_arr_lock, iflags); 3803 spin_unlock_irqrestore(&queued_arr_lock, iflags);
3819 goto respond_in_thread; 3804 goto respond_in_thread;
3820 } else 3805 } else
3821 scsi_result = device_qfull_result; 3806 scsi_result = device_qfull_result;
3822 } else if ((sdebug_every_nth != 0) && 3807 } else if (unlikely((sdebug_every_nth != 0) &&
3823 (SDEBUG_OPT_RARE_TSF & sdebug_opts) && 3808 (SDEBUG_OPT_RARE_TSF & sdebug_opts) &&
3824 (scsi_result == 0)) { 3809 (scsi_result == 0))) {
3825 if ((num_in_q == (qdepth - 1)) && 3810 if ((num_in_q == (qdepth - 1)) &&
3826 (atomic_inc_return(&sdebug_a_tsf) >= 3811 (atomic_inc_return(&sdebug_a_tsf) >=
3827 abs(sdebug_every_nth))) { 3812 abs(sdebug_every_nth))) {
@@ -3832,7 +3817,7 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
3832 } 3817 }
3833 3818
3834 k = find_first_zero_bit(queued_in_use_bm, sdebug_max_queue); 3819 k = find_first_zero_bit(queued_in_use_bm, sdebug_max_queue);
3835 if (k >= sdebug_max_queue) { 3820 if (unlikely(k >= sdebug_max_queue)) {
3836 spin_unlock_irqrestore(&queued_arr_lock, iflags); 3821 spin_unlock_irqrestore(&queued_arr_lock, iflags);
3837 if (scsi_result) 3822 if (scsi_result)
3838 goto respond_in_thread; 3823 goto respond_in_thread;
@@ -3888,8 +3873,8 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
3888 } 3873 }
3889 schedule_work(&sd_dp->ew.work); 3874 schedule_work(&sd_dp->ew.work);
3890 } 3875 }
3891 if ((SDEBUG_OPT_Q_NOISE & sdebug_opts) && 3876 if (unlikely((SDEBUG_OPT_Q_NOISE & sdebug_opts) &&
3892 (scsi_result == device_qfull_result)) 3877 (scsi_result == device_qfull_result)))
3893 sdev_printk(KERN_INFO, sdp, 3878 sdev_printk(KERN_INFO, sdp,
3894 "%s: num_in_q=%d +1, %s%s\n", __func__, 3879 "%s: num_in_q=%d +1, %s%s\n", __func__,
3895 num_in_q, (inject ? "<inject> " : ""), 3880 num_in_q, (inject ? "<inject> " : ""),
@@ -4632,9 +4617,11 @@ static int __init scsi_debug_init(void)
4632 switch (sdebug_dif) { 4617 switch (sdebug_dif) {
4633 4618
4634 case SD_DIF_TYPE0_PROTECTION: 4619 case SD_DIF_TYPE0_PROTECTION:
4620 break;
4635 case SD_DIF_TYPE1_PROTECTION: 4621 case SD_DIF_TYPE1_PROTECTION:
4636 case SD_DIF_TYPE2_PROTECTION: 4622 case SD_DIF_TYPE2_PROTECTION:
4637 case SD_DIF_TYPE3_PROTECTION: 4623 case SD_DIF_TYPE3_PROTECTION:
4624 have_dif_prot = true;
4638 break; 4625 break;
4639 4626
4640 default: 4627 default:
@@ -4971,7 +4958,8 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
4971 bool has_wlun_rl; 4958 bool has_wlun_rl;
4972 4959
4973 scsi_set_resid(scp, 0); 4960 scsi_set_resid(scp, 0);
4974 if (sdebug_verbose && !(SDEBUG_OPT_NO_CDB_NOISE & sdebug_opts)) { 4961 if (unlikely(sdebug_verbose &&
4962 !(SDEBUG_OPT_NO_CDB_NOISE & sdebug_opts))) {
4975 char b[120]; 4963 char b[120];
4976 int n, len, sb; 4964 int n, len, sb;
4977 4965
@@ -4987,17 +4975,16 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
4987 sdev_printk(KERN_INFO, sdp, "%s: cmd %s\n", my_name, b); 4975 sdev_printk(KERN_INFO, sdp, "%s: cmd %s\n", my_name, b);
4988 } 4976 }
4989 has_wlun_rl = (sdp->lun == SCSI_W_LUN_REPORT_LUNS); 4977 has_wlun_rl = (sdp->lun == SCSI_W_LUN_REPORT_LUNS);
4990 if ((sdp->lun >= sdebug_max_luns) && !has_wlun_rl) 4978 if (unlikely((sdp->lun >= sdebug_max_luns) && !has_wlun_rl))
4991 return schedule_resp(scp, NULL, DID_NO_CONNECT << 16, 0); 4979 goto err_out;
4992 4980
4993 sdeb_i = opcode_ind_arr[opcode]; /* fully mapped */ 4981 sdeb_i = opcode_ind_arr[opcode]; /* fully mapped */
4994 oip = &opcode_info_arr[sdeb_i]; /* safe if table consistent */ 4982 oip = &opcode_info_arr[sdeb_i]; /* safe if table consistent */
4995 devip = (struct sdebug_dev_info *)sdp->hostdata; 4983 devip = (struct sdebug_dev_info *)sdp->hostdata;
4996 if (!devip) { 4984 if (unlikely(!devip)) {
4997 devip = devInfoReg(sdp); 4985 devip = find_build_dev_info(sdp);
4998 if (NULL == devip) 4986 if (NULL == devip)
4999 return schedule_resp(scp, NULL, DID_NO_CONNECT << 16, 4987 goto err_out;
5000 0);
5001 } 4988 }
5002 na = oip->num_attached; 4989 na = oip->num_attached;
5003 r_pfp = oip->pfp; 4990 r_pfp = oip->pfp;
@@ -5029,18 +5016,18 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
5029 } 5016 }
5030 } /* else (when na==0) we assume the oip is a match */ 5017 } /* else (when na==0) we assume the oip is a match */
5031 flags = oip->flags; 5018 flags = oip->flags;
5032 if (F_INV_OP & flags) { 5019 if (unlikely(F_INV_OP & flags)) {
5033 mk_sense_invalid_opcode(scp); 5020 mk_sense_invalid_opcode(scp);
5034 goto check_cond; 5021 goto check_cond;
5035 } 5022 }
5036 if (has_wlun_rl && !(F_RL_WLUN_OK & flags)) { 5023 if (unlikely(has_wlun_rl && !(F_RL_WLUN_OK & flags))) {
5037 if (sdebug_verbose) 5024 if (sdebug_verbose)
5038 sdev_printk(KERN_INFO, sdp, "%s: Opcode 0x%x not%s\n", 5025 sdev_printk(KERN_INFO, sdp, "%s: Opcode 0x%x not%s\n",
5039 my_name, opcode, " supported for wlun"); 5026 my_name, opcode, " supported for wlun");
5040 mk_sense_invalid_opcode(scp); 5027 mk_sense_invalid_opcode(scp);
5041 goto check_cond; 5028 goto check_cond;
5042 } 5029 }
5043 if (sdebug_strict) { /* check cdb against mask */ 5030 if (unlikely(sdebug_strict)) { /* check cdb against mask */
5044 u8 rem; 5031 u8 rem;
5045 int j; 5032 int j;
5046 5033
@@ -5056,13 +5043,14 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
5056 } 5043 }
5057 } 5044 }
5058 } 5045 }
5059 if (!(F_SKIP_UA & flags) && 5046 if (unlikely(!(F_SKIP_UA & flags) &&
5060 SDEBUG_NUM_UAS != find_first_bit(devip->uas_bm, SDEBUG_NUM_UAS)) { 5047 SDEBUG_NUM_UAS != find_first_bit(devip->uas_bm,
5061 errsts = check_readiness(scp, UAS_ONLY, devip); 5048 SDEBUG_NUM_UAS))) {
5049 errsts = make_ua(scp, devip);
5062 if (errsts) 5050 if (errsts)
5063 goto check_cond; 5051 goto check_cond;
5064 } 5052 }
5065 if ((F_M_ACCESS & flags) && devip->stopped) { 5053 if (unlikely((F_M_ACCESS & flags) && devip->stopped)) {
5066 mk_sense_buffer(scp, NOT_READY, LOGICAL_UNIT_NOT_READY, 0x2); 5054 mk_sense_buffer(scp, NOT_READY, LOGICAL_UNIT_NOT_READY, 0x2);
5067 if (sdebug_verbose) 5055 if (sdebug_verbose)
5068 sdev_printk(KERN_INFO, sdp, "%s reports: Not ready: " 5056 sdev_printk(KERN_INFO, sdp, "%s reports: Not ready: "
@@ -5073,12 +5061,12 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
5073 } 5061 }
5074 if (sdebug_fake_rw && (F_FAKE_RW & flags)) 5062 if (sdebug_fake_rw && (F_FAKE_RW & flags))
5075 goto fini; 5063 goto fini;
5076 if (sdebug_every_nth) { 5064 if (unlikely(sdebug_every_nth)) {
5077 if (check_inject(scp)) 5065 if (check_inject(scp))
5078 return 0; /* ignore command: make trouble */ 5066 return 0; /* ignore command: make trouble */
5079 } 5067 }
5080 if (oip->pfp) /* if this command has a resp_* function, call it */ 5068 if (likely(oip->pfp))
5081 errsts = oip->pfp(scp, devip); 5069 errsts = oip->pfp(scp, devip); /* calls a resp_* function */
5082 else if (r_pfp) /* if leaf function ptr NULL, try the root's */ 5070 else if (r_pfp) /* if leaf function ptr NULL, try the root's */
5083 errsts = r_pfp(scp, devip); 5071 errsts = r_pfp(scp, devip);
5084 5072
@@ -5087,6 +5075,8 @@ fini:
5087 ((F_DELAY_OVERR & flags) ? 0 : sdebug_jdelay)); 5075 ((F_DELAY_OVERR & flags) ? 0 : sdebug_jdelay));
5088check_cond: 5076check_cond:
5089 return schedule_resp(scp, devip, check_condition_result, 0); 5077 return schedule_resp(scp, devip, check_condition_result, 0);
5078err_out:
5079 return schedule_resp(scp, NULL, DID_NO_CONNECT << 16, 0);
5090} 5080}
5091 5081
5092static struct scsi_host_template sdebug_driver_template = { 5082static struct scsi_host_template sdebug_driver_template = {
@@ -5122,7 +5112,7 @@ static int sdebug_driver_probe(struct device * dev)
5122 int error = 0; 5112 int error = 0;
5123 struct sdebug_host_info *sdbg_host; 5113 struct sdebug_host_info *sdbg_host;
5124 struct Scsi_Host *hpnt; 5114 struct Scsi_Host *hpnt;
5125 int host_prot; 5115 int hprot;
5126 5116
5127 sdbg_host = to_sdebug_host(dev); 5117 sdbg_host = to_sdebug_host(dev);
5128 5118
@@ -5145,44 +5135,45 @@ static int sdebug_driver_probe(struct device * dev)
5145 /* = sdebug_max_luns; */ 5135 /* = sdebug_max_luns; */
5146 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; 5136 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1;
5147 5137
5148 host_prot = 0; 5138 hprot = 0;
5149 5139
5150 switch (sdebug_dif) { 5140 switch (sdebug_dif) {
5151 5141
5152 case SD_DIF_TYPE1_PROTECTION: 5142 case SD_DIF_TYPE1_PROTECTION:
5153 host_prot = SHOST_DIF_TYPE1_PROTECTION; 5143 hprot = SHOST_DIF_TYPE1_PROTECTION;
5154 if (sdebug_dix) 5144 if (sdebug_dix)
5155 host_prot |= SHOST_DIX_TYPE1_PROTECTION; 5145 hprot |= SHOST_DIX_TYPE1_PROTECTION;
5156 break; 5146 break;
5157 5147
5158 case SD_DIF_TYPE2_PROTECTION: 5148 case SD_DIF_TYPE2_PROTECTION:
5159 host_prot = SHOST_DIF_TYPE2_PROTECTION; 5149 hprot = SHOST_DIF_TYPE2_PROTECTION;
5160 if (sdebug_dix) 5150 if (sdebug_dix)
5161 host_prot |= SHOST_DIX_TYPE2_PROTECTION; 5151 hprot |= SHOST_DIX_TYPE2_PROTECTION;
5162 break; 5152 break;
5163 5153
5164 case SD_DIF_TYPE3_PROTECTION: 5154 case SD_DIF_TYPE3_PROTECTION:
5165 host_prot = SHOST_DIF_TYPE3_PROTECTION; 5155 hprot = SHOST_DIF_TYPE3_PROTECTION;
5166 if (sdebug_dix) 5156 if (sdebug_dix)
5167 host_prot |= SHOST_DIX_TYPE3_PROTECTION; 5157 hprot |= SHOST_DIX_TYPE3_PROTECTION;
5168 break; 5158 break;
5169 5159
5170 default: 5160 default:
5171 if (sdebug_dix) 5161 if (sdebug_dix)
5172 host_prot |= SHOST_DIX_TYPE0_PROTECTION; 5162 hprot |= SHOST_DIX_TYPE0_PROTECTION;
5173 break; 5163 break;
5174 } 5164 }
5175 5165
5176 scsi_host_set_prot(hpnt, host_prot); 5166 scsi_host_set_prot(hpnt, hprot);
5177 5167
5178 pr_info("host protection%s%s%s%s%s%s%s\n", 5168 if (have_dif_prot || sdebug_dix)
5179 (host_prot & SHOST_DIF_TYPE1_PROTECTION) ? " DIF1" : "", 5169 pr_info("host protection%s%s%s%s%s%s%s\n",
5180 (host_prot & SHOST_DIF_TYPE2_PROTECTION) ? " DIF2" : "", 5170 (hprot & SHOST_DIF_TYPE1_PROTECTION) ? " DIF1" : "",
5181 (host_prot & SHOST_DIF_TYPE3_PROTECTION) ? " DIF3" : "", 5171 (hprot & SHOST_DIF_TYPE2_PROTECTION) ? " DIF2" : "",
5182 (host_prot & SHOST_DIX_TYPE0_PROTECTION) ? " DIX0" : "", 5172 (hprot & SHOST_DIF_TYPE3_PROTECTION) ? " DIF3" : "",
5183 (host_prot & SHOST_DIX_TYPE1_PROTECTION) ? " DIX1" : "", 5173 (hprot & SHOST_DIX_TYPE0_PROTECTION) ? " DIX0" : "",
5184 (host_prot & SHOST_DIX_TYPE2_PROTECTION) ? " DIX2" : "", 5174 (hprot & SHOST_DIX_TYPE1_PROTECTION) ? " DIX1" : "",
5185 (host_prot & SHOST_DIX_TYPE3_PROTECTION) ? " DIX3" : ""); 5175 (hprot & SHOST_DIX_TYPE2_PROTECTION) ? " DIX2" : "",
5176 (hprot & SHOST_DIX_TYPE3_PROTECTION) ? " DIX3" : "");
5186 5177
5187 if (sdebug_guard == 1) 5178 if (sdebug_guard == 1)
5188 scsi_host_set_guard(hpnt, SHOST_DIX_GUARD_IP); 5179 scsi_host_set_guard(hpnt, SHOST_DIX_GUARD_IP);