aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2016-04-25 12:16:28 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2016-04-29 19:22:39 -0400
commit773642d95b8220502555122578694deeee8af4af (patch)
tree7f4096ae71f0a2db9434df4ca5d15eb56c561f03 /drivers/scsi
parentff54aee466e3ad3f5aad76c629a8bcb88fc9b348 (diff)
scsi_debug: cleanup naming and bit crunching
Shorten file scope static and constant names. Use more get/put_unaligned calls to hide bit banging. Introduce sdebug_verbose boolean to replace frequent masking of option bit flags. Add GPL and bump version. [mkp: Use logical instead of bitwise OR for LBP VPD flags] Signed-off-by: Douglas Gilbert <dgilbert@interlog.com> Reviewed-by: Hannes Reinecke <hare@suse.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/scsi_debug.c1162
1 files changed, 525 insertions, 637 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 06b151711cdd..ac74cbde7adf 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -6,23 +6,15 @@
6 * anything out of the ordinary is seen. 6 * anything out of the ordinary is seen.
7 * ^^^^^^^^^^^^^^^^^^^^^^^ Original ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7 * ^^^^^^^^^^^^^^^^^^^^^^^ Original ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 * 8 *
9 * This version is more generic, simulating a variable number of disk 9 * Copyright (C) 2001 - 2016 Douglas Gilbert
10 * (or disk like devices) sharing a common amount of RAM. To be more
11 * realistic, the simulated devices have the transport attributes of
12 * SAS disks.
13 * 10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
14 * 15 *
15 * For documentation see http://sg.danny.cz/sg/sdebug26.html 16 * For documentation see http://sg.danny.cz/sg/sdebug26.html
16 * 17 *
17 * D. Gilbert (dpg) work for Magneto-Optical device test [20010421]
18 * dpg: work for devfs large number of disks [20010809]
19 * forked for lk 2.5 series [20011216, 20020101]
20 * use vmalloc() more inquiry+mode_sense [20020302]
21 * add timers for delayed responses [20020721]
22 * Patrick Mansfield <patmans@us.ibm.com> max_luns+scsi_level [20021031]
23 * Mike Anderson <andmike@us.ibm.com> sysfs work [20021118]
24 * dpg: change style of boot options to "scsi_debug.num_tgts=2" and
25 * module options to "modprobe scsi_debug num_tgts=2" [20021221]
26 */ 18 */
27 19
28 20
@@ -66,8 +58,9 @@
66#include "sd.h" 58#include "sd.h"
67#include "scsi_logging.h" 59#include "scsi_logging.h"
68 60
69#define SCSI_DEBUG_VERSION "1.85" 61/* make sure inq_product_rev string corresponds to this version */
70static const char *scsi_debug_version_date = "20141022"; 62#define SCSI_DEBUG_VERSION "1.86"
63static const char *sdebug_version_date = "20160422";
71 64
72#define MY_NAME "scsi_debug" 65#define MY_NAME "scsi_debug"
73 66
@@ -145,38 +138,44 @@ static const char *scsi_debug_version_date = "20141022";
145#define DEF_STRICT 0 138#define DEF_STRICT 0
146#define DELAY_OVERRIDDEN -9999 139#define DELAY_OVERRIDDEN -9999
147 140
148/* bit mask values for scsi_debug_opts */ 141/* bit mask values for sdebug_opts */
149#define SCSI_DEBUG_OPT_NOISE 1 142#define SDEBUG_OPT_NOISE 1
150#define SCSI_DEBUG_OPT_MEDIUM_ERR 2 143#define SDEBUG_OPT_MEDIUM_ERR 2
151#define SCSI_DEBUG_OPT_TIMEOUT 4 144#define SDEBUG_OPT_TIMEOUT 4
152#define SCSI_DEBUG_OPT_RECOVERED_ERR 8 145#define SDEBUG_OPT_RECOVERED_ERR 8
153#define SCSI_DEBUG_OPT_TRANSPORT_ERR 16 146#define SDEBUG_OPT_TRANSPORT_ERR 16
154#define SCSI_DEBUG_OPT_DIF_ERR 32 147#define SDEBUG_OPT_DIF_ERR 32
155#define SCSI_DEBUG_OPT_DIX_ERR 64 148#define SDEBUG_OPT_DIX_ERR 64
156#define SCSI_DEBUG_OPT_MAC_TIMEOUT 128 149#define SDEBUG_OPT_MAC_TIMEOUT 128
157#define SCSI_DEBUG_OPT_SHORT_TRANSFER 0x100 150#define SDEBUG_OPT_SHORT_TRANSFER 0x100
158#define SCSI_DEBUG_OPT_Q_NOISE 0x200 151#define SDEBUG_OPT_Q_NOISE 0x200
159#define SCSI_DEBUG_OPT_ALL_TSF 0x400 152#define SDEBUG_OPT_ALL_TSF 0x400
160#define SCSI_DEBUG_OPT_RARE_TSF 0x800 153#define SDEBUG_OPT_RARE_TSF 0x800
161#define SCSI_DEBUG_OPT_N_WCE 0x1000 154#define SDEBUG_OPT_N_WCE 0x1000
162#define SCSI_DEBUG_OPT_RESET_NOISE 0x2000 155#define SDEBUG_OPT_RESET_NOISE 0x2000
163#define SCSI_DEBUG_OPT_NO_CDB_NOISE 0x4000 156#define SDEBUG_OPT_NO_CDB_NOISE 0x4000
164#define SCSI_DEBUG_OPT_ALL_NOISE (0x1 | 0x200 | 0x2000) 157#define SDEBUG_OPT_ALL_NOISE (SDEBUG_OPT_NOISE | SDEBUG_OPT_Q_NOISE | \
158 SDEBUG_OPT_RESET_NOISE)
159#define SDEBUG_OPT_ALL_INJECTING (SDEBUG_OPT_RECOVERED_ERR | \
160 SDEBUG_OPT_TRANSPORT_ERR | \
161 SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR | \
162 SDEBUG_OPT_SHORT_TRANSFER)
165/* When "every_nth" > 0 then modulo "every_nth" commands: 163/* When "every_nth" > 0 then modulo "every_nth" commands:
166 * - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set 164 * - a no response is simulated if SDEBUG_OPT_TIMEOUT is set
167 * - a RECOVERED_ERROR is simulated on successful read and write 165 * - a RECOVERED_ERROR is simulated on successful read and write
168 * commands if SCSI_DEBUG_OPT_RECOVERED_ERR is set. 166 * commands if SDEBUG_OPT_RECOVERED_ERR is set.
169 * - a TRANSPORT_ERROR is simulated on successful read and write 167 * - a TRANSPORT_ERROR is simulated on successful read and write
170 * commands if SCSI_DEBUG_OPT_TRANSPORT_ERR is set. 168 * commands if SDEBUG_OPT_TRANSPORT_ERR is set.
171 * 169 *
172 * When "every_nth" < 0 then after "- every_nth" commands: 170 * When "every_nth" < 0 then after "- every_nth" commands:
173 * - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set 171 * - a no response is simulated if SDEBUG_OPT_TIMEOUT is set
174 * - a RECOVERED_ERROR is simulated on successful read and write 172 * - a RECOVERED_ERROR is simulated on successful read and write
175 * commands if SCSI_DEBUG_OPT_RECOVERED_ERR is set. 173 * commands if SDEBUG_OPT_RECOVERED_ERR is set.
176 * - a TRANSPORT_ERROR is simulated on successful read and write 174 * - a TRANSPORT_ERROR is simulated on successful read and write
177 * commands if SCSI_DEBUG_OPT_TRANSPORT_ERR is set. 175 * commands if _DEBUG_OPT_TRANSPORT_ERR is set.
178 * This will continue until some other action occurs (e.g. the user 176 * This will continue on every subsequent command until some other action
179 * writing a new value (other than -1 or 1) to every_nth via sysfs). 177 * occurs (e.g. the user * writing a new value (other than -1 or 1) to
178 * every_nth via sysfs).
180 */ 179 */
181 180
182/* As indicated in SAM-5 and SPC-4 Unit Attentions (UAs)are returned in 181/* As indicated in SAM-5 and SPC-4 Unit Attentions (UAs)are returned in
@@ -196,7 +195,7 @@ static const char *scsi_debug_version_date = "20141022";
196#define UAS_ONLY 1 /* check for UAs only */ 195#define UAS_ONLY 1 /* check for UAs only */
197#define UAS_TUR 0 /* if no UAs then check if media access possible */ 196#define UAS_TUR 0 /* if no UAs then check if media access possible */
198 197
199/* when 1==SCSI_DEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this 198/* when 1==SDEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this
200 * sector on read commands: */ 199 * sector on read commands: */
201#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */ 200#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */
202#define OPT_MEDIUM_ERR_NUM 10 /* number of consecutive medium errs */ 201#define OPT_MEDIUM_ERR_NUM 10 /* number of consecutive medium errs */
@@ -517,47 +516,48 @@ struct sdebug_scmd_extra_t {
517 bool inj_short; 516 bool inj_short;
518}; 517};
519 518
520static int scsi_debug_add_host = DEF_NUM_HOST; 519static int sdebug_add_host = DEF_NUM_HOST;
521static int scsi_debug_ato = DEF_ATO; 520static int sdebug_ato = DEF_ATO;
522static int scsi_debug_delay = DEF_DELAY; 521static int sdebug_delay = DEF_DELAY;
523static int scsi_debug_dev_size_mb = DEF_DEV_SIZE_MB; 522static int sdebug_dev_size_mb = DEF_DEV_SIZE_MB;
524static int scsi_debug_dif = DEF_DIF; 523static int sdebug_dif = DEF_DIF;
525static int scsi_debug_dix = DEF_DIX; 524static int sdebug_dix = DEF_DIX;
526static int scsi_debug_dsense = DEF_D_SENSE; 525static int sdebug_dsense = DEF_D_SENSE;
527static int scsi_debug_every_nth = DEF_EVERY_NTH; 526static int sdebug_every_nth = DEF_EVERY_NTH;
528static int scsi_debug_fake_rw = DEF_FAKE_RW; 527static int sdebug_fake_rw = DEF_FAKE_RW;
529static unsigned int scsi_debug_guard = DEF_GUARD; 528static unsigned int sdebug_guard = DEF_GUARD;
530static int scsi_debug_lowest_aligned = DEF_LOWEST_ALIGNED; 529static int sdebug_lowest_aligned = DEF_LOWEST_ALIGNED;
531static int scsi_debug_max_luns = DEF_MAX_LUNS; 530static int sdebug_max_luns = DEF_MAX_LUNS;
532static int scsi_debug_max_queue = SCSI_DEBUG_CANQUEUE; 531static int sdebug_max_queue = SCSI_DEBUG_CANQUEUE;
533static atomic_t retired_max_queue; /* if > 0 then was prior max_queue */ 532static atomic_t retired_max_queue; /* if > 0 then was prior max_queue */
534static int scsi_debug_ndelay = DEF_NDELAY; 533static int sdebug_ndelay = DEF_NDELAY;
535static int scsi_debug_no_lun_0 = DEF_NO_LUN_0; 534static int sdebug_no_lun_0 = DEF_NO_LUN_0;
536static int scsi_debug_no_uld = 0; 535static int sdebug_no_uld;
537static int scsi_debug_num_parts = DEF_NUM_PARTS; 536static int sdebug_num_parts = DEF_NUM_PARTS;
538static int scsi_debug_num_tgts = DEF_NUM_TGTS; /* targets per host */ 537static int sdebug_num_tgts = DEF_NUM_TGTS; /* targets per host */
539static int scsi_debug_opt_blks = DEF_OPT_BLKS; 538static int sdebug_opt_blks = DEF_OPT_BLKS;
540static int scsi_debug_opts = DEF_OPTS; 539static int sdebug_opts = DEF_OPTS;
541static int scsi_debug_physblk_exp = DEF_PHYSBLK_EXP; 540static int sdebug_physblk_exp = DEF_PHYSBLK_EXP;
542static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */ 541static int sdebug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */
543static int scsi_debug_scsi_level = DEF_SCSI_LEVEL; 542static int sdebug_scsi_level = DEF_SCSI_LEVEL;
544static int scsi_debug_sector_size = DEF_SECTOR_SIZE; 543static int sdebug_sector_size = DEF_SECTOR_SIZE;
545static int scsi_debug_virtual_gb = DEF_VIRTUAL_GB; 544static int sdebug_virtual_gb = DEF_VIRTUAL_GB;
546static int scsi_debug_vpd_use_hostno = DEF_VPD_USE_HOSTNO; 545static int sdebug_vpd_use_hostno = DEF_VPD_USE_HOSTNO;
547static unsigned int scsi_debug_lbpu = DEF_LBPU; 546static unsigned int sdebug_lbpu = DEF_LBPU;
548static unsigned int scsi_debug_lbpws = DEF_LBPWS; 547static unsigned int sdebug_lbpws = DEF_LBPWS;
549static unsigned int scsi_debug_lbpws10 = DEF_LBPWS10; 548static unsigned int sdebug_lbpws10 = DEF_LBPWS10;
550static unsigned int scsi_debug_lbprz = DEF_LBPRZ; 549static unsigned int sdebug_lbprz = DEF_LBPRZ;
551static unsigned int scsi_debug_unmap_alignment = DEF_UNMAP_ALIGNMENT; 550static unsigned int sdebug_unmap_alignment = DEF_UNMAP_ALIGNMENT;
552static unsigned int scsi_debug_unmap_granularity = DEF_UNMAP_GRANULARITY; 551static unsigned int sdebug_unmap_granularity = DEF_UNMAP_GRANULARITY;
553static unsigned int scsi_debug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; 552static unsigned int sdebug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS;
554static unsigned int scsi_debug_unmap_max_desc = DEF_UNMAP_MAX_DESC; 553static unsigned int sdebug_unmap_max_desc = DEF_UNMAP_MAX_DESC;
555static unsigned int scsi_debug_write_same_length = DEF_WRITESAME_LENGTH; 554static unsigned int sdebug_write_same_length = DEF_WRITESAME_LENGTH;
556static bool scsi_debug_removable = DEF_REMOVABLE; 555static bool sdebug_removable = DEF_REMOVABLE;
557static bool scsi_debug_clustering; 556static bool sdebug_clustering;
558static bool scsi_debug_host_lock = DEF_HOST_LOCK; 557static bool sdebug_host_lock = DEF_HOST_LOCK;
559static bool scsi_debug_strict = DEF_STRICT; 558static bool sdebug_strict = DEF_STRICT;
560static bool sdebug_any_injecting_opt; 559static bool sdebug_any_injecting_opt;
560static bool sdebug_verbose;
561 561
562static atomic_t sdebug_cmnd_count; 562static atomic_t sdebug_cmnd_count;
563static atomic_t sdebug_completions; 563static atomic_t sdebug_completions;
@@ -580,8 +580,8 @@ static int sdebug_sectors_per; /* sectors per cylinder */
580 580
581static unsigned int scsi_debug_lbp(void) 581static unsigned int scsi_debug_lbp(void)
582{ 582{
583 return ((0 == scsi_debug_fake_rw) && 583 return 0 == sdebug_fake_rw &&
584 (scsi_debug_lbpu | scsi_debug_lbpws | scsi_debug_lbpws10)); 584 (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10);
585} 585}
586 586
587struct sdebug_dev_info { 587struct sdebug_dev_info {
@@ -674,7 +674,7 @@ static void *fake_store(unsigned long long lba)
674{ 674{
675 lba = do_div(lba, sdebug_store_sectors); 675 lba = do_div(lba, sdebug_store_sectors);
676 676
677 return fake_storep + lba * scsi_debug_sector_size; 677 return fake_storep + lba * sdebug_sector_size;
678} 678}
679 679
680static struct sd_dif_tuple *dif_store(sector_t sector) 680static struct sd_dif_tuple *dif_store(sector_t sector)
@@ -696,11 +696,11 @@ static void sdebug_max_tgts_luns(void)
696 list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) { 696 list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
697 hpnt = sdbg_host->shost; 697 hpnt = sdbg_host->shost;
698 if ((hpnt->this_id >= 0) && 698 if ((hpnt->this_id >= 0) &&
699 (scsi_debug_num_tgts > hpnt->this_id)) 699 (sdebug_num_tgts > hpnt->this_id))
700 hpnt->max_id = scsi_debug_num_tgts + 1; 700 hpnt->max_id = sdebug_num_tgts + 1;
701 else 701 else
702 hpnt->max_id = scsi_debug_num_tgts; 702 hpnt->max_id = sdebug_num_tgts;
703 /* scsi_debug_max_luns; */ 703 /* sdebug_max_luns; */
704 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; 704 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1;
705 } 705 }
706 spin_unlock(&sdebug_host_list_lock); 706 spin_unlock(&sdebug_host_list_lock);
@@ -725,8 +725,7 @@ mk_sense_invalid_fld(struct scsi_cmnd *scp, enum sdeb_cmd_data c_d,
725 } 725 }
726 asc = c_d ? INVALID_FIELD_IN_CDB : INVALID_FIELD_IN_PARAM_LIST; 726 asc = c_d ? INVALID_FIELD_IN_CDB : INVALID_FIELD_IN_PARAM_LIST;
727 memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE); 727 memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE);
728 scsi_build_sense_buffer(scsi_debug_dsense, sbuff, ILLEGAL_REQUEST, 728 scsi_build_sense_buffer(sdebug_dsense, sbuff, ILLEGAL_REQUEST, asc, 0);
729 asc, 0);
730 memset(sks, 0, sizeof(sks)); 729 memset(sks, 0, sizeof(sks));
731 sks[0] = 0x80; 730 sks[0] = 0x80;
732 if (c_d) 731 if (c_d)
@@ -736,7 +735,7 @@ mk_sense_invalid_fld(struct scsi_cmnd *scp, enum sdeb_cmd_data c_d,
736 sks[0] |= 0x7 & in_bit; 735 sks[0] |= 0x7 & in_bit;
737 } 736 }
738 put_unaligned_be16(in_byte, sks + 1); 737 put_unaligned_be16(in_byte, sks + 1);
739 if (scsi_debug_dsense) { 738 if (sdebug_dsense) {
740 sl = sbuff[7] + 8; 739 sl = sbuff[7] + 8;
741 sbuff[7] = sl; 740 sbuff[7] = sl;
742 sbuff[sl] = 0x2; 741 sbuff[sl] = 0x2;
@@ -744,7 +743,7 @@ mk_sense_invalid_fld(struct scsi_cmnd *scp, enum sdeb_cmd_data c_d,
744 memcpy(sbuff + sl + 4, sks, 3); 743 memcpy(sbuff + sl + 4, sks, 3);
745 } else 744 } else
746 memcpy(sbuff + 15, sks, 3); 745 memcpy(sbuff + 15, sks, 3);
747 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 746 if (sdebug_verbose)
748 sdev_printk(KERN_INFO, scp->device, "%s: [sense_key,asc,ascq" 747 sdev_printk(KERN_INFO, scp->device, "%s: [sense_key,asc,ascq"
749 "]: [0x5,0x%x,0x0] %c byte=%d, bit=%d\n", 748 "]: [0x5,0x%x,0x0] %c byte=%d, bit=%d\n",
750 my_name, asc, c_d ? 'C' : 'D', in_byte, in_bit); 749 my_name, asc, c_d ? 'C' : 'D', in_byte, in_bit);
@@ -762,9 +761,9 @@ static void mk_sense_buffer(struct scsi_cmnd *scp, int key, int asc, int asq)
762 } 761 }
763 memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE); 762 memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE);
764 763
765 scsi_build_sense_buffer(scsi_debug_dsense, sbuff, key, asc, asq); 764 scsi_build_sense_buffer(sdebug_dsense, sbuff, key, asc, asq);
766 765
767 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 766 if (sdebug_verbose)
768 sdev_printk(KERN_INFO, scp->device, 767 sdev_printk(KERN_INFO, scp->device,
769 "%s: [sense_key,asc,ascq]: [0x%x,0x%x,0x%x]\n", 768 "%s: [sense_key,asc,ascq]: [0x%x,0x%x,0x%x]\n",
770 my_name, key, asc, asq); 769 my_name, key, asc, asq);
@@ -778,7 +777,7 @@ mk_sense_invalid_opcode(struct scsi_cmnd *scp)
778 777
779static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) 778static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
780{ 779{
781 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) { 780 if (sdebug_verbose) {
782 if (0x1261 == cmd) 781 if (0x1261 == cmd)
783 sdev_printk(KERN_INFO, dev, 782 sdev_printk(KERN_INFO, dev,
784 "%s: BLKFLSBUF [0x1261]\n", __func__); 783 "%s: BLKFLSBUF [0x1261]\n", __func__);
@@ -814,7 +813,6 @@ static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only,
814 struct sdebug_dev_info * devip) 813 struct sdebug_dev_info * devip)
815{ 814{
816 int k; 815 int k;
817 bool debug = !!(SCSI_DEBUG_OPT_NOISE & scsi_debug_opts);
818 816
819 k = find_first_bit(devip->uas_bm, SDEBUG_NUM_UAS); 817 k = find_first_bit(devip->uas_bm, SDEBUG_NUM_UAS);
820 if (k != SDEBUG_NUM_UAS) { 818 if (k != SDEBUG_NUM_UAS) {
@@ -824,38 +822,38 @@ static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only,
824 case SDEBUG_UA_POR: 822 case SDEBUG_UA_POR:
825 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 823 mk_sense_buffer(SCpnt, UNIT_ATTENTION,
826 UA_RESET_ASC, POWER_ON_RESET_ASCQ); 824 UA_RESET_ASC, POWER_ON_RESET_ASCQ);
827 if (debug) 825 if (sdebug_verbose)
828 cp = "power on reset"; 826 cp = "power on reset";
829 break; 827 break;
830 case SDEBUG_UA_BUS_RESET: 828 case SDEBUG_UA_BUS_RESET:
831 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 829 mk_sense_buffer(SCpnt, UNIT_ATTENTION,
832 UA_RESET_ASC, BUS_RESET_ASCQ); 830 UA_RESET_ASC, BUS_RESET_ASCQ);
833 if (debug) 831 if (sdebug_verbose)
834 cp = "bus reset"; 832 cp = "bus reset";
835 break; 833 break;
836 case SDEBUG_UA_MODE_CHANGED: 834 case SDEBUG_UA_MODE_CHANGED:
837 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 835 mk_sense_buffer(SCpnt, UNIT_ATTENTION,
838 UA_CHANGED_ASC, MODE_CHANGED_ASCQ); 836 UA_CHANGED_ASC, MODE_CHANGED_ASCQ);
839 if (debug) 837 if (sdebug_verbose)
840 cp = "mode parameters changed"; 838 cp = "mode parameters changed";
841 break; 839 break;
842 case SDEBUG_UA_CAPACITY_CHANGED: 840 case SDEBUG_UA_CAPACITY_CHANGED:
843 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 841 mk_sense_buffer(SCpnt, UNIT_ATTENTION,
844 UA_CHANGED_ASC, CAPACITY_CHANGED_ASCQ); 842 UA_CHANGED_ASC, CAPACITY_CHANGED_ASCQ);
845 if (debug) 843 if (sdebug_verbose)
846 cp = "capacity data changed"; 844 cp = "capacity data changed";
847 break; 845 break;
848 case SDEBUG_UA_MICROCODE_CHANGED: 846 case SDEBUG_UA_MICROCODE_CHANGED:
849 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 847 mk_sense_buffer(SCpnt, UNIT_ATTENTION,
850 TARGET_CHANGED_ASC, MICROCODE_CHANGED_ASCQ); 848 TARGET_CHANGED_ASC, MICROCODE_CHANGED_ASCQ);
851 if (debug) 849 if (sdebug_verbose)
852 cp = "microcode has been changed"; 850 cp = "microcode has been changed";
853 break; 851 break;
854 case SDEBUG_UA_MICROCODE_CHANGED_WO_RESET: 852 case SDEBUG_UA_MICROCODE_CHANGED_WO_RESET:
855 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 853 mk_sense_buffer(SCpnt, UNIT_ATTENTION,
856 TARGET_CHANGED_ASC, 854 TARGET_CHANGED_ASC,
857 MICROCODE_CHANGED_WO_RESET_ASCQ); 855 MICROCODE_CHANGED_WO_RESET_ASCQ);
858 if (debug) 856 if (sdebug_verbose)
859 cp = "microcode has been changed without reset"; 857 cp = "microcode has been changed without reset";
860 break; 858 break;
861 case SDEBUG_UA_LUNS_CHANGED: 859 case SDEBUG_UA_LUNS_CHANGED:
@@ -864,26 +862,25 @@ static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only,
864 * ASC/ASCQ REPORTED LUNS DATA HAS CHANGED on every LUN 862 * ASC/ASCQ REPORTED LUNS DATA HAS CHANGED on every LUN
865 * on the target, until a REPORT LUNS command is 863 * on the target, until a REPORT LUNS command is
866 * received. SPC-4 behavior is to report it only once. 864 * received. SPC-4 behavior is to report it only once.
867 * NOTE: scsi_debug_scsi_level does not use the same 865 * NOTE: sdebug_scsi_level does not use the same
868 * values as struct scsi_device->scsi_level. 866 * values as struct scsi_device->scsi_level.
869 */ 867 */
870 if (scsi_debug_scsi_level >= 6) /* SPC-4 and above */ 868 if (sdebug_scsi_level >= 6) /* SPC-4 and above */
871 clear_luns_changed_on_target(devip); 869 clear_luns_changed_on_target(devip);
872 mk_sense_buffer(SCpnt, UNIT_ATTENTION, 870 mk_sense_buffer(SCpnt, UNIT_ATTENTION,
873 TARGET_CHANGED_ASC, 871 TARGET_CHANGED_ASC,
874 LUNS_CHANGED_ASCQ); 872 LUNS_CHANGED_ASCQ);
875 if (debug) 873 if (sdebug_verbose)
876 cp = "reported luns data has changed"; 874 cp = "reported luns data has changed";
877 break; 875 break;
878 default: 876 default:
879 pr_warn("%s: unexpected unit attention code=%d\n", 877 pr_warn("unexpected unit attention code=%d\n", k);
880 __func__, k); 878 if (sdebug_verbose)
881 if (debug)
882 cp = "unknown"; 879 cp = "unknown";
883 break; 880 break;
884 } 881 }
885 clear_bit(k, devip->uas_bm); 882 clear_bit(k, devip->uas_bm);
886 if (debug) 883 if (sdebug_verbose)
887 sdev_printk(KERN_INFO, SCpnt->device, 884 sdev_printk(KERN_INFO, SCpnt->device,
888 "%s reports: Unit attention: %s\n", 885 "%s reports: Unit attention: %s\n",
889 my_name, cp); 886 my_name, cp);
@@ -892,7 +889,7 @@ static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only,
892 if ((UAS_TUR == uas_only) && devip->stopped) { 889 if ((UAS_TUR == uas_only) && devip->stopped) {
893 mk_sense_buffer(SCpnt, NOT_READY, LOGICAL_UNIT_NOT_READY, 890 mk_sense_buffer(SCpnt, NOT_READY, LOGICAL_UNIT_NOT_READY,
894 0x2); 891 0x2);
895 if (debug) 892 if (sdebug_verbose)
896 sdev_printk(KERN_INFO, SCpnt->device, 893 sdev_printk(KERN_INFO, SCpnt->device,
897 "%s reports: Not ready: %s\n", my_name, 894 "%s reports: Not ready: %s\n", my_name,
898 "initializing command required"); 895 "initializing command required");
@@ -911,7 +908,7 @@ static int fill_from_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
911 if (!sdb->length) 908 if (!sdb->length)
912 return 0; 909 return 0;
913 if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_FROM_DEVICE)) 910 if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_FROM_DEVICE))
914 return (DID_ERROR << 16); 911 return DID_ERROR << 16;
915 912
916 act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents, 913 act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents,
917 arr, arr_len); 914 arr, arr_len);
@@ -935,7 +932,10 @@ static int fetch_to_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
935 932
936static const char * inq_vendor_id = "Linux "; 933static const char * inq_vendor_id = "Linux ";
937static const char * inq_product_id = "scsi_debug "; 934static const char * inq_product_id = "scsi_debug ";
938static const char *inq_product_rev = "0184"; /* version less '.' */ 935static const char *inq_product_rev = "0186"; /* version less '.' */
936static const u64 naa5_comp_a = 0x5222222000000000ULL;
937static const u64 naa5_comp_b = 0x5333333000000000ULL;
938static const u64 naa5_comp_c = 0x5111111000000000ULL;
939 939
940/* Device identification VPD page. Returns number of bytes placed in arr */ 940/* Device identification VPD page. Returns number of bytes placed in arr */
941static int inquiry_evpd_83(unsigned char * arr, int port_group_id, 941static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
@@ -963,14 +963,8 @@ static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
963 arr[num++] = 0x3; /* PIV=0, lu, naa */ 963 arr[num++] = 0x3; /* PIV=0, lu, naa */
964 arr[num++] = 0x0; 964 arr[num++] = 0x0;
965 arr[num++] = 0x8; 965 arr[num++] = 0x8;
966 arr[num++] = 0x53; /* naa-5 ieee company id=0x333333 (fake) */ 966 put_unaligned_be64(naa5_comp_b + dev_id_num, arr + num);
967 arr[num++] = 0x33; 967 num += 8;
968 arr[num++] = 0x33;
969 arr[num++] = 0x30;
970 arr[num++] = (dev_id_num >> 24);
971 arr[num++] = (dev_id_num >> 16) & 0xff;
972 arr[num++] = (dev_id_num >> 8) & 0xff;
973 arr[num++] = dev_id_num & 0xff;
974 /* Target relative port number */ 968 /* Target relative port number */
975 arr[num++] = 0x61; /* proto=sas, binary */ 969 arr[num++] = 0x61; /* proto=sas, binary */
976 arr[num++] = 0x94; /* PIV=1, target port, rel port */ 970 arr[num++] = 0x94; /* PIV=1, target port, rel port */
@@ -986,14 +980,8 @@ static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
986 arr[num++] = 0x93; /* piv=1, target port, naa */ 980 arr[num++] = 0x93; /* piv=1, target port, naa */
987 arr[num++] = 0x0; 981 arr[num++] = 0x0;
988 arr[num++] = 0x8; 982 arr[num++] = 0x8;
989 arr[num++] = 0x52; /* naa-5, company id=0x222222 (fake) */ 983 put_unaligned_be64(naa5_comp_a + port_a, arr + num);
990 arr[num++] = 0x22; 984 num += 8;
991 arr[num++] = 0x22;
992 arr[num++] = 0x20;
993 arr[num++] = (port_a >> 24);
994 arr[num++] = (port_a >> 16) & 0xff;
995 arr[num++] = (port_a >> 8) & 0xff;
996 arr[num++] = port_a & 0xff;
997 /* NAA-5, Target port group identifier */ 985 /* NAA-5, Target port group identifier */
998 arr[num++] = 0x61; /* proto=sas, binary */ 986 arr[num++] = 0x61; /* proto=sas, binary */
999 arr[num++] = 0x95; /* piv=1, target port group id */ 987 arr[num++] = 0x95; /* piv=1, target port group id */
@@ -1001,21 +989,15 @@ static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
1001 arr[num++] = 0x4; 989 arr[num++] = 0x4;
1002 arr[num++] = 0; 990 arr[num++] = 0;
1003 arr[num++] = 0; 991 arr[num++] = 0;
1004 arr[num++] = (port_group_id >> 8) & 0xff; 992 put_unaligned_be16(port_group_id, arr + num);
1005 arr[num++] = port_group_id & 0xff; 993 num += 2;
1006 /* NAA-5, Target device identifier */ 994 /* NAA-5, Target device identifier */
1007 arr[num++] = 0x61; /* proto=sas, binary */ 995 arr[num++] = 0x61; /* proto=sas, binary */
1008 arr[num++] = 0xa3; /* piv=1, target device, naa */ 996 arr[num++] = 0xa3; /* piv=1, target device, naa */
1009 arr[num++] = 0x0; 997 arr[num++] = 0x0;
1010 arr[num++] = 0x8; 998 arr[num++] = 0x8;
1011 arr[num++] = 0x52; /* naa-5, company id=0x222222 (fake) */ 999 put_unaligned_be64(naa5_comp_a + target_dev_id, arr + num);
1012 arr[num++] = 0x22; 1000 num += 8;
1013 arr[num++] = 0x22;
1014 arr[num++] = 0x20;
1015 arr[num++] = (target_dev_id >> 24);
1016 arr[num++] = (target_dev_id >> 16) & 0xff;
1017 arr[num++] = (target_dev_id >> 8) & 0xff;
1018 arr[num++] = target_dev_id & 0xff;
1019 /* SCSI name string: Target device identifier */ 1001 /* SCSI name string: Target device identifier */
1020 arr[num++] = 0x63; /* proto=sas, UTF-8 */ 1002 arr[num++] = 0x63; /* proto=sas, UTF-8 */
1021 arr[num++] = 0xa8; /* piv=1, target device, SCSI name string */ 1003 arr[num++] = 0xa8; /* piv=1, target device, SCSI name string */
@@ -1031,7 +1013,6 @@ static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
1031 return num; 1013 return num;
1032} 1014}
1033 1015
1034
1035static unsigned char vpd84_data[] = { 1016static unsigned char vpd84_data[] = {
1036/* from 4th byte */ 0x22,0x22,0x22,0x0,0xbb,0x0, 1017/* from 4th byte */ 0x22,0x22,0x22,0x0,0xbb,0x0,
1037 0x22,0x22,0x22,0x0,0xbb,0x1, 1018 0x22,0x22,0x22,0x0,0xbb,0x1,
@@ -1101,15 +1082,8 @@ static int inquiry_evpd_88(unsigned char * arr, int target_dev_id)
1101 arr[num++] = 0x93; /* PIV=1, target port, NAA */ 1082 arr[num++] = 0x93; /* PIV=1, target port, NAA */
1102 arr[num++] = 0x0; /* reserved */ 1083 arr[num++] = 0x0; /* reserved */
1103 arr[num++] = 0x8; /* length */ 1084 arr[num++] = 0x8; /* length */
1104 arr[num++] = 0x52; /* NAA-5, company_id=0x222222 (fake) */ 1085 put_unaligned_be64(naa5_comp_a + port_a, arr + num);
1105 arr[num++] = 0x22; 1086 num += 8;
1106 arr[num++] = 0x22;
1107 arr[num++] = 0x20;
1108 arr[num++] = (port_a >> 24);
1109 arr[num++] = (port_a >> 16) & 0xff;
1110 arr[num++] = (port_a >> 8) & 0xff;
1111 arr[num++] = port_a & 0xff;
1112
1113 arr[num++] = 0x0; /* reserved */ 1087 arr[num++] = 0x0; /* reserved */
1114 arr[num++] = 0x0; /* reserved */ 1088 arr[num++] = 0x0; /* reserved */
1115 arr[num++] = 0x0; 1089 arr[num++] = 0x0;
@@ -1123,14 +1097,8 @@ static int inquiry_evpd_88(unsigned char * arr, int target_dev_id)
1123 arr[num++] = 0x93; /* PIV=1, target port, NAA */ 1097 arr[num++] = 0x93; /* PIV=1, target port, NAA */
1124 arr[num++] = 0x0; /* reserved */ 1098 arr[num++] = 0x0; /* reserved */
1125 arr[num++] = 0x8; /* length */ 1099 arr[num++] = 0x8; /* length */
1126 arr[num++] = 0x52; /* NAA-5, company_id=0x222222 (fake) */ 1100 put_unaligned_be64(naa5_comp_a + port_b, arr + num);
1127 arr[num++] = 0x22; 1101 num += 8;
1128 arr[num++] = 0x22;
1129 arr[num++] = 0x20;
1130 arr[num++] = (port_b >> 24);
1131 arr[num++] = (port_b >> 16) & 0xff;
1132 arr[num++] = (port_b >> 8) & 0xff;
1133 arr[num++] = port_b & 0xff;
1134 1102
1135 return num; 1103 return num;
1136} 1104}
@@ -1203,40 +1171,35 @@ static int inquiry_evpd_b0(unsigned char * arr)
1203 memcpy(arr, vpdb0_data, sizeof(vpdb0_data)); 1171 memcpy(arr, vpdb0_data, sizeof(vpdb0_data));
1204 1172
1205 /* Optimal transfer length granularity */ 1173 /* Optimal transfer length granularity */
1206 gran = 1 << scsi_debug_physblk_exp; 1174 gran = 1 << sdebug_physblk_exp;
1207 arr[2] = (gran >> 8) & 0xff; 1175 put_unaligned_be16(gran, arr + 2);
1208 arr[3] = gran & 0xff;
1209 1176
1210 /* Maximum Transfer Length */ 1177 /* Maximum Transfer Length */
1211 if (sdebug_store_sectors > 0x400) { 1178 if (sdebug_store_sectors > 0x400)
1212 arr[4] = (sdebug_store_sectors >> 24) & 0xff; 1179 put_unaligned_be32(sdebug_store_sectors, arr + 4);
1213 arr[5] = (sdebug_store_sectors >> 16) & 0xff;
1214 arr[6] = (sdebug_store_sectors >> 8) & 0xff;
1215 arr[7] = sdebug_store_sectors & 0xff;
1216 }
1217 1180
1218 /* Optimal Transfer Length */ 1181 /* Optimal Transfer Length */
1219 put_unaligned_be32(scsi_debug_opt_blks, &arr[8]); 1182 put_unaligned_be32(sdebug_opt_blks, &arr[8]);
1220 1183
1221 if (scsi_debug_lbpu) { 1184 if (sdebug_lbpu) {
1222 /* Maximum Unmap LBA Count */ 1185 /* Maximum Unmap LBA Count */
1223 put_unaligned_be32(scsi_debug_unmap_max_blocks, &arr[16]); 1186 put_unaligned_be32(sdebug_unmap_max_blocks, &arr[16]);
1224 1187
1225 /* Maximum Unmap Block Descriptor Count */ 1188 /* Maximum Unmap Block Descriptor Count */
1226 put_unaligned_be32(scsi_debug_unmap_max_desc, &arr[20]); 1189 put_unaligned_be32(sdebug_unmap_max_desc, &arr[20]);
1227 } 1190 }
1228 1191
1229 /* Unmap Granularity Alignment */ 1192 /* Unmap Granularity Alignment */
1230 if (scsi_debug_unmap_alignment) { 1193 if (sdebug_unmap_alignment) {
1231 put_unaligned_be32(scsi_debug_unmap_alignment, &arr[28]); 1194 put_unaligned_be32(sdebug_unmap_alignment, &arr[28]);
1232 arr[28] |= 0x80; /* UGAVALID */ 1195 arr[28] |= 0x80; /* UGAVALID */
1233 } 1196 }
1234 1197
1235 /* Optimal Unmap Granularity */ 1198 /* Optimal Unmap Granularity */
1236 put_unaligned_be32(scsi_debug_unmap_granularity, &arr[24]); 1199 put_unaligned_be32(sdebug_unmap_granularity, &arr[24]);
1237 1200
1238 /* Maximum WRITE SAME Length */ 1201 /* Maximum WRITE SAME Length */
1239 put_unaligned_be64(scsi_debug_write_same_length, &arr[32]); 1202 put_unaligned_be64(sdebug_write_same_length, &arr[32]);
1240 1203
1241 return 0x3c; /* Mandatory page length for Logical Block Provisioning */ 1204 return 0x3c; /* Mandatory page length for Logical Block Provisioning */
1242 1205
@@ -1261,16 +1224,16 @@ static int inquiry_evpd_b2(unsigned char *arr)
1261 memset(arr, 0, 0x4); 1224 memset(arr, 0, 0x4);
1262 arr[0] = 0; /* threshold exponent */ 1225 arr[0] = 0; /* threshold exponent */
1263 1226
1264 if (scsi_debug_lbpu) 1227 if (sdebug_lbpu)
1265 arr[1] = 1 << 7; 1228 arr[1] = 1 << 7;
1266 1229
1267 if (scsi_debug_lbpws) 1230 if (sdebug_lbpws)
1268 arr[1] |= 1 << 6; 1231 arr[1] |= 1 << 6;
1269 1232
1270 if (scsi_debug_lbpws10) 1233 if (sdebug_lbpws10)
1271 arr[1] |= 1 << 5; 1234 arr[1] |= 1 << 5;
1272 1235
1273 if (scsi_debug_lbprz) 1236 if (sdebug_lbprz)
1274 arr[1] |= 1 << 2; 1237 arr[1] |= 1 << 2;
1275 1238
1276 return 0x4; 1239 return 0x4;
@@ -1287,17 +1250,17 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1287 int alloc_len, n, ret; 1250 int alloc_len, n, ret;
1288 bool have_wlun; 1251 bool have_wlun;
1289 1252
1290 alloc_len = (cmd[3] << 8) + cmd[4]; 1253 alloc_len = get_unaligned_be16(cmd + 3);
1291 arr = kzalloc(SDEBUG_MAX_INQ_ARR_SZ, GFP_ATOMIC); 1254 arr = kzalloc(SDEBUG_MAX_INQ_ARR_SZ, GFP_ATOMIC);
1292 if (! arr) 1255 if (! arr)
1293 return DID_REQUEUE << 16; 1256 return DID_REQUEUE << 16;
1294 have_wlun = (scp->device->lun == SCSI_W_LUN_REPORT_LUNS); 1257 have_wlun = (scp->device->lun == SCSI_W_LUN_REPORT_LUNS);
1295 if (have_wlun) 1258 if (have_wlun)
1296 pq_pdt = 0x1e; /* present, wlun */ 1259 pq_pdt = 0x1e; /* present, wlun */
1297 else if (scsi_debug_no_lun_0 && (0 == devip->lun)) 1260 else if (sdebug_no_lun_0 && (0 == devip->lun))
1298 pq_pdt = 0x7f; /* not present, no device type */ 1261 pq_pdt = 0x7f; /* not present, no device type */
1299 else 1262 else
1300 pq_pdt = (scsi_debug_ptype & 0x1f); 1263 pq_pdt = (sdebug_ptype & 0x1f);
1301 arr[0] = pq_pdt; 1264 arr[0] = pq_pdt;
1302 if (0x2 & cmd[1]) { /* CMDDT bit set */ 1265 if (0x2 & cmd[1]) { /* CMDDT bit set */
1303 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 1); 1266 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 1);
@@ -1310,7 +1273,7 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1310 1273
1311 port_group_id = (((host_no + 1) & 0x7f) << 8) + 1274 port_group_id = (((host_no + 1) & 0x7f) << 8) +
1312 (devip->channel & 0x7f); 1275 (devip->channel & 0x7f);
1313 if (0 == scsi_debug_vpd_use_hostno) 1276 if (0 == sdebug_vpd_use_hostno)
1314 host_no = 0; 1277 host_no = 0;
1315 lu_id_num = have_wlun ? -1 : (((host_no + 1) * 2000) + 1278 lu_id_num = have_wlun ? -1 : (((host_no + 1) * 2000) +
1316 (devip->target * 1000) + devip->lun); 1279 (devip->target * 1000) + devip->lun);
@@ -1352,9 +1315,9 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1352 } else if (0x86 == cmd[2]) { /* extended inquiry */ 1315 } else if (0x86 == cmd[2]) { /* extended inquiry */
1353 arr[1] = cmd[2]; /*sanity */ 1316 arr[1] = cmd[2]; /*sanity */
1354 arr[3] = 0x3c; /* number of following entries */ 1317 arr[3] = 0x3c; /* number of following entries */
1355 if (scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) 1318 if (sdebug_dif == SD_DIF_TYPE3_PROTECTION)
1356 arr[4] = 0x4; /* SPT: GRD_CHK:1 */ 1319 arr[4] = 0x4; /* SPT: GRD_CHK:1 */
1357 else if (scsi_debug_dif) 1320 else if (sdebug_dif)
1358 arr[4] = 0x5; /* SPT: GRD_CHK:1, REF_CHK:1 */ 1321 arr[4] = 0x5; /* SPT: GRD_CHK:1, REF_CHK:1 */
1359 else 1322 else
1360 arr[4] = 0x0; /* no protection stuff */ 1323 arr[4] = 0x0; /* no protection stuff */
@@ -1372,8 +1335,7 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1372 } else if (0x89 == cmd[2]) { /* ATA information */ 1335 } else if (0x89 == cmd[2]) { /* ATA information */
1373 arr[1] = cmd[2]; /*sanity */ 1336 arr[1] = cmd[2]; /*sanity */
1374 n = inquiry_evpd_89(&arr[4]); 1337 n = inquiry_evpd_89(&arr[4]);
1375 arr[2] = (n >> 8); 1338 put_unaligned_be16(n, arr + 2);
1376 arr[3] = (n & 0xff);
1377 } else if (0xb0 == cmd[2]) { /* Block limits (SBC) */ 1339 } else if (0xb0 == cmd[2]) { /* Block limits (SBC) */
1378 arr[1] = cmd[2]; /*sanity */ 1340 arr[1] = cmd[2]; /*sanity */
1379 arr[3] = inquiry_evpd_b0(&arr[4]); 1341 arr[3] = inquiry_evpd_b0(&arr[4]);
@@ -1388,19 +1350,19 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1388 kfree(arr); 1350 kfree(arr);
1389 return check_condition_result; 1351 return check_condition_result;
1390 } 1352 }
1391 len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len); 1353 len = min(get_unaligned_be16(arr + 2) + 4, alloc_len);
1392 ret = fill_from_dev_buffer(scp, arr, 1354 ret = fill_from_dev_buffer(scp, arr,
1393 min(len, SDEBUG_MAX_INQ_ARR_SZ)); 1355 min(len, SDEBUG_MAX_INQ_ARR_SZ));
1394 kfree(arr); 1356 kfree(arr);
1395 return ret; 1357 return ret;
1396 } 1358 }
1397 /* drops through here for a standard inquiry */ 1359 /* drops through here for a standard inquiry */
1398 arr[1] = scsi_debug_removable ? 0x80 : 0; /* Removable disk */ 1360 arr[1] = sdebug_removable ? 0x80 : 0; /* Removable disk */
1399 arr[2] = scsi_debug_scsi_level; 1361 arr[2] = sdebug_scsi_level;
1400 arr[3] = 2; /* response_data_format==2 */ 1362 arr[3] = 2; /* response_data_format==2 */
1401 arr[4] = SDEBUG_LONG_INQ_SZ - 5; 1363 arr[4] = SDEBUG_LONG_INQ_SZ - 5;
1402 arr[5] = scsi_debug_dif ? 1 : 0; /* PROTECT bit */ 1364 arr[5] = sdebug_dif ? 1 : 0; /* PROTECT bit */
1403 if (0 == scsi_debug_vpd_use_hostno) 1365 if (0 == sdebug_vpd_use_hostno)
1404 arr[5] = 0x10; /* claim: implicit TGPS */ 1366 arr[5] = 0x10; /* claim: implicit TGPS */
1405 arr[6] = 0x10; /* claim: MultiP */ 1367 arr[6] = 0x10; /* claim: MultiP */
1406 /* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */ 1368 /* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */
@@ -1412,9 +1374,9 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1412 arr[58] = 0x0; arr[59] = 0xa2; /* SAM-5 rev 4 */ 1374 arr[58] = 0x0; arr[59] = 0xa2; /* SAM-5 rev 4 */
1413 arr[60] = 0x4; arr[61] = 0x68; /* SPC-4 rev 37 */ 1375 arr[60] = 0x4; arr[61] = 0x68; /* SPC-4 rev 37 */
1414 n = 62; 1376 n = 62;
1415 if (scsi_debug_ptype == 0) { 1377 if (sdebug_ptype == 0) {
1416 arr[n++] = 0x4; arr[n++] = 0xc5; /* SBC-4 rev 36 */ 1378 arr[n++] = 0x4; arr[n++] = 0xc5; /* SBC-4 rev 36 */
1417 } else if (scsi_debug_ptype == 1) { 1379 } else if (sdebug_ptype == 1) {
1418 arr[n++] = 0x5; arr[n++] = 0x25; /* SSC-4 rev 3 */ 1380 arr[n++] = 0x5; arr[n++] = 0x25; /* SSC-4 rev 3 */
1419 } 1381 }
1420 arr[n++] = 0x20; arr[n++] = 0xe6; /* SPL-3 rev 7 */ 1382 arr[n++] = 0x20; arr[n++] = 0xe6; /* SPL-3 rev 7 */
@@ -1452,7 +1414,7 @@ static int resp_requests(struct scsi_cmnd * scp,
1452 } 1414 }
1453 } else { 1415 } else {
1454 memcpy(arr, sbuff, SCSI_SENSE_BUFFERSIZE); 1416 memcpy(arr, sbuff, SCSI_SENSE_BUFFERSIZE);
1455 if (arr[0] >= 0x70 && dsense == scsi_debug_dsense) 1417 if (arr[0] >= 0x70 && dsense == sdebug_dsense)
1456 ; /* have sense and formats match */ 1418 ; /* have sense and formats match */
1457 else if (arr[0] <= 0x70) { 1419 else if (arr[0] <= 0x70) {
1458 if (dsense) { 1420 if (dsense) {
@@ -1504,9 +1466,11 @@ static int resp_start_stop(struct scsi_cmnd * scp,
1504 1466
1505static sector_t get_sdebug_capacity(void) 1467static sector_t get_sdebug_capacity(void)
1506{ 1468{
1507 if (scsi_debug_virtual_gb > 0) 1469 static const unsigned int gibibyte = 1073741824;
1508 return (sector_t)scsi_debug_virtual_gb * 1470
1509 (1073741824 / scsi_debug_sector_size); 1471 if (sdebug_virtual_gb > 0)
1472 return (sector_t)sdebug_virtual_gb *
1473 (gibibyte / sdebug_sector_size);
1510 else 1474 else
1511 return sdebug_store_sectors; 1475 return sdebug_store_sectors;
1512} 1476}
@@ -1523,18 +1487,10 @@ static int resp_readcap(struct scsi_cmnd * scp,
1523 memset(arr, 0, SDEBUG_READCAP_ARR_SZ); 1487 memset(arr, 0, SDEBUG_READCAP_ARR_SZ);
1524 if (sdebug_capacity < 0xffffffff) { 1488 if (sdebug_capacity < 0xffffffff) {
1525 capac = (unsigned int)sdebug_capacity - 1; 1489 capac = (unsigned int)sdebug_capacity - 1;
1526 arr[0] = (capac >> 24); 1490 put_unaligned_be32(capac, arr + 0);
1527 arr[1] = (capac >> 16) & 0xff; 1491 } else
1528 arr[2] = (capac >> 8) & 0xff; 1492 put_unaligned_be32(0xffffffff, arr + 0);
1529 arr[3] = capac & 0xff; 1493 put_unaligned_be16(sdebug_sector_size, arr + 6);
1530 } else {
1531 arr[0] = 0xff;
1532 arr[1] = 0xff;
1533 arr[2] = 0xff;
1534 arr[3] = 0xff;
1535 }
1536 arr[6] = (scsi_debug_sector_size >> 8) & 0xff;
1537 arr[7] = scsi_debug_sector_size & 0xff;
1538 return fill_from_dev_buffer(scp, arr, SDEBUG_READCAP_ARR_SZ); 1494 return fill_from_dev_buffer(scp, arr, SDEBUG_READCAP_ARR_SZ);
1539} 1495}
1540 1496
@@ -1544,34 +1500,27 @@ static int resp_readcap16(struct scsi_cmnd * scp,
1544{ 1500{
1545 unsigned char *cmd = scp->cmnd; 1501 unsigned char *cmd = scp->cmnd;
1546 unsigned char arr[SDEBUG_READCAP16_ARR_SZ]; 1502 unsigned char arr[SDEBUG_READCAP16_ARR_SZ];
1547 unsigned long long capac; 1503 int alloc_len;
1548 int k, alloc_len;
1549 1504
1550 alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8) 1505 alloc_len = get_unaligned_be32(cmd + 10);
1551 + cmd[13]);
1552 /* following just in case virtual_gb changed */ 1506 /* following just in case virtual_gb changed */
1553 sdebug_capacity = get_sdebug_capacity(); 1507 sdebug_capacity = get_sdebug_capacity();
1554 memset(arr, 0, SDEBUG_READCAP16_ARR_SZ); 1508 memset(arr, 0, SDEBUG_READCAP16_ARR_SZ);
1555 capac = sdebug_capacity - 1; 1509 put_unaligned_be64((u64)(sdebug_capacity - 1), arr + 0);
1556 for (k = 0; k < 8; ++k, capac >>= 8) 1510 put_unaligned_be32(sdebug_sector_size, arr + 8);
1557 arr[7 - k] = capac & 0xff; 1511 arr[13] = sdebug_physblk_exp & 0xf;
1558 arr[8] = (scsi_debug_sector_size >> 24) & 0xff; 1512 arr[14] = (sdebug_lowest_aligned >> 8) & 0x3f;
1559 arr[9] = (scsi_debug_sector_size >> 16) & 0xff;
1560 arr[10] = (scsi_debug_sector_size >> 8) & 0xff;
1561 arr[11] = scsi_debug_sector_size & 0xff;
1562 arr[13] = scsi_debug_physblk_exp & 0xf;
1563 arr[14] = (scsi_debug_lowest_aligned >> 8) & 0x3f;
1564 1513
1565 if (scsi_debug_lbp()) { 1514 if (scsi_debug_lbp()) {
1566 arr[14] |= 0x80; /* LBPME */ 1515 arr[14] |= 0x80; /* LBPME */
1567 if (scsi_debug_lbprz) 1516 if (sdebug_lbprz)
1568 arr[14] |= 0x40; /* LBPRZ */ 1517 arr[14] |= 0x40; /* LBPRZ */
1569 } 1518 }
1570 1519
1571 arr[15] = scsi_debug_lowest_aligned & 0xff; 1520 arr[15] = sdebug_lowest_aligned & 0xff;
1572 1521
1573 if (scsi_debug_dif) { 1522 if (sdebug_dif) {
1574 arr[12] = (scsi_debug_dif - 1) << 1; /* P_TYPE */ 1523 arr[12] = (sdebug_dif - 1) << 1; /* P_TYPE */
1575 arr[12] |= 1; /* PROT_EN */ 1524 arr[12] |= 1; /* PROT_EN */
1576 } 1525 }
1577 1526
@@ -1590,9 +1539,7 @@ static int resp_report_tgtpgs(struct scsi_cmnd * scp,
1590 int n, ret, alen, rlen; 1539 int n, ret, alen, rlen;
1591 int port_group_a, port_group_b, port_a, port_b; 1540 int port_group_a, port_group_b, port_a, port_b;
1592 1541
1593 alen = ((cmd[6] << 24) + (cmd[7] << 16) + (cmd[8] << 8) 1542 alen = get_unaligned_be32(cmd + 6);
1594 + cmd[9]);
1595
1596 arr = kzalloc(SDEBUG_MAX_TGTPGS_ARR_SZ, GFP_ATOMIC); 1543 arr = kzalloc(SDEBUG_MAX_TGTPGS_ARR_SZ, GFP_ATOMIC);
1597 if (! arr) 1544 if (! arr)
1598 return DID_REQUEUE << 16; 1545 return DID_REQUEUE << 16;
@@ -1605,49 +1552,46 @@ static int resp_report_tgtpgs(struct scsi_cmnd * scp,
1605 port_a = 0x1; /* relative port A */ 1552 port_a = 0x1; /* relative port A */
1606 port_b = 0x2; /* relative port B */ 1553 port_b = 0x2; /* relative port B */
1607 port_group_a = (((host_no + 1) & 0x7f) << 8) + 1554 port_group_a = (((host_no + 1) & 0x7f) << 8) +
1608 (devip->channel & 0x7f); 1555 (devip->channel & 0x7f);
1609 port_group_b = (((host_no + 1) & 0x7f) << 8) + 1556 port_group_b = (((host_no + 1) & 0x7f) << 8) +
1610 (devip->channel & 0x7f) + 0x80; 1557 (devip->channel & 0x7f) + 0x80;
1611 1558
1612 /* 1559 /*
1613 * The asymmetric access state is cycled according to the host_id. 1560 * The asymmetric access state is cycled according to the host_id.
1614 */ 1561 */
1615 n = 4; 1562 n = 4;
1616 if (0 == scsi_debug_vpd_use_hostno) { 1563 if (0 == sdebug_vpd_use_hostno) {
1617 arr[n++] = host_no % 3; /* Asymm access state */ 1564 arr[n++] = host_no % 3; /* Asymm access state */
1618 arr[n++] = 0x0F; /* claim: all states are supported */ 1565 arr[n++] = 0x0F; /* claim: all states are supported */
1619 } else { 1566 } else {
1620 arr[n++] = 0x0; /* Active/Optimized path */ 1567 arr[n++] = 0x0; /* Active/Optimized path */
1621 arr[n++] = 0x01; /* claim: only support active/optimized paths */ 1568 arr[n++] = 0x01; /* only support active/optimized paths */
1622 } 1569 }
1623 arr[n++] = (port_group_a >> 8) & 0xff; 1570 put_unaligned_be16(port_group_a, arr + n);
1624 arr[n++] = port_group_a & 0xff; 1571 n += 2;
1625 arr[n++] = 0; /* Reserved */ 1572 arr[n++] = 0; /* Reserved */
1626 arr[n++] = 0; /* Status code */ 1573 arr[n++] = 0; /* Status code */
1627 arr[n++] = 0; /* Vendor unique */ 1574 arr[n++] = 0; /* Vendor unique */
1628 arr[n++] = 0x1; /* One port per group */ 1575 arr[n++] = 0x1; /* One port per group */
1629 arr[n++] = 0; /* Reserved */ 1576 arr[n++] = 0; /* Reserved */
1630 arr[n++] = 0; /* Reserved */ 1577 arr[n++] = 0; /* Reserved */
1631 arr[n++] = (port_a >> 8) & 0xff; 1578 put_unaligned_be16(port_a, arr + n);
1632 arr[n++] = port_a & 0xff; 1579 n += 2;
1633 arr[n++] = 3; /* Port unavailable */ 1580 arr[n++] = 3; /* Port unavailable */
1634 arr[n++] = 0x08; /* claim: only unavailalbe paths are supported */ 1581 arr[n++] = 0x08; /* claim: only unavailalbe paths are supported */
1635 arr[n++] = (port_group_b >> 8) & 0xff; 1582 put_unaligned_be16(port_group_b, arr + n);
1636 arr[n++] = port_group_b & 0xff; 1583 n += 2;
1637 arr[n++] = 0; /* Reserved */ 1584 arr[n++] = 0; /* Reserved */
1638 arr[n++] = 0; /* Status code */ 1585 arr[n++] = 0; /* Status code */
1639 arr[n++] = 0; /* Vendor unique */ 1586 arr[n++] = 0; /* Vendor unique */
1640 arr[n++] = 0x1; /* One port per group */ 1587 arr[n++] = 0x1; /* One port per group */
1641 arr[n++] = 0; /* Reserved */ 1588 arr[n++] = 0; /* Reserved */
1642 arr[n++] = 0; /* Reserved */ 1589 arr[n++] = 0; /* Reserved */
1643 arr[n++] = (port_b >> 8) & 0xff; 1590 put_unaligned_be16(port_b, arr + n);
1644 arr[n++] = port_b & 0xff; 1591 n += 2;
1645 1592
1646 rlen = n - 4; 1593 rlen = n - 4;
1647 arr[0] = (rlen >> 24) & 0xff; 1594 put_unaligned_be32(rlen, arr + 0);
1648 arr[1] = (rlen >> 16) & 0xff;
1649 arr[2] = (rlen >> 8) & 0xff;
1650 arr[3] = rlen & 0xff;
1651 1595
1652 /* 1596 /*
1653 * Return the smallest value of either 1597 * Return the smallest value of either
@@ -1871,11 +1815,9 @@ static int resp_format_pg(unsigned char * p, int pcontrol, int target)
1871 0, 0, 0, 0, 0x40, 0, 0, 0}; 1815 0, 0, 0, 0, 0x40, 0, 0, 0};
1872 1816
1873 memcpy(p, format_pg, sizeof(format_pg)); 1817 memcpy(p, format_pg, sizeof(format_pg));
1874 p[10] = (sdebug_sectors_per >> 8) & 0xff; 1818 put_unaligned_be16(sdebug_sectors_per, p + 10);
1875 p[11] = sdebug_sectors_per & 0xff; 1819 put_unaligned_be16(sdebug_sector_size, p + 12);
1876 p[12] = (scsi_debug_sector_size >> 8) & 0xff; 1820 if (sdebug_removable)
1877 p[13] = scsi_debug_sector_size & 0xff;
1878 if (scsi_debug_removable)
1879 p[20] |= 0x20; /* should agree with INQUIRY */ 1821 p[20] |= 0x20; /* should agree with INQUIRY */
1880 if (1 == pcontrol) 1822 if (1 == pcontrol)
1881 memset(p + 2, 0, sizeof(format_pg) - 2); 1823 memset(p + 2, 0, sizeof(format_pg) - 2);
@@ -1889,7 +1831,7 @@ static int resp_caching_pg(unsigned char * p, int pcontrol, int target)
1889 unsigned char d_caching_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0, 1831 unsigned char d_caching_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0,
1890 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0}; 1832 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0};
1891 1833
1892 if (SCSI_DEBUG_OPT_N_WCE & scsi_debug_opts) 1834 if (SDEBUG_OPT_N_WCE & sdebug_opts)
1893 caching_pg[2] &= ~0x4; /* set WCE=0 (default WCE=1) */ 1835 caching_pg[2] &= ~0x4; /* set WCE=0 (default WCE=1) */
1894 memcpy(p, caching_pg, sizeof(caching_pg)); 1836 memcpy(p, caching_pg, sizeof(caching_pg));
1895 if (1 == pcontrol) 1837 if (1 == pcontrol)
@@ -1906,12 +1848,12 @@ static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target)
1906 unsigned char d_ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, 1848 unsigned char d_ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0,
1907 0, 0, 0x2, 0x4b}; 1849 0, 0, 0x2, 0x4b};
1908 1850
1909 if (scsi_debug_dsense) 1851 if (sdebug_dsense)
1910 ctrl_m_pg[2] |= 0x4; 1852 ctrl_m_pg[2] |= 0x4;
1911 else 1853 else
1912 ctrl_m_pg[2] &= ~0x4; 1854 ctrl_m_pg[2] &= ~0x4;
1913 1855
1914 if (scsi_debug_ato) 1856 if (sdebug_ato)
1915 ctrl_m_pg[5] |= 0x80; /* ATO=1 */ 1857 ctrl_m_pg[5] |= 0x80; /* ATO=1 */
1916 1858
1917 memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg)); 1859 memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg));
@@ -1955,31 +1897,29 @@ static int resp_sas_pcd_m_spg(unsigned char * p, int pcontrol, int target,
1955{ /* SAS phy control and discover mode page for mode_sense */ 1897{ /* SAS phy control and discover mode page for mode_sense */
1956 unsigned char sas_pcd_m_pg[] = {0x59, 0x1, 0, 0x64, 0, 0x6, 0, 2, 1898 unsigned char sas_pcd_m_pg[] = {0x59, 0x1, 0, 0x64, 0, 0x6, 0, 2,
1957 0, 0, 0, 0, 0x10, 0x9, 0x8, 0x0, 1899 0, 0, 0, 0, 0x10, 0x9, 0x8, 0x0,
1958 0x52, 0x22, 0x22, 0x20, 0x0, 0x0, 0x0, 0x0, 1900 0, 0, 0, 0, 0, 0, 0, 0, /* insert SAS addr */
1959 0x51, 0x11, 0x11, 0x10, 0x0, 0x0, 0x0, 0x1, 1901 0, 0, 0, 0, 0, 0, 0, 0, /* insert SAS addr */
1960 0x2, 0, 0, 0, 0, 0, 0, 0, 1902 0x2, 0, 0, 0, 0, 0, 0, 0,
1961 0x88, 0x99, 0, 0, 0, 0, 0, 0, 1903 0x88, 0x99, 0, 0, 0, 0, 0, 0,
1962 0, 0, 0, 0, 0, 0, 0, 0, 1904 0, 0, 0, 0, 0, 0, 0, 0,
1963 0, 1, 0, 0, 0x10, 0x9, 0x8, 0x0, 1905 0, 1, 0, 0, 0x10, 0x9, 0x8, 0x0,
1964 0x52, 0x22, 0x22, 0x20, 0x0, 0x0, 0x0, 0x0, 1906 0, 0, 0, 0, 0, 0, 0, 0, /* insert SAS addr */
1965 0x51, 0x11, 0x11, 0x10, 0x0, 0x0, 0x0, 0x1, 1907 0, 0, 0, 0, 0, 0, 0, 0, /* insert SAS addr */
1966 0x3, 0, 0, 0, 0, 0, 0, 0, 1908 0x3, 0, 0, 0, 0, 0, 0, 0,
1967 0x88, 0x99, 0, 0, 0, 0, 0, 0, 1909 0x88, 0x99, 0, 0, 0, 0, 0, 0,
1968 0, 0, 0, 0, 0, 0, 0, 0, 1910 0, 0, 0, 0, 0, 0, 0, 0,
1969 }; 1911 };
1970 int port_a, port_b; 1912 int port_a, port_b;
1971 1913
1914 put_unaligned_be64(naa5_comp_a, sas_pcd_m_pg + 16);
1915 put_unaligned_be64(naa5_comp_c + 1, sas_pcd_m_pg + 24);
1916 put_unaligned_be64(naa5_comp_a, sas_pcd_m_pg + 64);
1917 put_unaligned_be64(naa5_comp_c + 1, sas_pcd_m_pg + 72);
1972 port_a = target_dev_id + 1; 1918 port_a = target_dev_id + 1;
1973 port_b = port_a + 1; 1919 port_b = port_a + 1;
1974 memcpy(p, sas_pcd_m_pg, sizeof(sas_pcd_m_pg)); 1920 memcpy(p, sas_pcd_m_pg, sizeof(sas_pcd_m_pg));
1975 p[20] = (port_a >> 24); 1921 put_unaligned_be32(port_a, p + 20);
1976 p[21] = (port_a >> 16) & 0xff; 1922 put_unaligned_be32(port_b, p + 48 + 20);
1977 p[22] = (port_a >> 8) & 0xff;
1978 p[23] = port_a & 0xff;
1979 p[48 + 20] = (port_b >> 24);
1980 p[48 + 21] = (port_b >> 16) & 0xff;
1981 p[48 + 22] = (port_b >> 8) & 0xff;
1982 p[48 + 23] = port_b & 0xff;
1983 if (1 == pcontrol) 1923 if (1 == pcontrol)
1984 memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4); 1924 memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4);
1985 return sizeof(sas_pcd_m_pg); 1925 return sizeof(sas_pcd_m_pg);
@@ -2005,7 +1945,7 @@ resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2005 unsigned char dbd, llbaa; 1945 unsigned char dbd, llbaa;
2006 int pcontrol, pcode, subpcode, bd_len; 1946 int pcontrol, pcode, subpcode, bd_len;
2007 unsigned char dev_spec; 1947 unsigned char dev_spec;
2008 int k, alloc_len, msense_6, offset, len, target_dev_id; 1948 int alloc_len, msense_6, offset, len, target_dev_id;
2009 int target = scp->device->id; 1949 int target = scp->device->id;
2010 unsigned char * ap; 1950 unsigned char * ap;
2011 unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; 1951 unsigned char arr[SDEBUG_MAX_MSENSE_SZ];
@@ -2017,11 +1957,11 @@ resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2017 subpcode = cmd[3]; 1957 subpcode = cmd[3];
2018 msense_6 = (MODE_SENSE == cmd[0]); 1958 msense_6 = (MODE_SENSE == cmd[0]);
2019 llbaa = msense_6 ? 0 : !!(cmd[1] & 0x10); 1959 llbaa = msense_6 ? 0 : !!(cmd[1] & 0x10);
2020 if ((0 == scsi_debug_ptype) && (0 == dbd)) 1960 if ((0 == sdebug_ptype) && (0 == dbd))
2021 bd_len = llbaa ? 16 : 8; 1961 bd_len = llbaa ? 16 : 8;
2022 else 1962 else
2023 bd_len = 0; 1963 bd_len = 0;
2024 alloc_len = msense_6 ? cmd[4] : ((cmd[7] << 8) | cmd[8]); 1964 alloc_len = msense_6 ? cmd[4] : get_unaligned_be16(cmd + 7);
2025 memset(arr, 0, SDEBUG_MAX_MSENSE_SZ); 1965 memset(arr, 0, SDEBUG_MAX_MSENSE_SZ);
2026 if (0x3 == pcontrol) { /* Saving values not supported */ 1966 if (0x3 == pcontrol) { /* Saving values not supported */
2027 mk_sense_buffer(scp, ILLEGAL_REQUEST, SAVING_PARAMS_UNSUP, 0); 1967 mk_sense_buffer(scp, ILLEGAL_REQUEST, SAVING_PARAMS_UNSUP, 0);
@@ -2030,7 +1970,7 @@ resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2030 target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) + 1970 target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) +
2031 (devip->target * 1000) - 3; 1971 (devip->target * 1000) - 3;
2032 /* set DPOFUA bit for disks */ 1972 /* set DPOFUA bit for disks */
2033 if (0 == scsi_debug_ptype) 1973 if (0 == sdebug_ptype)
2034 dev_spec = (DEV_READONLY(target) ? 0x80 : 0x0) | 0x10; 1974 dev_spec = (DEV_READONLY(target) ? 0x80 : 0x0) | 0x10;
2035 else 1975 else
2036 dev_spec = 0x0; 1976 dev_spec = 0x0;
@@ -2050,30 +1990,16 @@ resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2050 sdebug_capacity = get_sdebug_capacity(); 1990 sdebug_capacity = get_sdebug_capacity();
2051 1991
2052 if (8 == bd_len) { 1992 if (8 == bd_len) {
2053 if (sdebug_capacity > 0xfffffffe) { 1993 if (sdebug_capacity > 0xfffffffe)
2054 ap[0] = 0xff; 1994 put_unaligned_be32(0xffffffff, ap + 0);
2055 ap[1] = 0xff; 1995 else
2056 ap[2] = 0xff; 1996 put_unaligned_be32(sdebug_capacity, ap + 0);
2057 ap[3] = 0xff; 1997 put_unaligned_be16(sdebug_sector_size, ap + 6);
2058 } else {
2059 ap[0] = (sdebug_capacity >> 24) & 0xff;
2060 ap[1] = (sdebug_capacity >> 16) & 0xff;
2061 ap[2] = (sdebug_capacity >> 8) & 0xff;
2062 ap[3] = sdebug_capacity & 0xff;
2063 }
2064 ap[6] = (scsi_debug_sector_size >> 8) & 0xff;
2065 ap[7] = scsi_debug_sector_size & 0xff;
2066 offset += bd_len; 1998 offset += bd_len;
2067 ap = arr + offset; 1999 ap = arr + offset;
2068 } else if (16 == bd_len) { 2000 } else if (16 == bd_len) {
2069 unsigned long long capac = sdebug_capacity; 2001 put_unaligned_be64((u64)sdebug_capacity, ap + 0);
2070 2002 put_unaligned_be32(sdebug_sector_size, ap + 12);
2071 for (k = 0; k < 8; ++k, capac >>= 8)
2072 ap[7 - k] = capac & 0xff;
2073 ap[12] = (scsi_debug_sector_size >> 24) & 0xff;
2074 ap[13] = (scsi_debug_sector_size >> 16) & 0xff;
2075 ap[14] = (scsi_debug_sector_size >> 8) & 0xff;
2076 ap[15] = scsi_debug_sector_size & 0xff;
2077 offset += bd_len; 2003 offset += bd_len;
2078 ap = arr + offset; 2004 ap = arr + offset;
2079 } 2005 }
@@ -2149,10 +2075,8 @@ resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2149 } 2075 }
2150 if (msense_6) 2076 if (msense_6)
2151 arr[0] = offset - 1; 2077 arr[0] = offset - 1;
2152 else { 2078 else
2153 arr[0] = ((offset - 2) >> 8) & 0xff; 2079 put_unaligned_be16((offset - 2), arr + 0);
2154 arr[1] = (offset - 2) & 0xff;
2155 }
2156 return fill_from_dev_buffer(scp, arr, min(alloc_len, offset)); 2080 return fill_from_dev_buffer(scp, arr, min(alloc_len, offset));
2157} 2081}
2158 2082
@@ -2170,21 +2094,20 @@ resp_mode_select(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2170 memset(arr, 0, sizeof(arr)); 2094 memset(arr, 0, sizeof(arr));
2171 pf = cmd[1] & 0x10; 2095 pf = cmd[1] & 0x10;
2172 sp = cmd[1] & 0x1; 2096 sp = cmd[1] & 0x1;
2173 param_len = mselect6 ? cmd[4] : ((cmd[7] << 8) + cmd[8]); 2097 param_len = mselect6 ? cmd[4] : get_unaligned_be16(cmd + 7);
2174 if ((0 == pf) || sp || (param_len > SDEBUG_MAX_MSELECT_SZ)) { 2098 if ((0 == pf) || sp || (param_len > SDEBUG_MAX_MSELECT_SZ)) {
2175 mk_sense_invalid_fld(scp, SDEB_IN_CDB, mselect6 ? 4 : 7, -1); 2099 mk_sense_invalid_fld(scp, SDEB_IN_CDB, mselect6 ? 4 : 7, -1);
2176 return check_condition_result; 2100 return check_condition_result;
2177 } 2101 }
2178 res = fetch_to_dev_buffer(scp, arr, param_len); 2102 res = fetch_to_dev_buffer(scp, arr, param_len);
2179 if (-1 == res) 2103 if (-1 == res)
2180 return (DID_ERROR << 16); 2104 return DID_ERROR << 16;
2181 else if ((res < param_len) && 2105 else if (sdebug_verbose && (res < param_len))
2182 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
2183 sdev_printk(KERN_INFO, scp->device, 2106 sdev_printk(KERN_INFO, scp->device,
2184 "%s: cdb indicated=%d, IO sent=%d bytes\n", 2107 "%s: cdb indicated=%d, IO sent=%d bytes\n",
2185 __func__, param_len, res); 2108 __func__, param_len, res);
2186 md_len = mselect6 ? (arr[0] + 1) : ((arr[0] << 8) + arr[1] + 2); 2109 md_len = mselect6 ? (arr[0] + 1) : (get_unaligned_be16(arr + 0) + 2);
2187 bd_len = mselect6 ? arr[3] : ((arr[6] << 8) + arr[7]); 2110 bd_len = mselect6 ? arr[3] : get_unaligned_be16(arr + 6);
2188 if (md_len > 2) { 2111 if (md_len > 2) {
2189 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1); 2112 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1);
2190 return check_condition_result; 2113 return check_condition_result;
@@ -2197,7 +2120,7 @@ resp_mode_select(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2197 return check_condition_result; 2120 return check_condition_result;
2198 } 2121 }
2199 spf = !!(arr[off] & 0x40); 2122 spf = !!(arr[off] & 0x40);
2200 pg_len = spf ? ((arr[off + 2] << 8) + arr[off + 3] + 4) : 2123 pg_len = spf ? (get_unaligned_be16(arr + off + 2) + 4) :
2201 (arr[off + 1] + 2); 2124 (arr[off + 1] + 2);
2202 if ((pg_len + off) > param_len) { 2125 if ((pg_len + off) > param_len) {
2203 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2126 mk_sense_buffer(scp, ILLEGAL_REQUEST,
@@ -2216,7 +2139,7 @@ resp_mode_select(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2216 if (ctrl_m_pg[1] == arr[off + 1]) { 2139 if (ctrl_m_pg[1] == arr[off + 1]) {
2217 memcpy(ctrl_m_pg + 2, arr + off + 2, 2140 memcpy(ctrl_m_pg + 2, arr + off + 2,
2218 sizeof(ctrl_m_pg) - 2); 2141 sizeof(ctrl_m_pg) - 2);
2219 scsi_debug_dsense = !!(ctrl_m_pg[2] & 0x4); 2142 sdebug_dsense = !!(ctrl_m_pg[2] & 0x4);
2220 goto set_mode_changed_ua; 2143 goto set_mode_changed_ua;
2221 } 2144 }
2222 break; 2145 break;
@@ -2279,7 +2202,7 @@ static int resp_log_sense(struct scsi_cmnd * scp,
2279 pcontrol = (cmd[2] & 0xc0) >> 6; 2202 pcontrol = (cmd[2] & 0xc0) >> 6;
2280 pcode = cmd[2] & 0x3f; 2203 pcode = cmd[2] & 0x3f;
2281 subpcode = cmd[3] & 0xff; 2204 subpcode = cmd[3] & 0xff;
2282 alloc_len = (cmd[7] << 8) + cmd[8]; 2205 alloc_len = get_unaligned_be16(cmd + 7);
2283 arr[0] = pcode; 2206 arr[0] = pcode;
2284 if (0 == subpcode) { 2207 if (0 == subpcode) {
2285 switch (pcode) { 2208 switch (pcode) {
@@ -2336,7 +2259,7 @@ static int resp_log_sense(struct scsi_cmnd * scp,
2336 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); 2259 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1);
2337 return check_condition_result; 2260 return check_condition_result;
2338 } 2261 }
2339 len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len); 2262 len = min(get_unaligned_be16(arr + 2) + 4, alloc_len);
2340 return fill_from_dev_buffer(scp, arr, 2263 return fill_from_dev_buffer(scp, arr,
2341 min(len, SDEBUG_MAX_INQ_ARR_SZ)); 2264 min(len, SDEBUG_MAX_INQ_ARR_SZ));
2342} 2265}
@@ -2384,15 +2307,15 @@ do_device_access(struct scsi_cmnd *scmd, u64 lba, u32 num, bool do_write)
2384 rest = block + num - sdebug_store_sectors; 2307 rest = block + num - sdebug_store_sectors;
2385 2308
2386 ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, 2309 ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents,
2387 fake_storep + (block * scsi_debug_sector_size), 2310 fake_storep + (block * sdebug_sector_size),
2388 (num - rest) * scsi_debug_sector_size, 0, do_write); 2311 (num - rest) * sdebug_sector_size, 0, do_write);
2389 if (ret != (num - rest) * scsi_debug_sector_size) 2312 if (ret != (num - rest) * sdebug_sector_size)
2390 return ret; 2313 return ret;
2391 2314
2392 if (rest) { 2315 if (rest) {
2393 ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents, 2316 ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents,
2394 fake_storep, rest * scsi_debug_sector_size, 2317 fake_storep, rest * sdebug_sector_size,
2395 (num - rest) * scsi_debug_sector_size, do_write); 2318 (num - rest) * sdebug_sector_size, do_write);
2396 } 2319 }
2397 2320
2398 return ret; 2321 return ret;
@@ -2407,7 +2330,7 @@ comp_write_worker(u64 lba, u32 num, const u8 *arr)
2407 bool res; 2330 bool res;
2408 u64 block, rest = 0; 2331 u64 block, rest = 0;
2409 u32 store_blks = sdebug_store_sectors; 2332 u32 store_blks = sdebug_store_sectors;
2410 u32 lb_size = scsi_debug_sector_size; 2333 u32 lb_size = sdebug_sector_size;
2411 2334
2412 block = do_div(lba, store_blks); 2335 block = do_div(lba, store_blks);
2413 if (block + num > store_blks) 2336 if (block + num > store_blks)
@@ -2434,7 +2357,7 @@ static __be16 dif_compute_csum(const void *buf, int len)
2434{ 2357{
2435 __be16 csum; 2358 __be16 csum;
2436 2359
2437 if (scsi_debug_guard) 2360 if (sdebug_guard)
2438 csum = (__force __be16)ip_compute_csum(buf, len); 2361 csum = (__force __be16)ip_compute_csum(buf, len);
2439 else 2362 else
2440 csum = cpu_to_be16(crc_t10dif(buf, len)); 2363 csum = cpu_to_be16(crc_t10dif(buf, len));
@@ -2445,7 +2368,7 @@ static __be16 dif_compute_csum(const void *buf, int len)
2445static int dif_verify(struct sd_dif_tuple *sdt, const void *data, 2368static int dif_verify(struct sd_dif_tuple *sdt, const void *data,
2446 sector_t sector, u32 ei_lba) 2369 sector_t sector, u32 ei_lba)
2447{ 2370{
2448 __be16 csum = dif_compute_csum(data, scsi_debug_sector_size); 2371 __be16 csum = dif_compute_csum(data, sdebug_sector_size);
2449 2372
2450 if (sdt->guard_tag != csum) { 2373 if (sdt->guard_tag != csum) {
2451 pr_err("GUARD check failed on sector %lu rcvd 0x%04x, data 0x%04x\n", 2374 pr_err("GUARD check failed on sector %lu rcvd 0x%04x, data 0x%04x\n",
@@ -2454,13 +2377,13 @@ static int dif_verify(struct sd_dif_tuple *sdt, const void *data,
2454 be16_to_cpu(csum)); 2377 be16_to_cpu(csum));
2455 return 0x01; 2378 return 0x01;
2456 } 2379 }
2457 if (scsi_debug_dif == SD_DIF_TYPE1_PROTECTION && 2380 if (sdebug_dif == SD_DIF_TYPE1_PROTECTION &&
2458 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) { 2381 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) {
2459 pr_err("REF check failed on sector %lu\n", 2382 pr_err("REF check failed on sector %lu\n",
2460 (unsigned long)sector); 2383 (unsigned long)sector);
2461 return 0x03; 2384 return 0x03;
2462 } 2385 }
2463 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && 2386 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION &&
2464 be32_to_cpu(sdt->ref_tag) != ei_lba) { 2387 be32_to_cpu(sdt->ref_tag) != ei_lba) {
2465 pr_err("REF check failed on sector %lu\n", 2388 pr_err("REF check failed on sector %lu\n",
2466 (unsigned long)sector); 2389 (unsigned long)sector);
@@ -2592,13 +2515,13 @@ resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2592 break; 2515 break;
2593 } 2516 }
2594 if (check_prot) { 2517 if (check_prot) {
2595 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && 2518 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION &&
2596 (cmd[1] & 0xe0)) { 2519 (cmd[1] & 0xe0)) {
2597 mk_sense_invalid_opcode(scp); 2520 mk_sense_invalid_opcode(scp);
2598 return check_condition_result; 2521 return check_condition_result;
2599 } 2522 }
2600 if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION || 2523 if ((sdebug_dif == SD_DIF_TYPE1_PROTECTION ||
2601 scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) && 2524 sdebug_dif == SD_DIF_TYPE3_PROTECTION) &&
2602 (cmd[1] & 0xe0) == 0) 2525 (cmd[1] & 0xe0) == 0)
2603 sdev_printk(KERN_ERR, scp->device, "Unprotected RD " 2526 sdev_printk(KERN_ERR, scp->device, "Unprotected RD "
2604 "to DIF device\n"); 2527 "to DIF device\n");
@@ -2622,7 +2545,7 @@ resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2622 return check_condition_result; 2545 return check_condition_result;
2623 } 2546 }
2624 2547
2625 if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && 2548 if ((SDEBUG_OPT_MEDIUM_ERR & sdebug_opts) &&
2626 (lba <= (OPT_MEDIUM_ERR_ADDR + OPT_MEDIUM_ERR_NUM - 1)) && 2549 (lba <= (OPT_MEDIUM_ERR_ADDR + OPT_MEDIUM_ERR_NUM - 1)) &&
2627 ((lba + num) > OPT_MEDIUM_ERR_ADDR)) { 2550 ((lba + num) > OPT_MEDIUM_ERR_ADDR)) {
2628 /* claim unrecoverable read error */ 2551 /* claim unrecoverable read error */
@@ -2641,7 +2564,7 @@ resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2641 read_lock_irqsave(&atomic_rw, iflags); 2564 read_lock_irqsave(&atomic_rw, iflags);
2642 2565
2643 /* DIX + T10 DIF */ 2566 /* DIX + T10 DIF */
2644 if (scsi_debug_dix && scsi_prot_sg_count(scp)) { 2567 if (sdebug_dix && scsi_prot_sg_count(scp)) {
2645 int prot_ret = prot_verify_read(scp, lba, num, ei_lba); 2568 int prot_ret = prot_verify_read(scp, lba, num, ei_lba);
2646 2569
2647 if (prot_ret) { 2570 if (prot_ret) {
@@ -2750,13 +2673,13 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
2750 2673
2751 ret = dif_verify(sdt, daddr, sector, ei_lba); 2674 ret = dif_verify(sdt, daddr, sector, ei_lba);
2752 if (ret) { 2675 if (ret) {
2753 dump_sector(daddr, scsi_debug_sector_size); 2676 dump_sector(daddr, sdebug_sector_size);
2754 goto out; 2677 goto out;
2755 } 2678 }
2756 2679
2757 sector++; 2680 sector++;
2758 ei_lba++; 2681 ei_lba++;
2759 dpage_offset += scsi_debug_sector_size; 2682 dpage_offset += sdebug_sector_size;
2760 } 2683 }
2761 diter.consumed = dpage_offset; 2684 diter.consumed = dpage_offset;
2762 sg_miter_stop(&diter); 2685 sg_miter_stop(&diter);
@@ -2777,24 +2700,18 @@ out:
2777 2700
2778static unsigned long lba_to_map_index(sector_t lba) 2701static unsigned long lba_to_map_index(sector_t lba)
2779{ 2702{
2780 if (scsi_debug_unmap_alignment) { 2703 if (sdebug_unmap_alignment)
2781 lba += scsi_debug_unmap_granularity - 2704 lba += sdebug_unmap_granularity - sdebug_unmap_alignment;
2782 scsi_debug_unmap_alignment; 2705 sector_div(lba, sdebug_unmap_granularity);
2783 }
2784 sector_div(lba, scsi_debug_unmap_granularity);
2785
2786 return lba; 2706 return lba;
2787} 2707}
2788 2708
2789static sector_t map_index_to_lba(unsigned long index) 2709static sector_t map_index_to_lba(unsigned long index)
2790{ 2710{
2791 sector_t lba = index * scsi_debug_unmap_granularity; 2711 sector_t lba = index * sdebug_unmap_granularity;
2792
2793 if (scsi_debug_unmap_alignment) {
2794 lba -= scsi_debug_unmap_granularity -
2795 scsi_debug_unmap_alignment;
2796 }
2797 2712
2713 if (sdebug_unmap_alignment)
2714 lba -= sdebug_unmap_granularity - sdebug_unmap_alignment;
2798 return lba; 2715 return lba;
2799} 2716}
2800 2717
@@ -2815,7 +2732,6 @@ static unsigned int map_state(sector_t lba, unsigned int *num)
2815 2732
2816 end = min_t(sector_t, sdebug_store_sectors, map_index_to_lba(next)); 2733 end = min_t(sector_t, sdebug_store_sectors, map_index_to_lba(next));
2817 *num = end - lba; 2734 *num = end - lba;
2818
2819 return mapped; 2735 return mapped;
2820} 2736}
2821 2737
@@ -2841,19 +2757,19 @@ static void unmap_region(sector_t lba, unsigned int len)
2841 unsigned long index = lba_to_map_index(lba); 2757 unsigned long index = lba_to_map_index(lba);
2842 2758
2843 if (lba == map_index_to_lba(index) && 2759 if (lba == map_index_to_lba(index) &&
2844 lba + scsi_debug_unmap_granularity <= end && 2760 lba + sdebug_unmap_granularity <= end &&
2845 index < map_size) { 2761 index < map_size) {
2846 clear_bit(index, map_storep); 2762 clear_bit(index, map_storep);
2847 if (scsi_debug_lbprz) { 2763 if (sdebug_lbprz) {
2848 memset(fake_storep + 2764 memset(fake_storep +
2849 lba * scsi_debug_sector_size, 0, 2765 lba * sdebug_sector_size, 0,
2850 scsi_debug_sector_size * 2766 sdebug_sector_size *
2851 scsi_debug_unmap_granularity); 2767 sdebug_unmap_granularity);
2852 } 2768 }
2853 if (dif_storep) { 2769 if (dif_storep) {
2854 memset(dif_storep + lba, 0xff, 2770 memset(dif_storep + lba, 0xff,
2855 sizeof(*dif_storep) * 2771 sizeof(*dif_storep) *
2856 scsi_debug_unmap_granularity); 2772 sdebug_unmap_granularity);
2857 } 2773 }
2858 } 2774 }
2859 lba = map_index_to_lba(index + 1); 2775 lba = map_index_to_lba(index + 1);
@@ -2911,13 +2827,13 @@ resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2911 break; 2827 break;
2912 } 2828 }
2913 if (check_prot) { 2829 if (check_prot) {
2914 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && 2830 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION &&
2915 (cmd[1] & 0xe0)) { 2831 (cmd[1] & 0xe0)) {
2916 mk_sense_invalid_opcode(scp); 2832 mk_sense_invalid_opcode(scp);
2917 return check_condition_result; 2833 return check_condition_result;
2918 } 2834 }
2919 if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION || 2835 if ((sdebug_dif == SD_DIF_TYPE1_PROTECTION ||
2920 scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) && 2836 sdebug_dif == SD_DIF_TYPE3_PROTECTION) &&
2921 (cmd[1] & 0xe0) == 0) 2837 (cmd[1] & 0xe0) == 0)
2922 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " 2838 sdev_printk(KERN_ERR, scp->device, "Unprotected WR "
2923 "to DIF device\n"); 2839 "to DIF device\n");
@@ -2938,7 +2854,7 @@ resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2938 write_lock_irqsave(&atomic_rw, iflags); 2854 write_lock_irqsave(&atomic_rw, iflags);
2939 2855
2940 /* DIX + T10 DIF */ 2856 /* DIX + T10 DIF */
2941 if (scsi_debug_dix && scsi_prot_sg_count(scp)) { 2857 if (sdebug_dix && scsi_prot_sg_count(scp)) {
2942 int prot_ret = prot_verify_write(scp, lba, num, ei_lba); 2858 int prot_ret = prot_verify_write(scp, lba, num, ei_lba);
2943 2859
2944 if (prot_ret) { 2860 if (prot_ret) {
@@ -2953,12 +2869,11 @@ resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2953 map_region(lba, num); 2869 map_region(lba, num);
2954 write_unlock_irqrestore(&atomic_rw, iflags); 2870 write_unlock_irqrestore(&atomic_rw, iflags);
2955 if (-1 == ret) 2871 if (-1 == ret)
2956 return (DID_ERROR << 16); 2872 return DID_ERROR << 16;
2957 else if ((ret < (num * scsi_debug_sector_size)) && 2873 else if (sdebug_verbose && (ret < (num * sdebug_sector_size)))
2958 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
2959 sdev_printk(KERN_INFO, scp->device, 2874 sdev_printk(KERN_INFO, scp->device,
2960 "%s: write: cdb indicated=%u, IO sent=%d bytes\n", 2875 "%s: write: cdb indicated=%u, IO sent=%d bytes\n",
2961 my_name, num * scsi_debug_sector_size, ret); 2876 my_name, num * sdebug_sector_size, ret);
2962 2877
2963 if (sdebug_any_injecting_opt) { 2878 if (sdebug_any_injecting_opt) {
2964 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp); 2879 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
@@ -2986,6 +2901,7 @@ resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, u32 ei_lba,
2986 unsigned long iflags; 2901 unsigned long iflags;
2987 unsigned long long i; 2902 unsigned long long i;
2988 int ret; 2903 int ret;
2904 u64 lba_off;
2989 2905
2990 ret = check_device_access_params(scp, lba, num); 2906 ret = check_device_access_params(scp, lba, num);
2991 if (ret) 2907 if (ret)
@@ -2998,31 +2914,29 @@ resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, u32 ei_lba,
2998 goto out; 2914 goto out;
2999 } 2915 }
3000 2916
2917 lba_off = lba * sdebug_sector_size;
3001 /* if ndob then zero 1 logical block, else fetch 1 logical block */ 2918 /* if ndob then zero 1 logical block, else fetch 1 logical block */
3002 if (ndob) { 2919 if (ndob) {
3003 memset(fake_storep + (lba * scsi_debug_sector_size), 0, 2920 memset(fake_storep + lba_off, 0, sdebug_sector_size);
3004 scsi_debug_sector_size);
3005 ret = 0; 2921 ret = 0;
3006 } else 2922 } else
3007 ret = fetch_to_dev_buffer(scp, fake_storep + 2923 ret = fetch_to_dev_buffer(scp, fake_storep + lba_off,
3008 (lba * scsi_debug_sector_size), 2924 sdebug_sector_size);
3009 scsi_debug_sector_size);
3010 2925
3011 if (-1 == ret) { 2926 if (-1 == ret) {
3012 write_unlock_irqrestore(&atomic_rw, iflags); 2927 write_unlock_irqrestore(&atomic_rw, iflags);
3013 return (DID_ERROR << 16); 2928 return DID_ERROR << 16;
3014 } else if ((ret < (num * scsi_debug_sector_size)) && 2929 } else if (sdebug_verbose && (ret < (num * sdebug_sector_size)))
3015 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
3016 sdev_printk(KERN_INFO, scp->device, 2930 sdev_printk(KERN_INFO, scp->device,
3017 "%s: %s: cdb indicated=%u, IO sent=%d bytes\n", 2931 "%s: %s: cdb indicated=%u, IO sent=%d bytes\n",
3018 my_name, "write same", 2932 my_name, "write same",
3019 num * scsi_debug_sector_size, ret); 2933 num * sdebug_sector_size, ret);
3020 2934
3021 /* Copy first sector to remaining blocks */ 2935 /* Copy first sector to remaining blocks */
3022 for (i = 1 ; i < num ; i++) 2936 for (i = 1 ; i < num ; i++)
3023 memcpy(fake_storep + ((lba + i) * scsi_debug_sector_size), 2937 memcpy(fake_storep + ((lba + i) * sdebug_sector_size),
3024 fake_storep + (lba * scsi_debug_sector_size), 2938 fake_storep + lba_off,
3025 scsi_debug_sector_size); 2939 sdebug_sector_size);
3026 2940
3027 if (scsi_debug_lbp()) 2941 if (scsi_debug_lbp())
3028 map_region(lba, num); 2942 map_region(lba, num);
@@ -3042,7 +2956,7 @@ resp_write_same_10(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3042 bool unmap = false; 2956 bool unmap = false;
3043 2957
3044 if (cmd[1] & 0x8) { 2958 if (cmd[1] & 0x8) {
3045 if (scsi_debug_lbpws10 == 0) { 2959 if (sdebug_lbpws10 == 0) {
3046 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 3); 2960 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 3);
3047 return check_condition_result; 2961 return check_condition_result;
3048 } else 2962 } else
@@ -3050,7 +2964,7 @@ resp_write_same_10(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3050 } 2964 }
3051 lba = get_unaligned_be32(cmd + 2); 2965 lba = get_unaligned_be32(cmd + 2);
3052 num = get_unaligned_be16(cmd + 7); 2966 num = get_unaligned_be16(cmd + 7);
3053 if (num > scsi_debug_write_same_length) { 2967 if (num > sdebug_write_same_length) {
3054 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); 2968 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1);
3055 return check_condition_result; 2969 return check_condition_result;
3056 } 2970 }
@@ -3068,7 +2982,7 @@ resp_write_same_16(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3068 bool ndob = false; 2982 bool ndob = false;
3069 2983
3070 if (cmd[1] & 0x8) { /* UNMAP */ 2984 if (cmd[1] & 0x8) { /* UNMAP */
3071 if (scsi_debug_lbpws == 0) { 2985 if (sdebug_lbpws == 0) {
3072 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 3); 2986 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 3);
3073 return check_condition_result; 2987 return check_condition_result;
3074 } else 2988 } else
@@ -3078,7 +2992,7 @@ resp_write_same_16(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3078 ndob = true; 2992 ndob = true;
3079 lba = get_unaligned_be64(cmd + 2); 2993 lba = get_unaligned_be64(cmd + 2);
3080 num = get_unaligned_be32(cmd + 10); 2994 num = get_unaligned_be32(cmd + 10);
3081 if (num > scsi_debug_write_same_length) { 2995 if (num > sdebug_write_same_length) {
3082 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1); 2996 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1);
3083 return check_condition_result; 2997 return check_condition_result;
3084 } 2998 }
@@ -3142,7 +3056,7 @@ resp_comp_write(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3142 u8 *fake_storep_hold; 3056 u8 *fake_storep_hold;
3143 u64 lba; 3057 u64 lba;
3144 u32 dnum; 3058 u32 dnum;
3145 u32 lb_size = scsi_debug_sector_size; 3059 u32 lb_size = sdebug_sector_size;
3146 u8 num; 3060 u8 num;
3147 unsigned long iflags; 3061 unsigned long iflags;
3148 int ret; 3062 int ret;
@@ -3152,13 +3066,13 @@ resp_comp_write(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3152 num = cmd[13]; /* 1 to a maximum of 255 logical blocks */ 3066 num = cmd[13]; /* 1 to a maximum of 255 logical blocks */
3153 if (0 == num) 3067 if (0 == num)
3154 return 0; /* degenerate case, not an error */ 3068 return 0; /* degenerate case, not an error */
3155 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && 3069 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION &&
3156 (cmd[1] & 0xe0)) { 3070 (cmd[1] & 0xe0)) {
3157 mk_sense_invalid_opcode(scp); 3071 mk_sense_invalid_opcode(scp);
3158 return check_condition_result; 3072 return check_condition_result;
3159 } 3073 }
3160 if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION || 3074 if ((sdebug_dif == SD_DIF_TYPE1_PROTECTION ||
3161 scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) && 3075 sdebug_dif == SD_DIF_TYPE3_PROTECTION) &&
3162 (cmd[1] & 0xe0) == 0) 3076 (cmd[1] & 0xe0) == 0)
3163 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " 3077 sdev_printk(KERN_ERR, scp->device, "Unprotected WR "
3164 "to DIF device\n"); 3078 "to DIF device\n");
@@ -3193,8 +3107,7 @@ resp_comp_write(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3193 if (ret == -1) { 3107 if (ret == -1) {
3194 retval = DID_ERROR << 16; 3108 retval = DID_ERROR << 16;
3195 goto cleanup; 3109 goto cleanup;
3196 } else if ((ret < (dnum * lb_size)) && 3110 } else if (sdebug_verbose && (ret < (dnum * lb_size)))
3197 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
3198 sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " 3111 sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb "
3199 "indicated=%u, IO sent=%d bytes\n", my_name, 3112 "indicated=%u, IO sent=%d bytes\n", my_name,
3200 dnum * lb_size, ret); 3113 dnum * lb_size, ret);
@@ -3233,7 +3146,7 @@ resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3233 BUG_ON(scsi_bufflen(scp) != payload_len); 3146 BUG_ON(scsi_bufflen(scp) != payload_len);
3234 3147
3235 descriptors = (payload_len - 8) / 16; 3148 descriptors = (payload_len - 8) / 16;
3236 if (descriptors > scsi_debug_unmap_max_desc) { 3149 if (descriptors > sdebug_unmap_max_desc) {
3237 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); 3150 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1);
3238 return check_condition_result; 3151 return check_condition_result;
3239 } 3152 }
@@ -3339,10 +3252,10 @@ static int resp_report_luns(struct scsi_cmnd * scp,
3339 } 3252 }
3340 /* can produce response with up to 16k luns (lun 0 to lun 16383) */ 3253 /* can produce response with up to 16k luns (lun 0 to lun 16383) */
3341 memset(arr, 0, SDEBUG_RLUN_ARR_SZ); 3254 memset(arr, 0, SDEBUG_RLUN_ARR_SZ);
3342 lun_cnt = scsi_debug_max_luns; 3255 lun_cnt = sdebug_max_luns;
3343 if (1 == select_report) 3256 if (1 == select_report)
3344 lun_cnt = 0; 3257 lun_cnt = 0;
3345 else if (scsi_debug_no_lun_0 && (lun_cnt > 0)) 3258 else if (sdebug_no_lun_0 && (lun_cnt > 0))
3346 --lun_cnt; 3259 --lun_cnt;
3347 want_wlun = (select_report > 0) ? 1 : 0; 3260 want_wlun = (select_report > 0) ? 1 : 0;
3348 num = lun_cnt + want_wlun; 3261 num = lun_cnt + want_wlun;
@@ -3356,7 +3269,7 @@ static int resp_report_luns(struct scsi_cmnd * scp,
3356 } 3269 }
3357 one_lun = (struct scsi_lun *) &arr[8]; 3270 one_lun = (struct scsi_lun *) &arr[8];
3358 max_addr = arr + SDEBUG_RLUN_ARR_SZ; 3271 max_addr = arr + SDEBUG_RLUN_ARR_SZ;
3359 for (i = 0, lun = (scsi_debug_no_lun_0 ? 1 : 0); 3272 for (i = 0, lun = (sdebug_no_lun_0 ? 1 : 0);
3360 ((i < lun_cnt) && ((unsigned char *)(one_lun + i) < max_addr)); 3273 ((i < lun_cnt) && ((unsigned char *)(one_lun + i) < max_addr));
3361 i++, lun++) { 3274 i++, lun++) {
3362 upper = (lun >> 8) & 0x3f; 3275 upper = (lun >> 8) & 0x3f;
@@ -3486,7 +3399,7 @@ static void sdebug_q_cmd_complete(unsigned long indx)
3486 return; 3399 return;
3487 } 3400 }
3488 k = find_last_bit(queued_in_use_bm, retval); 3401 k = find_last_bit(queued_in_use_bm, retval);
3489 if ((k < scsi_debug_max_queue) || (k == retval)) 3402 if ((k < sdebug_max_queue) || (k == retval))
3490 atomic_set(&retired_max_queue, 0); 3403 atomic_set(&retired_max_queue, 0);
3491 else 3404 else
3492 atomic_set(&retired_max_queue, k + 1); 3405 atomic_set(&retired_max_queue, k + 1);
@@ -3546,7 +3459,7 @@ sdebug_q_cmd_hrt_complete(struct hrtimer *timer)
3546 goto the_end; 3459 goto the_end;
3547 } 3460 }
3548 k = find_last_bit(queued_in_use_bm, retval); 3461 k = find_last_bit(queued_in_use_bm, retval);
3549 if ((k < scsi_debug_max_queue) || (k == retval)) 3462 if ((k < sdebug_max_queue) || (k == retval))
3550 atomic_set(&retired_max_queue, 0); 3463 atomic_set(&retired_max_queue, 0);
3551 else 3464 else
3552 atomic_set(&retired_max_queue, k + 1); 3465 atomic_set(&retired_max_queue, k + 1);
@@ -3614,7 +3527,7 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
3614 3527
3615static int scsi_debug_slave_alloc(struct scsi_device *sdp) 3528static int scsi_debug_slave_alloc(struct scsi_device *sdp)
3616{ 3529{
3617 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 3530 if (sdebug_verbose)
3618 pr_info("slave_alloc <%u %u %u %llu>\n", 3531 pr_info("slave_alloc <%u %u %u %llu>\n",
3619 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); 3532 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
3620 queue_flag_set_unlocked(QUEUE_FLAG_BIDI, sdp->request_queue); 3533 queue_flag_set_unlocked(QUEUE_FLAG_BIDI, sdp->request_queue);
@@ -3625,7 +3538,7 @@ static int scsi_debug_slave_configure(struct scsi_device *sdp)
3625{ 3538{
3626 struct sdebug_dev_info *devip; 3539 struct sdebug_dev_info *devip;
3627 3540
3628 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 3541 if (sdebug_verbose)
3629 pr_info("slave_configure <%u %u %u %llu>\n", 3542 pr_info("slave_configure <%u %u %u %llu>\n",
3630 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); 3543 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
3631 if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) 3544 if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN)
@@ -3635,7 +3548,7 @@ static int scsi_debug_slave_configure(struct scsi_device *sdp)
3635 return 1; /* no resources, will be marked offline */ 3548 return 1; /* no resources, will be marked offline */
3636 sdp->hostdata = devip; 3549 sdp->hostdata = devip;
3637 blk_queue_max_segment_size(sdp->request_queue, -1U); 3550 blk_queue_max_segment_size(sdp->request_queue, -1U);
3638 if (scsi_debug_no_uld) 3551 if (sdebug_no_uld)
3639 sdp->no_uld_attach = 1; 3552 sdp->no_uld_attach = 1;
3640 return 0; 3553 return 0;
3641} 3554}
@@ -3645,7 +3558,7 @@ static void scsi_debug_slave_destroy(struct scsi_device *sdp)
3645 struct sdebug_dev_info *devip = 3558 struct sdebug_dev_info *devip =
3646 (struct sdebug_dev_info *)sdp->hostdata; 3559 (struct sdebug_dev_info *)sdp->hostdata;
3647 3560
3648 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 3561 if (sdebug_verbose)
3649 pr_info("slave_destroy <%u %u %u %llu>\n", 3562 pr_info("slave_destroy <%u %u %u %llu>\n",
3650 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); 3563 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
3651 if (devip) { 3564 if (devip) {
@@ -3664,7 +3577,7 @@ static int stop_queued_cmnd(struct scsi_cmnd *cmnd)
3664 struct sdebug_dev_info *devip; 3577 struct sdebug_dev_info *devip;
3665 3578
3666 spin_lock_irqsave(&queued_arr_lock, iflags); 3579 spin_lock_irqsave(&queued_arr_lock, iflags);
3667 qmax = scsi_debug_max_queue; 3580 qmax = sdebug_max_queue;
3668 r_qmax = atomic_read(&retired_max_queue); 3581 r_qmax = atomic_read(&retired_max_queue);
3669 if (r_qmax > qmax) 3582 if (r_qmax > qmax)
3670 qmax = r_qmax; 3583 qmax = r_qmax;
@@ -3679,15 +3592,15 @@ static int stop_queued_cmnd(struct scsi_cmnd *cmnd)
3679 sqcp->a_cmnd = NULL; 3592 sqcp->a_cmnd = NULL;
3680 spin_unlock_irqrestore(&queued_arr_lock, 3593 spin_unlock_irqrestore(&queued_arr_lock,
3681 iflags); 3594 iflags);
3682 if (scsi_debug_ndelay > 0) { 3595 if (sdebug_ndelay > 0) {
3683 if (sqcp->sd_hrtp) 3596 if (sqcp->sd_hrtp)
3684 hrtimer_cancel( 3597 hrtimer_cancel(
3685 &sqcp->sd_hrtp->hrt); 3598 &sqcp->sd_hrtp->hrt);
3686 } else if (scsi_debug_delay > 0) { 3599 } else if (sdebug_delay > 0) {
3687 if (sqcp->cmnd_timerp) 3600 if (sqcp->cmnd_timerp)
3688 del_timer_sync( 3601 del_timer_sync(
3689 sqcp->cmnd_timerp); 3602 sqcp->cmnd_timerp);
3690 } else if (scsi_debug_delay < 0) { 3603 } else if (sdebug_delay < 0) {
3691 if (sqcp->tletp) 3604 if (sqcp->tletp)
3692 tasklet_kill(sqcp->tletp); 3605 tasklet_kill(sqcp->tletp);
3693 } 3606 }
@@ -3720,15 +3633,15 @@ static void stop_all_queued(void)
3720 sqcp->a_cmnd = NULL; 3633 sqcp->a_cmnd = NULL;
3721 spin_unlock_irqrestore(&queued_arr_lock, 3634 spin_unlock_irqrestore(&queued_arr_lock,
3722 iflags); 3635 iflags);
3723 if (scsi_debug_ndelay > 0) { 3636 if (sdebug_ndelay > 0) {
3724 if (sqcp->sd_hrtp) 3637 if (sqcp->sd_hrtp)
3725 hrtimer_cancel( 3638 hrtimer_cancel(
3726 &sqcp->sd_hrtp->hrt); 3639 &sqcp->sd_hrtp->hrt);
3727 } else if (scsi_debug_delay > 0) { 3640 } else if (sdebug_delay > 0) {
3728 if (sqcp->cmnd_timerp) 3641 if (sqcp->cmnd_timerp)
3729 del_timer_sync( 3642 del_timer_sync(
3730 sqcp->cmnd_timerp); 3643 sqcp->cmnd_timerp);
3731 } else if (scsi_debug_delay < 0) { 3644 } else if (sdebug_delay < 0) {
3732 if (sqcp->tletp) 3645 if (sqcp->tletp)
3733 tasklet_kill(sqcp->tletp); 3646 tasklet_kill(sqcp->tletp);
3734 } 3647 }
@@ -3765,7 +3678,7 @@ static int scsi_debug_abort(struct scsi_cmnd *SCpnt)
3765 ++num_aborts; 3678 ++num_aborts;
3766 if (SCpnt) { 3679 if (SCpnt) {
3767 if (SCpnt->device && 3680 if (SCpnt->device &&
3768 (SCSI_DEBUG_OPT_ALL_NOISE & scsi_debug_opts)) 3681 (SDEBUG_OPT_ALL_NOISE & sdebug_opts))
3769 sdev_printk(KERN_INFO, SCpnt->device, "%s\n", 3682 sdev_printk(KERN_INFO, SCpnt->device, "%s\n",
3770 __func__); 3683 __func__);
3771 stop_queued_cmnd(SCpnt); 3684 stop_queued_cmnd(SCpnt);
@@ -3781,7 +3694,7 @@ static int scsi_debug_device_reset(struct scsi_cmnd * SCpnt)
3781 if (SCpnt && SCpnt->device) { 3694 if (SCpnt && SCpnt->device) {
3782 struct scsi_device *sdp = SCpnt->device; 3695 struct scsi_device *sdp = SCpnt->device;
3783 3696
3784 if (SCSI_DEBUG_OPT_ALL_NOISE & scsi_debug_opts) 3697 if (SDEBUG_OPT_ALL_NOISE & sdebug_opts)
3785 sdev_printk(KERN_INFO, sdp, "%s\n", __func__); 3698 sdev_printk(KERN_INFO, sdp, "%s\n", __func__);
3786 devip = devInfoReg(sdp); 3699 devip = devInfoReg(sdp);
3787 if (devip) 3700 if (devip)
@@ -3804,7 +3717,7 @@ static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt)
3804 sdp = SCpnt->device; 3717 sdp = SCpnt->device;
3805 if (!sdp) 3718 if (!sdp)
3806 goto lie; 3719 goto lie;
3807 if (SCSI_DEBUG_OPT_ALL_NOISE & scsi_debug_opts) 3720 if (SDEBUG_OPT_ALL_NOISE & sdebug_opts)
3808 sdev_printk(KERN_INFO, sdp, "%s\n", __func__); 3721 sdev_printk(KERN_INFO, sdp, "%s\n", __func__);
3809 hp = sdp->host; 3722 hp = sdp->host;
3810 if (!hp) 3723 if (!hp)
@@ -3819,7 +3732,7 @@ static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt)
3819 ++k; 3732 ++k;
3820 } 3733 }
3821 } 3734 }
3822 if (SCSI_DEBUG_OPT_RESET_NOISE & scsi_debug_opts) 3735 if (SDEBUG_OPT_RESET_NOISE & sdebug_opts)
3823 sdev_printk(KERN_INFO, sdp, 3736 sdev_printk(KERN_INFO, sdp,
3824 "%s: %d device(s) found in target\n", __func__, k); 3737 "%s: %d device(s) found in target\n", __func__, k);
3825lie: 3738lie:
@@ -3838,7 +3751,7 @@ static int scsi_debug_bus_reset(struct scsi_cmnd * SCpnt)
3838 if (!(SCpnt && SCpnt->device)) 3751 if (!(SCpnt && SCpnt->device))
3839 goto lie; 3752 goto lie;
3840 sdp = SCpnt->device; 3753 sdp = SCpnt->device;
3841 if (SCSI_DEBUG_OPT_ALL_NOISE & scsi_debug_opts) 3754 if (SDEBUG_OPT_ALL_NOISE & sdebug_opts)
3842 sdev_printk(KERN_INFO, sdp, "%s\n", __func__); 3755 sdev_printk(KERN_INFO, sdp, "%s\n", __func__);
3843 hp = sdp->host; 3756 hp = sdp->host;
3844 if (hp) { 3757 if (hp) {
@@ -3852,7 +3765,7 @@ static int scsi_debug_bus_reset(struct scsi_cmnd * SCpnt)
3852 } 3765 }
3853 } 3766 }
3854 } 3767 }
3855 if (SCSI_DEBUG_OPT_RESET_NOISE & scsi_debug_opts) 3768 if (SDEBUG_OPT_RESET_NOISE & sdebug_opts)
3856 sdev_printk(KERN_INFO, sdp, 3769 sdev_printk(KERN_INFO, sdp,
3857 "%s: %d device(s) found in host\n", __func__, k); 3770 "%s: %d device(s) found in host\n", __func__, k);
3858lie: 3771lie:
@@ -3866,7 +3779,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd * SCpnt)
3866 int k = 0; 3779 int k = 0;
3867 3780
3868 ++num_host_resets; 3781 ++num_host_resets;
3869 if ((SCpnt->device) && (SCSI_DEBUG_OPT_ALL_NOISE & scsi_debug_opts)) 3782 if ((SCpnt->device) && (SDEBUG_OPT_ALL_NOISE & sdebug_opts))
3870 sdev_printk(KERN_INFO, SCpnt->device, "%s\n", __func__); 3783 sdev_printk(KERN_INFO, SCpnt->device, "%s\n", __func__);
3871 spin_lock(&sdebug_host_list_lock); 3784 spin_lock(&sdebug_host_list_lock);
3872 list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) { 3785 list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
@@ -3878,7 +3791,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd * SCpnt)
3878 } 3791 }
3879 spin_unlock(&sdebug_host_list_lock); 3792 spin_unlock(&sdebug_host_list_lock);
3880 stop_all_queued(); 3793 stop_all_queued();
3881 if (SCSI_DEBUG_OPT_RESET_NOISE & scsi_debug_opts) 3794 if (SDEBUG_OPT_RESET_NOISE & sdebug_opts)
3882 sdev_printk(KERN_INFO, SCpnt->device, 3795 sdev_printk(KERN_INFO, SCpnt->device,
3883 "%s: %d device(s) found\n", __func__, k); 3796 "%s: %d device(s) found\n", __func__, k);
3884 return SUCCESS; 3797 return SUCCESS;
@@ -3893,22 +3806,22 @@ static void __init sdebug_build_parts(unsigned char *ramp,
3893 int heads_by_sects, start_sec, end_sec; 3806 int heads_by_sects, start_sec, end_sec;
3894 3807
3895 /* assume partition table already zeroed */ 3808 /* assume partition table already zeroed */
3896 if ((scsi_debug_num_parts < 1) || (store_size < 1048576)) 3809 if ((sdebug_num_parts < 1) || (store_size < 1048576))
3897 return; 3810 return;
3898 if (scsi_debug_num_parts > SDEBUG_MAX_PARTS) { 3811 if (sdebug_num_parts > SDEBUG_MAX_PARTS) {
3899 scsi_debug_num_parts = SDEBUG_MAX_PARTS; 3812 sdebug_num_parts = SDEBUG_MAX_PARTS;
3900 pr_warn("reducing partitions to %d\n", SDEBUG_MAX_PARTS); 3813 pr_warn("reducing partitions to %d\n", SDEBUG_MAX_PARTS);
3901 } 3814 }
3902 num_sectors = (int)sdebug_store_sectors; 3815 num_sectors = (int)sdebug_store_sectors;
3903 sectors_per_part = (num_sectors - sdebug_sectors_per) 3816 sectors_per_part = (num_sectors - sdebug_sectors_per)
3904 / scsi_debug_num_parts; 3817 / sdebug_num_parts;
3905 heads_by_sects = sdebug_heads * sdebug_sectors_per; 3818 heads_by_sects = sdebug_heads * sdebug_sectors_per;
3906 starts[0] = sdebug_sectors_per; 3819 starts[0] = sdebug_sectors_per;
3907 for (k = 1; k < scsi_debug_num_parts; ++k) 3820 for (k = 1; k < sdebug_num_parts; ++k)
3908 starts[k] = ((k * sectors_per_part) / heads_by_sects) 3821 starts[k] = ((k * sectors_per_part) / heads_by_sects)
3909 * heads_by_sects; 3822 * heads_by_sects;
3910 starts[scsi_debug_num_parts] = num_sectors; 3823 starts[sdebug_num_parts] = num_sectors;
3911 starts[scsi_debug_num_parts + 1] = 0; 3824 starts[sdebug_num_parts + 1] = 0;
3912 3825
3913 ramp[510] = 0x55; /* magic partition markings */ 3826 ramp[510] = 0x55; /* magic partition markings */
3914 ramp[511] = 0xAA; 3827 ramp[511] = 0xAA;
@@ -3955,7 +3868,7 @@ schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
3955 3868
3956 sdp = cmnd->device; 3869 sdp = cmnd->device;
3957 3870
3958 if ((scsi_result) && (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) 3871 if (sdebug_verbose && scsi_result)
3959 sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n", 3872 sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n",
3960 __func__, scsi_result); 3873 __func__, scsi_result);
3961 if (delta_jiff == 0) 3874 if (delta_jiff == 0)
@@ -3972,29 +3885,29 @@ schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
3972 goto respond_in_thread; 3885 goto respond_in_thread;
3973 } else 3886 } else
3974 scsi_result = device_qfull_result; 3887 scsi_result = device_qfull_result;
3975 } else if ((scsi_debug_every_nth != 0) && 3888 } else if ((sdebug_every_nth != 0) &&
3976 (SCSI_DEBUG_OPT_RARE_TSF & scsi_debug_opts) && 3889 (SDEBUG_OPT_RARE_TSF & sdebug_opts) &&
3977 (scsi_result == 0)) { 3890 (scsi_result == 0)) {
3978 if ((num_in_q == (qdepth - 1)) && 3891 if ((num_in_q == (qdepth - 1)) &&
3979 (atomic_inc_return(&sdebug_a_tsf) >= 3892 (atomic_inc_return(&sdebug_a_tsf) >=
3980 abs(scsi_debug_every_nth))) { 3893 abs(sdebug_every_nth))) {
3981 atomic_set(&sdebug_a_tsf, 0); 3894 atomic_set(&sdebug_a_tsf, 0);
3982 inject = 1; 3895 inject = 1;
3983 scsi_result = device_qfull_result; 3896 scsi_result = device_qfull_result;
3984 } 3897 }
3985 } 3898 }
3986 3899
3987 k = find_first_zero_bit(queued_in_use_bm, scsi_debug_max_queue); 3900 k = find_first_zero_bit(queued_in_use_bm, sdebug_max_queue);
3988 if (k >= scsi_debug_max_queue) { 3901 if (k >= sdebug_max_queue) {
3989 spin_unlock_irqrestore(&queued_arr_lock, iflags); 3902 spin_unlock_irqrestore(&queued_arr_lock, iflags);
3990 if (scsi_result) 3903 if (scsi_result)
3991 goto respond_in_thread; 3904 goto respond_in_thread;
3992 else if (SCSI_DEBUG_OPT_ALL_TSF & scsi_debug_opts) 3905 else if (SDEBUG_OPT_ALL_TSF & sdebug_opts)
3993 scsi_result = device_qfull_result; 3906 scsi_result = device_qfull_result;
3994 if (SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) 3907 if (SDEBUG_OPT_Q_NOISE & sdebug_opts)
3995 sdev_printk(KERN_INFO, sdp, 3908 sdev_printk(KERN_INFO, sdp,
3996 "%s: max_queue=%d exceeded, %s\n", 3909 "%s: max_queue=%d exceeded, %s\n",
3997 __func__, scsi_debug_max_queue, 3910 __func__, sdebug_max_queue,
3998 (scsi_result ? "status: TASK SET FULL" : 3911 (scsi_result ? "status: TASK SET FULL" :
3999 "report: host busy")); 3912 "report: host busy"));
4000 if (scsi_result) 3913 if (scsi_result)
@@ -4020,8 +3933,8 @@ schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
4020 sqcp->cmnd_timerp->data = k; 3933 sqcp->cmnd_timerp->data = k;
4021 sqcp->cmnd_timerp->expires = get_jiffies_64() + delta_jiff; 3934 sqcp->cmnd_timerp->expires = get_jiffies_64() + delta_jiff;
4022 add_timer(sqcp->cmnd_timerp); 3935 add_timer(sqcp->cmnd_timerp);
4023 } else if (scsi_debug_ndelay > 0) { 3936 } else if (sdebug_ndelay > 0) {
4024 ktime_t kt = ktime_set(0, scsi_debug_ndelay); 3937 ktime_t kt = ktime_set(0, sdebug_ndelay);
4025 struct sdebug_hrtimer *sd_hp = sqcp->sd_hrtp; 3938 struct sdebug_hrtimer *sd_hp = sqcp->sd_hrtp;
4026 3939
4027 if (NULL == sd_hp) { 3940 if (NULL == sd_hp) {
@@ -4049,7 +3962,7 @@ schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
4049 else 3962 else
4050 tasklet_schedule(sqcp->tletp); 3963 tasklet_schedule(sqcp->tletp);
4051 } 3964 }
4052 if ((SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) && 3965 if ((SDEBUG_OPT_Q_NOISE & sdebug_opts) &&
4053 (scsi_result == device_qfull_result)) 3966 (scsi_result == device_qfull_result))
4054 sdev_printk(KERN_INFO, sdp, 3967 sdev_printk(KERN_INFO, sdp,
4055 "%s: num_in_q=%d +1, %s%s\n", __func__, 3968 "%s: num_in_q=%d +1, %s%s\n", __func__,
@@ -4069,46 +3982,46 @@ respond_in_thread: /* call back to mid-layer using invocation thread */
4069 as it can when the corresponding attribute in the 3982 as it can when the corresponding attribute in the
4070 /sys/bus/pseudo/drivers/scsi_debug directory is changed. 3983 /sys/bus/pseudo/drivers/scsi_debug directory is changed.
4071 */ 3984 */
4072module_param_named(add_host, scsi_debug_add_host, int, S_IRUGO | S_IWUSR); 3985module_param_named(add_host, sdebug_add_host, int, S_IRUGO | S_IWUSR);
4073module_param_named(ato, scsi_debug_ato, int, S_IRUGO); 3986module_param_named(ato, sdebug_ato, int, S_IRUGO);
4074module_param_named(clustering, scsi_debug_clustering, bool, S_IRUGO | S_IWUSR); 3987module_param_named(clustering, sdebug_clustering, bool, S_IRUGO | S_IWUSR);
4075module_param_named(delay, scsi_debug_delay, int, S_IRUGO | S_IWUSR); 3988module_param_named(delay, sdebug_delay, int, S_IRUGO | S_IWUSR);
4076module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, S_IRUGO); 3989module_param_named(dev_size_mb, sdebug_dev_size_mb, int, S_IRUGO);
4077module_param_named(dif, scsi_debug_dif, int, S_IRUGO); 3990module_param_named(dif, sdebug_dif, int, S_IRUGO);
4078module_param_named(dix, scsi_debug_dix, int, S_IRUGO); 3991module_param_named(dix, sdebug_dix, int, S_IRUGO);
4079module_param_named(dsense, scsi_debug_dsense, int, S_IRUGO | S_IWUSR); 3992module_param_named(dsense, sdebug_dsense, int, S_IRUGO | S_IWUSR);
4080module_param_named(every_nth, scsi_debug_every_nth, int, S_IRUGO | S_IWUSR); 3993module_param_named(every_nth, sdebug_every_nth, int, S_IRUGO | S_IWUSR);
4081module_param_named(fake_rw, scsi_debug_fake_rw, int, S_IRUGO | S_IWUSR); 3994module_param_named(fake_rw, sdebug_fake_rw, int, S_IRUGO | S_IWUSR);
4082module_param_named(guard, scsi_debug_guard, uint, S_IRUGO); 3995module_param_named(guard, sdebug_guard, uint, S_IRUGO);
4083module_param_named(host_lock, scsi_debug_host_lock, bool, S_IRUGO | S_IWUSR); 3996module_param_named(host_lock, sdebug_host_lock, bool, S_IRUGO | S_IWUSR);
4084module_param_named(lbpu, scsi_debug_lbpu, int, S_IRUGO); 3997module_param_named(lbpu, sdebug_lbpu, int, S_IRUGO);
4085module_param_named(lbpws, scsi_debug_lbpws, int, S_IRUGO); 3998module_param_named(lbpws, sdebug_lbpws, int, S_IRUGO);
4086module_param_named(lbpws10, scsi_debug_lbpws10, int, S_IRUGO); 3999module_param_named(lbpws10, sdebug_lbpws10, int, S_IRUGO);
4087module_param_named(lbprz, scsi_debug_lbprz, int, S_IRUGO); 4000module_param_named(lbprz, sdebug_lbprz, int, S_IRUGO);
4088module_param_named(lowest_aligned, scsi_debug_lowest_aligned, int, S_IRUGO); 4001module_param_named(lowest_aligned, sdebug_lowest_aligned, int, S_IRUGO);
4089module_param_named(max_luns, scsi_debug_max_luns, int, S_IRUGO | S_IWUSR); 4002module_param_named(max_luns, sdebug_max_luns, int, S_IRUGO | S_IWUSR);
4090module_param_named(max_queue, scsi_debug_max_queue, int, S_IRUGO | S_IWUSR); 4003module_param_named(max_queue, sdebug_max_queue, int, S_IRUGO | S_IWUSR);
4091module_param_named(ndelay, scsi_debug_ndelay, int, S_IRUGO | S_IWUSR); 4004module_param_named(ndelay, sdebug_ndelay, int, S_IRUGO | S_IWUSR);
4092module_param_named(no_lun_0, scsi_debug_no_lun_0, int, S_IRUGO | S_IWUSR); 4005module_param_named(no_lun_0, sdebug_no_lun_0, int, S_IRUGO | S_IWUSR);
4093module_param_named(no_uld, scsi_debug_no_uld, int, S_IRUGO); 4006module_param_named(no_uld, sdebug_no_uld, int, S_IRUGO);
4094module_param_named(num_parts, scsi_debug_num_parts, int, S_IRUGO); 4007module_param_named(num_parts, sdebug_num_parts, int, S_IRUGO);
4095module_param_named(num_tgts, scsi_debug_num_tgts, int, S_IRUGO | S_IWUSR); 4008module_param_named(num_tgts, sdebug_num_tgts, int, S_IRUGO | S_IWUSR);
4096module_param_named(opt_blks, scsi_debug_opt_blks, int, S_IRUGO); 4009module_param_named(opt_blks, sdebug_opt_blks, int, S_IRUGO);
4097module_param_named(opts, scsi_debug_opts, int, S_IRUGO | S_IWUSR); 4010module_param_named(opts, sdebug_opts, int, S_IRUGO | S_IWUSR);
4098module_param_named(physblk_exp, scsi_debug_physblk_exp, int, S_IRUGO); 4011module_param_named(physblk_exp, sdebug_physblk_exp, int, S_IRUGO);
4099module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR); 4012module_param_named(ptype, sdebug_ptype, int, S_IRUGO | S_IWUSR);
4100module_param_named(removable, scsi_debug_removable, bool, S_IRUGO | S_IWUSR); 4013module_param_named(removable, sdebug_removable, bool, S_IRUGO | S_IWUSR);
4101module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO); 4014module_param_named(scsi_level, sdebug_scsi_level, int, S_IRUGO);
4102module_param_named(sector_size, scsi_debug_sector_size, int, S_IRUGO); 4015module_param_named(sector_size, sdebug_sector_size, int, S_IRUGO);
4103module_param_named(strict, scsi_debug_strict, bool, S_IRUGO | S_IWUSR); 4016module_param_named(strict, sdebug_strict, bool, S_IRUGO | S_IWUSR);
4104module_param_named(unmap_alignment, scsi_debug_unmap_alignment, int, S_IRUGO); 4017module_param_named(unmap_alignment, sdebug_unmap_alignment, int, S_IRUGO);
4105module_param_named(unmap_granularity, scsi_debug_unmap_granularity, int, S_IRUGO); 4018module_param_named(unmap_granularity, sdebug_unmap_granularity, int, S_IRUGO);
4106module_param_named(unmap_max_blocks, scsi_debug_unmap_max_blocks, int, S_IRUGO); 4019module_param_named(unmap_max_blocks, sdebug_unmap_max_blocks, int, S_IRUGO);
4107module_param_named(unmap_max_desc, scsi_debug_unmap_max_desc, int, S_IRUGO); 4020module_param_named(unmap_max_desc, sdebug_unmap_max_desc, int, S_IRUGO);
4108module_param_named(virtual_gb, scsi_debug_virtual_gb, int, S_IRUGO | S_IWUSR); 4021module_param_named(virtual_gb, sdebug_virtual_gb, int, S_IRUGO | S_IWUSR);
4109module_param_named(vpd_use_hostno, scsi_debug_vpd_use_hostno, int, 4022module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int,
4110 S_IRUGO | S_IWUSR); 4023 S_IRUGO | S_IWUSR);
4111module_param_named(write_same_length, scsi_debug_write_same_length, int, 4024module_param_named(write_same_length, sdebug_write_same_length, int,
4112 S_IRUGO | S_IWUSR); 4025 S_IRUGO | S_IWUSR);
4113 4026
4114MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); 4027MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert");
@@ -4162,8 +4075,7 @@ static const char * scsi_debug_info(struct Scsi_Host * shp)
4162{ 4075{
4163 sprintf(sdebug_info, "scsi_debug, version %s [%s], " 4076 sprintf(sdebug_info, "scsi_debug, version %s [%s], "
4164 "dev_size_mb=%d, opts=0x%x", SCSI_DEBUG_VERSION, 4077 "dev_size_mb=%d, opts=0x%x", SCSI_DEBUG_VERSION,
4165 scsi_debug_version_date, scsi_debug_dev_size_mb, 4078 sdebug_version_date, sdebug_dev_size_mb, sdebug_opts);
4166 scsi_debug_opts);
4167 return sdebug_info; 4079 return sdebug_info;
4168} 4080}
4169 4081
@@ -4180,8 +4092,10 @@ static int scsi_debug_write_info(struct Scsi_Host *host, char *buffer, int lengt
4180 arr[minLen] = '\0'; 4092 arr[minLen] = '\0';
4181 if (1 != sscanf(arr, "%d", &opts)) 4093 if (1 != sscanf(arr, "%d", &opts))
4182 return -EINVAL; 4094 return -EINVAL;
4183 scsi_debug_opts = opts; 4095 sdebug_opts = opts;
4184 if (scsi_debug_every_nth != 0) 4096 sdebug_verbose = !!(SDEBUG_OPT_NOISE & opts);
4097 sdebug_any_injecting_opt = !!(SDEBUG_OPT_ALL_INJECTING & opts);
4098 if (sdebug_every_nth != 0)
4185 atomic_set(&sdebug_cmnd_count, 0); 4099 atomic_set(&sdebug_cmnd_count, 0);
4186 return length; 4100 return length;
4187} 4101}
@@ -4194,9 +4108,9 @@ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host)
4194 int f, l; 4108 int f, l;
4195 char b[32]; 4109 char b[32];
4196 4110
4197 if (scsi_debug_every_nth > 0) 4111 if (sdebug_every_nth > 0)
4198 snprintf(b, sizeof(b), " (curr:%d)", 4112 snprintf(b, sizeof(b), " (curr:%d)",
4199 ((SCSI_DEBUG_OPT_RARE_TSF & scsi_debug_opts) ? 4113 ((SDEBUG_OPT_RARE_TSF & sdebug_opts) ?
4200 atomic_read(&sdebug_a_tsf) : 4114 atomic_read(&sdebug_a_tsf) :
4201 atomic_read(&sdebug_cmnd_count))); 4115 atomic_read(&sdebug_cmnd_count)));
4202 else 4116 else
@@ -4210,18 +4124,18 @@ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host)
4210 "command aborts=%d; RESETs: device=%d, target=%d, bus=%d, " 4124 "command aborts=%d; RESETs: device=%d, target=%d, bus=%d, "
4211 "host=%d\ndix_reads=%d dix_writes=%d dif_errors=%d " 4125 "host=%d\ndix_reads=%d dix_writes=%d dif_errors=%d "
4212 "usec_in_jiffy=%lu\n", 4126 "usec_in_jiffy=%lu\n",
4213 SCSI_DEBUG_VERSION, scsi_debug_version_date, 4127 SCSI_DEBUG_VERSION, sdebug_version_date,
4214 scsi_debug_num_tgts, scsi_debug_dev_size_mb, scsi_debug_opts, 4128 sdebug_num_tgts, sdebug_dev_size_mb, sdebug_opts,
4215 scsi_debug_every_nth, b, scsi_debug_delay, scsi_debug_ndelay, 4129 sdebug_every_nth, b, sdebug_delay, sdebug_ndelay,
4216 scsi_debug_max_luns, atomic_read(&sdebug_completions), 4130 sdebug_max_luns, atomic_read(&sdebug_completions),
4217 scsi_debug_sector_size, sdebug_cylinders_per, sdebug_heads, 4131 sdebug_sector_size, sdebug_cylinders_per, sdebug_heads,
4218 sdebug_sectors_per, num_aborts, num_dev_resets, 4132 sdebug_sectors_per, num_aborts, num_dev_resets,
4219 num_target_resets, num_bus_resets, num_host_resets, 4133 num_target_resets, num_bus_resets, num_host_resets,
4220 dix_reads, dix_writes, dif_errors, TICK_NSEC / 1000); 4134 dix_reads, dix_writes, dif_errors, TICK_NSEC / 1000);
4221 4135
4222 f = find_first_bit(queued_in_use_bm, scsi_debug_max_queue); 4136 f = find_first_bit(queued_in_use_bm, sdebug_max_queue);
4223 if (f != scsi_debug_max_queue) { 4137 if (f != sdebug_max_queue) {
4224 l = find_last_bit(queued_in_use_bm, scsi_debug_max_queue); 4138 l = find_last_bit(queued_in_use_bm, sdebug_max_queue);
4225 seq_printf(m, " %s BUSY: first,last bits set: %d,%d\n", 4139 seq_printf(m, " %s BUSY: first,last bits set: %d,%d\n",
4226 "queued_in_use_bm", f, l); 4140 "queued_in_use_bm", f, l);
4227 } 4141 }
@@ -4230,7 +4144,7 @@ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host)
4230 4144
4231static ssize_t delay_show(struct device_driver *ddp, char *buf) 4145static ssize_t delay_show(struct device_driver *ddp, char *buf)
4232{ 4146{
4233 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_delay); 4147 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_delay);
4234} 4148}
4235/* Returns -EBUSY if delay is being changed and commands are queued */ 4149/* Returns -EBUSY if delay is being changed and commands are queued */
4236static ssize_t delay_store(struct device_driver *ddp, const char *buf, 4150static ssize_t delay_store(struct device_driver *ddp, const char *buf,
@@ -4240,18 +4154,17 @@ static ssize_t delay_store(struct device_driver *ddp, const char *buf,
4240 4154
4241 if ((count > 0) && (1 == sscanf(buf, "%d", &delay))) { 4155 if ((count > 0) && (1 == sscanf(buf, "%d", &delay))) {
4242 res = count; 4156 res = count;
4243 if (scsi_debug_delay != delay) { 4157 if (sdebug_delay != delay) {
4244 unsigned long iflags; 4158 unsigned long iflags;
4245 int k; 4159 int k;
4246 4160
4247 spin_lock_irqsave(&queued_arr_lock, iflags); 4161 spin_lock_irqsave(&queued_arr_lock, iflags);
4248 k = find_first_bit(queued_in_use_bm, 4162 k = find_first_bit(queued_in_use_bm, sdebug_max_queue);
4249 scsi_debug_max_queue); 4163 if (k != sdebug_max_queue)
4250 if (k != scsi_debug_max_queue)
4251 res = -EBUSY; /* have queued commands */ 4164 res = -EBUSY; /* have queued commands */
4252 else { 4165 else {
4253 scsi_debug_delay = delay; 4166 sdebug_delay = delay;
4254 scsi_debug_ndelay = 0; 4167 sdebug_ndelay = 0;
4255 } 4168 }
4256 spin_unlock_irqrestore(&queued_arr_lock, iflags); 4169 spin_unlock_irqrestore(&queued_arr_lock, iflags);
4257 } 4170 }
@@ -4263,10 +4176,10 @@ static DRIVER_ATTR_RW(delay);
4263 4176
4264static ssize_t ndelay_show(struct device_driver *ddp, char *buf) 4177static ssize_t ndelay_show(struct device_driver *ddp, char *buf)
4265{ 4178{
4266 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_ndelay); 4179 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_ndelay);
4267} 4180}
4268/* Returns -EBUSY if ndelay is being changed and commands are queued */ 4181/* Returns -EBUSY if ndelay is being changed and commands are queued */
4269/* If > 0 and accepted then scsi_debug_delay is set to DELAY_OVERRIDDEN */ 4182/* If > 0 and accepted then sdebug_delay is set to DELAY_OVERRIDDEN */
4270static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, 4183static ssize_t ndelay_store(struct device_driver *ddp, const char *buf,
4271 size_t count) 4184 size_t count)
4272{ 4185{
@@ -4276,15 +4189,14 @@ static ssize_t ndelay_store(struct device_driver *ddp, const char *buf,
4276 if ((count > 0) && (1 == sscanf(buf, "%d", &ndelay)) && 4189 if ((count > 0) && (1 == sscanf(buf, "%d", &ndelay)) &&
4277 (ndelay >= 0) && (ndelay < 1000000000)) { 4190 (ndelay >= 0) && (ndelay < 1000000000)) {
4278 res = count; 4191 res = count;
4279 if (scsi_debug_ndelay != ndelay) { 4192 if (sdebug_ndelay != ndelay) {
4280 spin_lock_irqsave(&queued_arr_lock, iflags); 4193 spin_lock_irqsave(&queued_arr_lock, iflags);
4281 k = find_first_bit(queued_in_use_bm, 4194 k = find_first_bit(queued_in_use_bm, sdebug_max_queue);
4282 scsi_debug_max_queue); 4195 if (k != sdebug_max_queue)
4283 if (k != scsi_debug_max_queue)
4284 res = -EBUSY; /* have queued commands */ 4196 res = -EBUSY; /* have queued commands */
4285 else { 4197 else {
4286 scsi_debug_ndelay = ndelay; 4198 sdebug_ndelay = ndelay;
4287 scsi_debug_delay = ndelay ? DELAY_OVERRIDDEN 4199 sdebug_delay = ndelay ? DELAY_OVERRIDDEN
4288 : DEF_DELAY; 4200 : DEF_DELAY;
4289 } 4201 }
4290 spin_unlock_irqrestore(&queued_arr_lock, iflags); 4202 spin_unlock_irqrestore(&queued_arr_lock, iflags);
@@ -4297,7 +4209,7 @@ static DRIVER_ATTR_RW(ndelay);
4297 4209
4298static ssize_t opts_show(struct device_driver *ddp, char *buf) 4210static ssize_t opts_show(struct device_driver *ddp, char *buf)
4299{ 4211{
4300 return scnprintf(buf, PAGE_SIZE, "0x%x\n", scsi_debug_opts); 4212 return scnprintf(buf, PAGE_SIZE, "0x%x\n", sdebug_opts);
4301} 4213}
4302 4214
4303static ssize_t opts_store(struct device_driver *ddp, const char *buf, 4215static ssize_t opts_store(struct device_driver *ddp, const char *buf,
@@ -4317,17 +4229,9 @@ static ssize_t opts_store(struct device_driver *ddp, const char *buf,
4317 } 4229 }
4318 return -EINVAL; 4230 return -EINVAL;
4319opts_done: 4231opts_done:
4320 scsi_debug_opts = opts; 4232 sdebug_opts = opts;
4321 if (SCSI_DEBUG_OPT_RECOVERED_ERR & opts) 4233 sdebug_verbose = !!(SDEBUG_OPT_NOISE & opts);
4322 sdebug_any_injecting_opt = true; 4234 sdebug_any_injecting_opt = !!(SDEBUG_OPT_ALL_INJECTING & opts);
4323 else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & opts)
4324 sdebug_any_injecting_opt = true;
4325 else if (SCSI_DEBUG_OPT_DIF_ERR & opts)
4326 sdebug_any_injecting_opt = true;
4327 else if (SCSI_DEBUG_OPT_DIX_ERR & opts)
4328 sdebug_any_injecting_opt = true;
4329 else if (SCSI_DEBUG_OPT_SHORT_TRANSFER & opts)
4330 sdebug_any_injecting_opt = true;
4331 atomic_set(&sdebug_cmnd_count, 0); 4235 atomic_set(&sdebug_cmnd_count, 0);
4332 atomic_set(&sdebug_a_tsf, 0); 4236 atomic_set(&sdebug_a_tsf, 0);
4333 return count; 4237 return count;
@@ -4336,7 +4240,7 @@ static DRIVER_ATTR_RW(opts);
4336 4240
4337static ssize_t ptype_show(struct device_driver *ddp, char *buf) 4241static ssize_t ptype_show(struct device_driver *ddp, char *buf)
4338{ 4242{
4339 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_ptype); 4243 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_ptype);
4340} 4244}
4341static ssize_t ptype_store(struct device_driver *ddp, const char *buf, 4245static ssize_t ptype_store(struct device_driver *ddp, const char *buf,
4342 size_t count) 4246 size_t count)
@@ -4344,7 +4248,7 @@ static ssize_t ptype_store(struct device_driver *ddp, const char *buf,
4344 int n; 4248 int n;
4345 4249
4346 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4250 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4347 scsi_debug_ptype = n; 4251 sdebug_ptype = n;
4348 return count; 4252 return count;
4349 } 4253 }
4350 return -EINVAL; 4254 return -EINVAL;
@@ -4353,7 +4257,7 @@ static DRIVER_ATTR_RW(ptype);
4353 4257
4354static ssize_t dsense_show(struct device_driver *ddp, char *buf) 4258static ssize_t dsense_show(struct device_driver *ddp, char *buf)
4355{ 4259{
4356 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dsense); 4260 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_dsense);
4357} 4261}
4358static ssize_t dsense_store(struct device_driver *ddp, const char *buf, 4262static ssize_t dsense_store(struct device_driver *ddp, const char *buf,
4359 size_t count) 4263 size_t count)
@@ -4361,7 +4265,7 @@ static ssize_t dsense_store(struct device_driver *ddp, const char *buf,
4361 int n; 4265 int n;
4362 4266
4363 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4267 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4364 scsi_debug_dsense = n; 4268 sdebug_dsense = n;
4365 return count; 4269 return count;
4366 } 4270 }
4367 return -EINVAL; 4271 return -EINVAL;
@@ -4370,7 +4274,7 @@ static DRIVER_ATTR_RW(dsense);
4370 4274
4371static ssize_t fake_rw_show(struct device_driver *ddp, char *buf) 4275static ssize_t fake_rw_show(struct device_driver *ddp, char *buf)
4372{ 4276{
4373 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_fake_rw); 4277 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_fake_rw);
4374} 4278}
4375static ssize_t fake_rw_store(struct device_driver *ddp, const char *buf, 4279static ssize_t fake_rw_store(struct device_driver *ddp, const char *buf,
4376 size_t count) 4280 size_t count)
@@ -4379,11 +4283,11 @@ static ssize_t fake_rw_store(struct device_driver *ddp, const char *buf,
4379 4283
4380 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4284 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4381 n = (n > 0); 4285 n = (n > 0);
4382 scsi_debug_fake_rw = (scsi_debug_fake_rw > 0); 4286 sdebug_fake_rw = (sdebug_fake_rw > 0);
4383 if (scsi_debug_fake_rw != n) { 4287 if (sdebug_fake_rw != n) {
4384 if ((0 == n) && (NULL == fake_storep)) { 4288 if ((0 == n) && (NULL == fake_storep)) {
4385 unsigned long sz = 4289 unsigned long sz =
4386 (unsigned long)scsi_debug_dev_size_mb * 4290 (unsigned long)sdebug_dev_size_mb *
4387 1048576; 4291 1048576;
4388 4292
4389 fake_storep = vmalloc(sz); 4293 fake_storep = vmalloc(sz);
@@ -4393,7 +4297,7 @@ static ssize_t fake_rw_store(struct device_driver *ddp, const char *buf,
4393 } 4297 }
4394 memset(fake_storep, 0, sz); 4298 memset(fake_storep, 0, sz);
4395 } 4299 }
4396 scsi_debug_fake_rw = n; 4300 sdebug_fake_rw = n;
4397 } 4301 }
4398 return count; 4302 return count;
4399 } 4303 }
@@ -4403,7 +4307,7 @@ static DRIVER_ATTR_RW(fake_rw);
4403 4307
4404static ssize_t no_lun_0_show(struct device_driver *ddp, char *buf) 4308static ssize_t no_lun_0_show(struct device_driver *ddp, char *buf)
4405{ 4309{
4406 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_lun_0); 4310 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_no_lun_0);
4407} 4311}
4408static ssize_t no_lun_0_store(struct device_driver *ddp, const char *buf, 4312static ssize_t no_lun_0_store(struct device_driver *ddp, const char *buf,
4409 size_t count) 4313 size_t count)
@@ -4411,7 +4315,7 @@ static ssize_t no_lun_0_store(struct device_driver *ddp, const char *buf,
4411 int n; 4315 int n;
4412 4316
4413 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4317 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4414 scsi_debug_no_lun_0 = n; 4318 sdebug_no_lun_0 = n;
4415 return count; 4319 return count;
4416 } 4320 }
4417 return -EINVAL; 4321 return -EINVAL;
@@ -4420,7 +4324,7 @@ static DRIVER_ATTR_RW(no_lun_0);
4420 4324
4421static ssize_t num_tgts_show(struct device_driver *ddp, char *buf) 4325static ssize_t num_tgts_show(struct device_driver *ddp, char *buf)
4422{ 4326{
4423 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); 4327 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_num_tgts);
4424} 4328}
4425static ssize_t num_tgts_store(struct device_driver *ddp, const char *buf, 4329static ssize_t num_tgts_store(struct device_driver *ddp, const char *buf,
4426 size_t count) 4330 size_t count)
@@ -4428,7 +4332,7 @@ static ssize_t num_tgts_store(struct device_driver *ddp, const char *buf,
4428 int n; 4332 int n;
4429 4333
4430 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4334 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4431 scsi_debug_num_tgts = n; 4335 sdebug_num_tgts = n;
4432 sdebug_max_tgts_luns(); 4336 sdebug_max_tgts_luns();
4433 return count; 4337 return count;
4434 } 4338 }
@@ -4438,19 +4342,19 @@ static DRIVER_ATTR_RW(num_tgts);
4438 4342
4439static ssize_t dev_size_mb_show(struct device_driver *ddp, char *buf) 4343static ssize_t dev_size_mb_show(struct device_driver *ddp, char *buf)
4440{ 4344{
4441 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dev_size_mb); 4345 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_dev_size_mb);
4442} 4346}
4443static DRIVER_ATTR_RO(dev_size_mb); 4347static DRIVER_ATTR_RO(dev_size_mb);
4444 4348
4445static ssize_t num_parts_show(struct device_driver *ddp, char *buf) 4349static ssize_t num_parts_show(struct device_driver *ddp, char *buf)
4446{ 4350{
4447 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_parts); 4351 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_num_parts);
4448} 4352}
4449static DRIVER_ATTR_RO(num_parts); 4353static DRIVER_ATTR_RO(num_parts);
4450 4354
4451static ssize_t every_nth_show(struct device_driver *ddp, char *buf) 4355static ssize_t every_nth_show(struct device_driver *ddp, char *buf)
4452{ 4356{
4453 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_every_nth); 4357 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_every_nth);
4454} 4358}
4455static ssize_t every_nth_store(struct device_driver *ddp, const char *buf, 4359static ssize_t every_nth_store(struct device_driver *ddp, const char *buf,
4456 size_t count) 4360 size_t count)
@@ -4458,7 +4362,7 @@ static ssize_t every_nth_store(struct device_driver *ddp, const char *buf,
4458 int nth; 4362 int nth;
4459 4363
4460 if ((count > 0) && (1 == sscanf(buf, "%d", &nth))) { 4364 if ((count > 0) && (1 == sscanf(buf, "%d", &nth))) {
4461 scsi_debug_every_nth = nth; 4365 sdebug_every_nth = nth;
4462 atomic_set(&sdebug_cmnd_count, 0); 4366 atomic_set(&sdebug_cmnd_count, 0);
4463 return count; 4367 return count;
4464 } 4368 }
@@ -4468,7 +4372,7 @@ static DRIVER_ATTR_RW(every_nth);
4468 4372
4469static ssize_t max_luns_show(struct device_driver *ddp, char *buf) 4373static ssize_t max_luns_show(struct device_driver *ddp, char *buf)
4470{ 4374{
4471 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_luns); 4375 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_max_luns);
4472} 4376}
4473static ssize_t max_luns_store(struct device_driver *ddp, const char *buf, 4377static ssize_t max_luns_store(struct device_driver *ddp, const char *buf,
4474 size_t count) 4378 size_t count)
@@ -4477,10 +4381,10 @@ static ssize_t max_luns_store(struct device_driver *ddp, const char *buf,
4477 bool changed; 4381 bool changed;
4478 4382
4479 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4383 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4480 changed = (scsi_debug_max_luns != n); 4384 changed = (sdebug_max_luns != n);
4481 scsi_debug_max_luns = n; 4385 sdebug_max_luns = n;
4482 sdebug_max_tgts_luns(); 4386 sdebug_max_tgts_luns();
4483 if (changed && (scsi_debug_scsi_level >= 5)) { /* >= SPC-3 */ 4387 if (changed && (sdebug_scsi_level >= 5)) { /* >= SPC-3 */
4484 struct sdebug_host_info *sdhp; 4388 struct sdebug_host_info *sdhp;
4485 struct sdebug_dev_info *dp; 4389 struct sdebug_dev_info *dp;
4486 4390
@@ -4503,7 +4407,7 @@ static DRIVER_ATTR_RW(max_luns);
4503 4407
4504static ssize_t max_queue_show(struct device_driver *ddp, char *buf) 4408static ssize_t max_queue_show(struct device_driver *ddp, char *buf)
4505{ 4409{
4506 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_queue); 4410 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_max_queue);
4507} 4411}
4508/* N.B. max_queue can be changed while there are queued commands. In flight 4412/* N.B. max_queue can be changed while there are queued commands. In flight
4509 * commands beyond the new max_queue will be completed. */ 4413 * commands beyond the new max_queue will be completed. */
@@ -4517,7 +4421,7 @@ static ssize_t max_queue_store(struct device_driver *ddp, const char *buf,
4517 (n <= SCSI_DEBUG_CANQUEUE)) { 4421 (n <= SCSI_DEBUG_CANQUEUE)) {
4518 spin_lock_irqsave(&queued_arr_lock, iflags); 4422 spin_lock_irqsave(&queued_arr_lock, iflags);
4519 k = find_last_bit(queued_in_use_bm, SCSI_DEBUG_CANQUEUE); 4423 k = find_last_bit(queued_in_use_bm, SCSI_DEBUG_CANQUEUE);
4520 scsi_debug_max_queue = n; 4424 sdebug_max_queue = n;
4521 if (SCSI_DEBUG_CANQUEUE == k) 4425 if (SCSI_DEBUG_CANQUEUE == k)
4522 atomic_set(&retired_max_queue, 0); 4426 atomic_set(&retired_max_queue, 0);
4523 else if (k >= n) 4427 else if (k >= n)
@@ -4533,19 +4437,19 @@ static DRIVER_ATTR_RW(max_queue);
4533 4437
4534static ssize_t no_uld_show(struct device_driver *ddp, char *buf) 4438static ssize_t no_uld_show(struct device_driver *ddp, char *buf)
4535{ 4439{
4536 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_uld); 4440 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_no_uld);
4537} 4441}
4538static DRIVER_ATTR_RO(no_uld); 4442static DRIVER_ATTR_RO(no_uld);
4539 4443
4540static ssize_t scsi_level_show(struct device_driver *ddp, char *buf) 4444static ssize_t scsi_level_show(struct device_driver *ddp, char *buf)
4541{ 4445{
4542 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_scsi_level); 4446 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_scsi_level);
4543} 4447}
4544static DRIVER_ATTR_RO(scsi_level); 4448static DRIVER_ATTR_RO(scsi_level);
4545 4449
4546static ssize_t virtual_gb_show(struct device_driver *ddp, char *buf) 4450static ssize_t virtual_gb_show(struct device_driver *ddp, char *buf)
4547{ 4451{
4548 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_virtual_gb); 4452 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_virtual_gb);
4549} 4453}
4550static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf, 4454static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf,
4551 size_t count) 4455 size_t count)
@@ -4554,8 +4458,8 @@ static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf,
4554 bool changed; 4458 bool changed;
4555 4459
4556 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4460 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4557 changed = (scsi_debug_virtual_gb != n); 4461 changed = (sdebug_virtual_gb != n);
4558 scsi_debug_virtual_gb = n; 4462 sdebug_virtual_gb = n;
4559 sdebug_capacity = get_sdebug_capacity(); 4463 sdebug_capacity = get_sdebug_capacity();
4560 if (changed) { 4464 if (changed) {
4561 struct sdebug_host_info *sdhp; 4465 struct sdebug_host_info *sdhp;
@@ -4580,7 +4484,7 @@ static DRIVER_ATTR_RW(virtual_gb);
4580 4484
4581static ssize_t add_host_show(struct device_driver *ddp, char *buf) 4485static ssize_t add_host_show(struct device_driver *ddp, char *buf)
4582{ 4486{
4583 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); 4487 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_add_host);
4584} 4488}
4585 4489
4586static ssize_t add_host_store(struct device_driver *ddp, const char *buf, 4490static ssize_t add_host_store(struct device_driver *ddp, const char *buf,
@@ -4605,7 +4509,7 @@ static DRIVER_ATTR_RW(add_host);
4605 4509
4606static ssize_t vpd_use_hostno_show(struct device_driver *ddp, char *buf) 4510static ssize_t vpd_use_hostno_show(struct device_driver *ddp, char *buf)
4607{ 4511{
4608 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_vpd_use_hostno); 4512 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_vpd_use_hostno);
4609} 4513}
4610static ssize_t vpd_use_hostno_store(struct device_driver *ddp, const char *buf, 4514static ssize_t vpd_use_hostno_store(struct device_driver *ddp, const char *buf,
4611 size_t count) 4515 size_t count)
@@ -4613,7 +4517,7 @@ static ssize_t vpd_use_hostno_store(struct device_driver *ddp, const char *buf,
4613 int n; 4517 int n;
4614 4518
4615 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4519 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4616 scsi_debug_vpd_use_hostno = n; 4520 sdebug_vpd_use_hostno = n;
4617 return count; 4521 return count;
4618 } 4522 }
4619 return -EINVAL; 4523 return -EINVAL;
@@ -4622,31 +4526,31 @@ static DRIVER_ATTR_RW(vpd_use_hostno);
4622 4526
4623static ssize_t sector_size_show(struct device_driver *ddp, char *buf) 4527static ssize_t sector_size_show(struct device_driver *ddp, char *buf)
4624{ 4528{
4625 return scnprintf(buf, PAGE_SIZE, "%u\n", scsi_debug_sector_size); 4529 return scnprintf(buf, PAGE_SIZE, "%u\n", sdebug_sector_size);
4626} 4530}
4627static DRIVER_ATTR_RO(sector_size); 4531static DRIVER_ATTR_RO(sector_size);
4628 4532
4629static ssize_t dix_show(struct device_driver *ddp, char *buf) 4533static ssize_t dix_show(struct device_driver *ddp, char *buf)
4630{ 4534{
4631 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dix); 4535 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_dix);
4632} 4536}
4633static DRIVER_ATTR_RO(dix); 4537static DRIVER_ATTR_RO(dix);
4634 4538
4635static ssize_t dif_show(struct device_driver *ddp, char *buf) 4539static ssize_t dif_show(struct device_driver *ddp, char *buf)
4636{ 4540{
4637 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dif); 4541 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_dif);
4638} 4542}
4639static DRIVER_ATTR_RO(dif); 4543static DRIVER_ATTR_RO(dif);
4640 4544
4641static ssize_t guard_show(struct device_driver *ddp, char *buf) 4545static ssize_t guard_show(struct device_driver *ddp, char *buf)
4642{ 4546{
4643 return scnprintf(buf, PAGE_SIZE, "%u\n", scsi_debug_guard); 4547 return scnprintf(buf, PAGE_SIZE, "%u\n", sdebug_guard);
4644} 4548}
4645static DRIVER_ATTR_RO(guard); 4549static DRIVER_ATTR_RO(guard);
4646 4550
4647static ssize_t ato_show(struct device_driver *ddp, char *buf) 4551static ssize_t ato_show(struct device_driver *ddp, char *buf)
4648{ 4552{
4649 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_ato); 4553 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_ato);
4650} 4554}
4651static DRIVER_ATTR_RO(ato); 4555static DRIVER_ATTR_RO(ato);
4652 4556
@@ -4669,7 +4573,7 @@ static DRIVER_ATTR_RO(map);
4669 4573
4670static ssize_t removable_show(struct device_driver *ddp, char *buf) 4574static ssize_t removable_show(struct device_driver *ddp, char *buf)
4671{ 4575{
4672 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_removable ? 1 : 0); 4576 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_removable ? 1 : 0);
4673} 4577}
4674static ssize_t removable_store(struct device_driver *ddp, const char *buf, 4578static ssize_t removable_store(struct device_driver *ddp, const char *buf,
4675 size_t count) 4579 size_t count)
@@ -4677,7 +4581,7 @@ static ssize_t removable_store(struct device_driver *ddp, const char *buf,
4677 int n; 4581 int n;
4678 4582
4679 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4583 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4680 scsi_debug_removable = (n > 0); 4584 sdebug_removable = (n > 0);
4681 return count; 4585 return count;
4682 } 4586 }
4683 return -EINVAL; 4587 return -EINVAL;
@@ -4686,7 +4590,7 @@ static DRIVER_ATTR_RW(removable);
4686 4590
4687static ssize_t host_lock_show(struct device_driver *ddp, char *buf) 4591static ssize_t host_lock_show(struct device_driver *ddp, char *buf)
4688{ 4592{
4689 return scnprintf(buf, PAGE_SIZE, "%d\n", !!scsi_debug_host_lock); 4593 return scnprintf(buf, PAGE_SIZE, "%d\n", !!sdebug_host_lock);
4690} 4594}
4691/* Returns -EBUSY if host_lock is being changed and commands are queued */ 4595/* Returns -EBUSY if host_lock is being changed and commands are queued */
4692static ssize_t host_lock_store(struct device_driver *ddp, const char *buf, 4596static ssize_t host_lock_store(struct device_driver *ddp, const char *buf,
@@ -4698,17 +4602,17 @@ static ssize_t host_lock_store(struct device_driver *ddp, const char *buf,
4698 bool new_host_lock = (n > 0); 4602 bool new_host_lock = (n > 0);
4699 4603
4700 res = count; 4604 res = count;
4701 if (new_host_lock != scsi_debug_host_lock) { 4605 if (new_host_lock != sdebug_host_lock) {
4702 unsigned long iflags; 4606 unsigned long iflags;
4703 int k; 4607 int k;
4704 4608
4705 spin_lock_irqsave(&queued_arr_lock, iflags); 4609 spin_lock_irqsave(&queued_arr_lock, iflags);
4706 k = find_first_bit(queued_in_use_bm, 4610 k = find_first_bit(queued_in_use_bm,
4707 scsi_debug_max_queue); 4611 sdebug_max_queue);
4708 if (k != scsi_debug_max_queue) 4612 if (k != sdebug_max_queue)
4709 res = -EBUSY; /* have queued commands */ 4613 res = -EBUSY; /* have queued commands */
4710 else 4614 else
4711 scsi_debug_host_lock = new_host_lock; 4615 sdebug_host_lock = new_host_lock;
4712 spin_unlock_irqrestore(&queued_arr_lock, iflags); 4616 spin_unlock_irqrestore(&queued_arr_lock, iflags);
4713 } 4617 }
4714 return res; 4618 return res;
@@ -4719,7 +4623,7 @@ static DRIVER_ATTR_RW(host_lock);
4719 4623
4720static ssize_t strict_show(struct device_driver *ddp, char *buf) 4624static ssize_t strict_show(struct device_driver *ddp, char *buf)
4721{ 4625{
4722 return scnprintf(buf, PAGE_SIZE, "%d\n", !!scsi_debug_strict); 4626 return scnprintf(buf, PAGE_SIZE, "%d\n", !!sdebug_strict);
4723} 4627}
4724static ssize_t strict_store(struct device_driver *ddp, const char *buf, 4628static ssize_t strict_store(struct device_driver *ddp, const char *buf,
4725 size_t count) 4629 size_t count)
@@ -4727,7 +4631,7 @@ static ssize_t strict_store(struct device_driver *ddp, const char *buf,
4727 int n; 4631 int n;
4728 4632
4729 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4633 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4730 scsi_debug_strict = (n > 0); 4634 sdebug_strict = (n > 0);
4731 return count; 4635 return count;
4732 } 4636 }
4733 return -EINVAL; 4637 return -EINVAL;
@@ -4787,24 +4691,24 @@ static int __init scsi_debug_init(void)
4787 atomic_set(&sdebug_completions, 0); 4691 atomic_set(&sdebug_completions, 0);
4788 atomic_set(&retired_max_queue, 0); 4692 atomic_set(&retired_max_queue, 0);
4789 4693
4790 if (scsi_debug_ndelay >= 1000000000) { 4694 if (sdebug_ndelay >= 1000 * 1000 * 1000) {
4791 pr_warn("ndelay must be less than 1 second, ignored\n"); 4695 pr_warn("ndelay must be less than 1 second, ignored\n");
4792 scsi_debug_ndelay = 0; 4696 sdebug_ndelay = 0;
4793 } else if (scsi_debug_ndelay > 0) 4697 } else if (sdebug_ndelay > 0)
4794 scsi_debug_delay = DELAY_OVERRIDDEN; 4698 sdebug_delay = DELAY_OVERRIDDEN;
4795 4699
4796 switch (scsi_debug_sector_size) { 4700 switch (sdebug_sector_size) {
4797 case 512: 4701 case 512:
4798 case 1024: 4702 case 1024:
4799 case 2048: 4703 case 2048:
4800 case 4096: 4704 case 4096:
4801 break; 4705 break;
4802 default: 4706 default:
4803 pr_err("invalid sector_size %d\n", scsi_debug_sector_size); 4707 pr_err("invalid sector_size %d\n", sdebug_sector_size);
4804 return -EINVAL; 4708 return -EINVAL;
4805 } 4709 }
4806 4710
4807 switch (scsi_debug_dif) { 4711 switch (sdebug_dif) {
4808 4712
4809 case SD_DIF_TYPE0_PROTECTION: 4713 case SD_DIF_TYPE0_PROTECTION:
4810 case SD_DIF_TYPE1_PROTECTION: 4714 case SD_DIF_TYPE1_PROTECTION:
@@ -4817,39 +4721,38 @@ static int __init scsi_debug_init(void)
4817 return -EINVAL; 4721 return -EINVAL;
4818 } 4722 }
4819 4723
4820 if (scsi_debug_guard > 1) { 4724 if (sdebug_guard > 1) {
4821 pr_err("guard must be 0 or 1\n"); 4725 pr_err("guard must be 0 or 1\n");
4822 return -EINVAL; 4726 return -EINVAL;
4823 } 4727 }
4824 4728
4825 if (scsi_debug_ato > 1) { 4729 if (sdebug_ato > 1) {
4826 pr_err("ato must be 0 or 1\n"); 4730 pr_err("ato must be 0 or 1\n");
4827 return -EINVAL; 4731 return -EINVAL;
4828 } 4732 }
4829 4733
4830 if (scsi_debug_physblk_exp > 15) { 4734 if (sdebug_physblk_exp > 15) {
4831 pr_err("invalid physblk_exp %u\n", scsi_debug_physblk_exp); 4735 pr_err("invalid physblk_exp %u\n", sdebug_physblk_exp);
4832 return -EINVAL; 4736 return -EINVAL;
4833 } 4737 }
4834 4738
4835 if (scsi_debug_lowest_aligned > 0x3fff) { 4739 if (sdebug_lowest_aligned > 0x3fff) {
4836 pr_err("lowest_aligned too big: %u\n", 4740 pr_err("lowest_aligned too big: %u\n", sdebug_lowest_aligned);
4837 scsi_debug_lowest_aligned);
4838 return -EINVAL; 4741 return -EINVAL;
4839 } 4742 }
4840 4743
4841 if (scsi_debug_dev_size_mb < 1) 4744 if (sdebug_dev_size_mb < 1)
4842 scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */ 4745 sdebug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
4843 sz = (unsigned long)scsi_debug_dev_size_mb * 1048576; 4746 sz = (unsigned long)sdebug_dev_size_mb * 1048576;
4844 sdebug_store_sectors = sz / scsi_debug_sector_size; 4747 sdebug_store_sectors = sz / sdebug_sector_size;
4845 sdebug_capacity = get_sdebug_capacity(); 4748 sdebug_capacity = get_sdebug_capacity();
4846 4749
4847 /* play around with geometry, don't waste too much on track 0 */ 4750 /* play around with geometry, don't waste too much on track 0 */
4848 sdebug_heads = 8; 4751 sdebug_heads = 8;
4849 sdebug_sectors_per = 32; 4752 sdebug_sectors_per = 32;
4850 if (scsi_debug_dev_size_mb >= 256) 4753 if (sdebug_dev_size_mb >= 256)
4851 sdebug_heads = 64; 4754 sdebug_heads = 64;
4852 else if (scsi_debug_dev_size_mb >= 16) 4755 else if (sdebug_dev_size_mb >= 16)
4853 sdebug_heads = 32; 4756 sdebug_heads = 32;
4854 sdebug_cylinders_per = (unsigned long)sdebug_capacity / 4757 sdebug_cylinders_per = (unsigned long)sdebug_capacity /
4855 (sdebug_sectors_per * sdebug_heads); 4758 (sdebug_sectors_per * sdebug_heads);
@@ -4861,18 +4764,18 @@ static int __init scsi_debug_init(void)
4861 (sdebug_sectors_per * sdebug_heads); 4764 (sdebug_sectors_per * sdebug_heads);
4862 } 4765 }
4863 4766
4864 if (0 == scsi_debug_fake_rw) { 4767 if (0 == sdebug_fake_rw) {
4865 fake_storep = vmalloc(sz); 4768 fake_storep = vmalloc(sz);
4866 if (NULL == fake_storep) { 4769 if (NULL == fake_storep) {
4867 pr_err("out of memory, 1\n"); 4770 pr_err("out of memory, 1\n");
4868 return -ENOMEM; 4771 return -ENOMEM;
4869 } 4772 }
4870 memset(fake_storep, 0, sz); 4773 memset(fake_storep, 0, sz);
4871 if (scsi_debug_num_parts > 0) 4774 if (sdebug_num_parts > 0)
4872 sdebug_build_parts(fake_storep, sz); 4775 sdebug_build_parts(fake_storep, sz);
4873 } 4776 }
4874 4777
4875 if (scsi_debug_dix) { 4778 if (sdebug_dix) {
4876 int dif_size; 4779 int dif_size;
4877 4780
4878 dif_size = sdebug_store_sectors * sizeof(struct sd_dif_tuple); 4781 dif_size = sdebug_store_sectors * sizeof(struct sd_dif_tuple);
@@ -4891,18 +4794,18 @@ static int __init scsi_debug_init(void)
4891 4794
4892 /* Logical Block Provisioning */ 4795 /* Logical Block Provisioning */
4893 if (scsi_debug_lbp()) { 4796 if (scsi_debug_lbp()) {
4894 scsi_debug_unmap_max_blocks = 4797 sdebug_unmap_max_blocks =
4895 clamp(scsi_debug_unmap_max_blocks, 0U, 0xffffffffU); 4798 clamp(sdebug_unmap_max_blocks, 0U, 0xffffffffU);
4896 4799
4897 scsi_debug_unmap_max_desc = 4800 sdebug_unmap_max_desc =
4898 clamp(scsi_debug_unmap_max_desc, 0U, 256U); 4801 clamp(sdebug_unmap_max_desc, 0U, 256U);
4899 4802
4900 scsi_debug_unmap_granularity = 4803 sdebug_unmap_granularity =
4901 clamp(scsi_debug_unmap_granularity, 1U, 0xffffffffU); 4804 clamp(sdebug_unmap_granularity, 1U, 0xffffffffU);
4902 4805
4903 if (scsi_debug_unmap_alignment && 4806 if (sdebug_unmap_alignment &&
4904 scsi_debug_unmap_granularity <= 4807 sdebug_unmap_granularity <=
4905 scsi_debug_unmap_alignment) { 4808 sdebug_unmap_alignment) {
4906 pr_err("ERR: unmap_granularity <= unmap_alignment\n"); 4809 pr_err("ERR: unmap_granularity <= unmap_alignment\n");
4907 return -EINVAL; 4810 return -EINVAL;
4908 } 4811 }
@@ -4921,7 +4824,7 @@ static int __init scsi_debug_init(void)
4921 bitmap_zero(map_storep, map_size); 4824 bitmap_zero(map_storep, map_size);
4922 4825
4923 /* Map first 1KB for partition table */ 4826 /* Map first 1KB for partition table */
4924 if (scsi_debug_num_parts) 4827 if (sdebug_num_parts)
4925 map_region(0, 2); 4828 map_region(0, 2);
4926 } 4829 }
4927 4830
@@ -4942,8 +4845,8 @@ static int __init scsi_debug_init(void)
4942 goto bus_unreg; 4845 goto bus_unreg;
4943 } 4846 }
4944 4847
4945 host_to_add = scsi_debug_add_host; 4848 host_to_add = sdebug_add_host;
4946 scsi_debug_add_host = 0; 4849 sdebug_add_host = 0;
4947 4850
4948 for (k = 0; k < host_to_add; k++) { 4851 for (k = 0; k < host_to_add; k++) {
4949 if (sdebug_add_adapter()) { 4852 if (sdebug_add_adapter()) {
@@ -4952,8 +4855,8 @@ static int __init scsi_debug_init(void)
4952 } 4855 }
4953 } 4856 }
4954 4857
4955 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 4858 if (sdebug_verbose)
4956 pr_info("built %d host(s)\n", scsi_debug_add_host); 4859 pr_info("built %d host(s)\n", sdebug_add_host);
4957 4860
4958 return 0; 4861 return 0;
4959 4862
@@ -4971,7 +4874,7 @@ free_vm:
4971 4874
4972static void __exit scsi_debug_exit(void) 4875static void __exit scsi_debug_exit(void)
4973{ 4876{
4974 int k = scsi_debug_add_host; 4877 int k = sdebug_add_host;
4975 4878
4976 stop_all_queued(); 4879 stop_all_queued();
4977 free_all_queued(); 4880 free_all_queued();
@@ -5011,7 +4914,7 @@ static int sdebug_add_adapter(void)
5011 4914
5012 INIT_LIST_HEAD(&sdbg_host->dev_info_list); 4915 INIT_LIST_HEAD(&sdbg_host->dev_info_list);
5013 4916
5014 devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns; 4917 devs_per_host = sdebug_num_tgts * sdebug_max_luns;
5015 for (k = 0; k < devs_per_host; k++) { 4918 for (k = 0; k < devs_per_host; k++) {
5016 sdbg_devinfo = sdebug_device_create(sdbg_host, GFP_KERNEL); 4919 sdbg_devinfo = sdebug_device_create(sdbg_host, GFP_KERNEL);
5017 if (!sdbg_devinfo) { 4920 if (!sdbg_devinfo) {
@@ -5028,14 +4931,14 @@ static int sdebug_add_adapter(void)
5028 sdbg_host->dev.bus = &pseudo_lld_bus; 4931 sdbg_host->dev.bus = &pseudo_lld_bus;
5029 sdbg_host->dev.parent = pseudo_primary; 4932 sdbg_host->dev.parent = pseudo_primary;
5030 sdbg_host->dev.release = &sdebug_release_adapter; 4933 sdbg_host->dev.release = &sdebug_release_adapter;
5031 dev_set_name(&sdbg_host->dev, "adapter%d", scsi_debug_add_host); 4934 dev_set_name(&sdbg_host->dev, "adapter%d", sdebug_add_host);
5032 4935
5033 error = device_register(&sdbg_host->dev); 4936 error = device_register(&sdbg_host->dev);
5034 4937
5035 if (error) 4938 if (error)
5036 goto clean; 4939 goto clean;
5037 4940
5038 ++scsi_debug_add_host; 4941 ++sdebug_add_host;
5039 return error; 4942 return error;
5040 4943
5041clean: 4944clean:
@@ -5064,8 +4967,8 @@ static void sdebug_remove_adapter(void)
5064 if (!sdbg_host) 4967 if (!sdbg_host)
5065 return; 4968 return;
5066 4969
5067 device_unregister(&sdbg_host->dev); 4970 device_unregister(&sdbg_host->dev);
5068 --scsi_debug_add_host; 4971 --sdebug_add_host;
5069} 4972}
5070 4973
5071static int 4974static int
@@ -5091,7 +4994,7 @@ sdebug_change_qdepth(struct scsi_device *sdev, int qdepth)
5091 qdepth = SCSI_DEBUG_CANQUEUE + 10; 4994 qdepth = SCSI_DEBUG_CANQUEUE + 10;
5092 scsi_change_queue_depth(sdev, qdepth); 4995 scsi_change_queue_depth(sdev, qdepth);
5093 4996
5094 if (SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) { 4997 if (SDEBUG_OPT_Q_NOISE & sdebug_opts) {
5095 sdev_printk(KERN_INFO, sdev, 4998 sdev_printk(KERN_INFO, sdev,
5096 "%s: qdepth=%d, num_in_q=%d\n", 4999 "%s: qdepth=%d, num_in_q=%d\n",
5097 __func__, qdepth, num_in_q); 5000 __func__, qdepth, num_in_q);
@@ -5106,28 +5009,25 @@ check_inject(struct scsi_cmnd *scp)
5106 5009
5107 memset(ep, 0, sizeof(struct sdebug_scmd_extra_t)); 5010 memset(ep, 0, sizeof(struct sdebug_scmd_extra_t));
5108 5011
5109 if (atomic_inc_return(&sdebug_cmnd_count) >= 5012 if (atomic_inc_return(&sdebug_cmnd_count) >= abs(sdebug_every_nth)) {
5110 abs(scsi_debug_every_nth)) {
5111 atomic_set(&sdebug_cmnd_count, 0); 5013 atomic_set(&sdebug_cmnd_count, 0);
5112 if (scsi_debug_every_nth < -1) 5014 if (sdebug_every_nth < -1)
5113 scsi_debug_every_nth = -1; 5015 sdebug_every_nth = -1;
5114 if (SCSI_DEBUG_OPT_TIMEOUT & scsi_debug_opts) 5016 if (SDEBUG_OPT_TIMEOUT & sdebug_opts)
5115 return 1; /* ignore command causing timeout */ 5017 return 1; /* ignore command causing timeout */
5116 else if (SCSI_DEBUG_OPT_MAC_TIMEOUT & scsi_debug_opts && 5018 else if (SDEBUG_OPT_MAC_TIMEOUT & sdebug_opts &&
5117 scsi_medium_access_command(scp)) 5019 scsi_medium_access_command(scp))
5118 return 1; /* time out reads and writes */ 5020 return 1; /* time out reads and writes */
5119 if (sdebug_any_injecting_opt) { 5021 if (sdebug_any_injecting_opt) {
5120 int opts = scsi_debug_opts; 5022 if (SDEBUG_OPT_RECOVERED_ERR & sdebug_opts)
5121
5122 if (SCSI_DEBUG_OPT_RECOVERED_ERR & opts)
5123 ep->inj_recovered = true; 5023 ep->inj_recovered = true;
5124 else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & opts) 5024 if (SDEBUG_OPT_TRANSPORT_ERR & sdebug_opts)
5125 ep->inj_transport = true; 5025 ep->inj_transport = true;
5126 else if (SCSI_DEBUG_OPT_DIF_ERR & opts) 5026 if (SDEBUG_OPT_DIF_ERR & sdebug_opts)
5127 ep->inj_dif = true; 5027 ep->inj_dif = true;
5128 else if (SCSI_DEBUG_OPT_DIX_ERR & opts) 5028 if (SDEBUG_OPT_DIX_ERR & sdebug_opts)
5129 ep->inj_dix = true; 5029 ep->inj_dix = true;
5130 else if (SCSI_DEBUG_OPT_SHORT_TRANSFER & opts) 5030 if (SDEBUG_OPT_SHORT_TRANSFER & sdebug_opts)
5131 ep->inj_short = true; 5031 ep->inj_short = true;
5132 } 5032 }
5133 } 5033 }
@@ -5146,15 +5046,13 @@ scsi_debug_queuecommand(struct scsi_cmnd *scp)
5146 int (*r_pfp)(struct scsi_cmnd *, struct sdebug_dev_info *); 5046 int (*r_pfp)(struct scsi_cmnd *, struct sdebug_dev_info *);
5147 int k, na; 5047 int k, na;
5148 int errsts = 0; 5048 int errsts = 0;
5149 int errsts_no_connect = DID_NO_CONNECT << 16;
5150 u32 flags; 5049 u32 flags;
5151 u16 sa; 5050 u16 sa;
5152 u8 opcode = cmd[0]; 5051 u8 opcode = cmd[0];
5153 bool has_wlun_rl; 5052 bool has_wlun_rl;
5154 bool debug = !!(SCSI_DEBUG_OPT_NOISE & scsi_debug_opts);
5155 5053
5156 scsi_set_resid(scp, 0); 5054 scsi_set_resid(scp, 0);
5157 if (debug && !(SCSI_DEBUG_OPT_NO_CDB_NOISE & scsi_debug_opts)) { 5055 if (sdebug_verbose && !(SDEBUG_OPT_NO_CDB_NOISE & sdebug_opts)) {
5158 char b[120]; 5056 char b[120];
5159 int n, len, sb; 5057 int n, len, sb;
5160 5058
@@ -5170,8 +5068,8 @@ scsi_debug_queuecommand(struct scsi_cmnd *scp)
5170 sdev_printk(KERN_INFO, sdp, "%s: cmd %s\n", my_name, b); 5068 sdev_printk(KERN_INFO, sdp, "%s: cmd %s\n", my_name, b);
5171 } 5069 }
5172 has_wlun_rl = (sdp->lun == SCSI_W_LUN_REPORT_LUNS); 5070 has_wlun_rl = (sdp->lun == SCSI_W_LUN_REPORT_LUNS);
5173 if ((sdp->lun >= scsi_debug_max_luns) && !has_wlun_rl) 5071 if ((sdp->lun >= sdebug_max_luns) && !has_wlun_rl)
5174 return schedule_resp(scp, NULL, errsts_no_connect, 0); 5072 return schedule_resp(scp, NULL, DID_NO_CONNECT << 16, 0);
5175 5073
5176 sdeb_i = opcode_ind_arr[opcode]; /* fully mapped */ 5074 sdeb_i = opcode_ind_arr[opcode]; /* fully mapped */
5177 oip = &opcode_info_arr[sdeb_i]; /* safe if table consistent */ 5075 oip = &opcode_info_arr[sdeb_i]; /* safe if table consistent */
@@ -5179,7 +5077,8 @@ scsi_debug_queuecommand(struct scsi_cmnd *scp)
5179 if (!devip) { 5077 if (!devip) {
5180 devip = devInfoReg(sdp); 5078 devip = devInfoReg(sdp);
5181 if (NULL == devip) 5079 if (NULL == devip)
5182 return schedule_resp(scp, NULL, errsts_no_connect, 0); 5080 return schedule_resp(scp, NULL, DID_NO_CONNECT << 16,
5081 0);
5183 } 5082 }
5184 na = oip->num_attached; 5083 na = oip->num_attached;
5185 r_pfp = oip->pfp; 5084 r_pfp = oip->pfp;
@@ -5216,13 +5115,13 @@ scsi_debug_queuecommand(struct scsi_cmnd *scp)
5216 goto check_cond; 5115 goto check_cond;
5217 } 5116 }
5218 if (has_wlun_rl && !(F_RL_WLUN_OK & flags)) { 5117 if (has_wlun_rl && !(F_RL_WLUN_OK & flags)) {
5219 if (debug) 5118 if (sdebug_verbose)
5220 sdev_printk(KERN_INFO, sdp, "scsi_debug: Opcode: " 5119 sdev_printk(KERN_INFO, sdp, "%s: Opcode 0x%x not%s\n",
5221 "0x%x not supported for wlun\n", opcode); 5120 my_name, opcode, " supported for wlun");
5222 mk_sense_invalid_opcode(scp); 5121 mk_sense_invalid_opcode(scp);
5223 goto check_cond; 5122 goto check_cond;
5224 } 5123 }
5225 if (scsi_debug_strict) { /* check cdb against mask */ 5124 if (sdebug_strict) { /* check cdb against mask */
5226 u8 rem; 5125 u8 rem;
5227 int j; 5126 int j;
5228 5127
@@ -5246,16 +5145,16 @@ scsi_debug_queuecommand(struct scsi_cmnd *scp)
5246 } 5145 }
5247 if ((F_M_ACCESS & flags) && devip->stopped) { 5146 if ((F_M_ACCESS & flags) && devip->stopped) {
5248 mk_sense_buffer(scp, NOT_READY, LOGICAL_UNIT_NOT_READY, 0x2); 5147 mk_sense_buffer(scp, NOT_READY, LOGICAL_UNIT_NOT_READY, 0x2);
5249 if (debug) 5148 if (sdebug_verbose)
5250 sdev_printk(KERN_INFO, sdp, "%s reports: Not ready: " 5149 sdev_printk(KERN_INFO, sdp, "%s reports: Not ready: "
5251 "%s\n", my_name, "initializing command " 5150 "%s\n", my_name, "initializing command "
5252 "required"); 5151 "required");
5253 errsts = check_condition_result; 5152 errsts = check_condition_result;
5254 goto fini; 5153 goto fini;
5255 } 5154 }
5256 if (scsi_debug_fake_rw && (F_FAKE_RW & flags)) 5155 if (sdebug_fake_rw && (F_FAKE_RW & flags))
5257 goto fini; 5156 goto fini;
5258 if (scsi_debug_every_nth) { 5157 if (sdebug_every_nth) {
5259 if (check_inject(scp)) 5158 if (check_inject(scp))
5260 return 0; /* ignore command: make trouble */ 5159 return 0; /* ignore command: make trouble */
5261 } 5160 }
@@ -5266,7 +5165,7 @@ scsi_debug_queuecommand(struct scsi_cmnd *scp)
5266 5165
5267fini: 5166fini:
5268 return schedule_resp(scp, devip, errsts, 5167 return schedule_resp(scp, devip, errsts,
5269 ((F_DELAY_OVERR & flags) ? 0 : scsi_debug_delay)); 5168 ((F_DELAY_OVERR & flags) ? 0 : sdebug_delay));
5270check_cond: 5169check_cond:
5271 return schedule_resp(scp, devip, check_condition_result, 0); 5170 return schedule_resp(scp, devip, check_condition_result, 0);
5272} 5171}
@@ -5274,7 +5173,7 @@ check_cond:
5274static int 5173static int
5275sdebug_queuecommand_lock_or_not(struct Scsi_Host *shost, struct scsi_cmnd *cmd) 5174sdebug_queuecommand_lock_or_not(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
5276{ 5175{
5277 if (scsi_debug_host_lock) { 5176 if (sdebug_host_lock) {
5278 unsigned long iflags; 5177 unsigned long iflags;
5279 int rc; 5178 int rc;
5280 5179
@@ -5317,15 +5216,14 @@ static struct scsi_host_template sdebug_driver_template = {
5317static int sdebug_driver_probe(struct device * dev) 5216static int sdebug_driver_probe(struct device * dev)
5318{ 5217{
5319 int error = 0; 5218 int error = 0;
5320 int opts;
5321 struct sdebug_host_info *sdbg_host; 5219 struct sdebug_host_info *sdbg_host;
5322 struct Scsi_Host *hpnt; 5220 struct Scsi_Host *hpnt;
5323 int host_prot; 5221 int host_prot;
5324 5222
5325 sdbg_host = to_sdebug_host(dev); 5223 sdbg_host = to_sdebug_host(dev);
5326 5224
5327 sdebug_driver_template.can_queue = scsi_debug_max_queue; 5225 sdebug_driver_template.can_queue = sdebug_max_queue;
5328 if (scsi_debug_clustering) 5226 if (sdebug_clustering)
5329 sdebug_driver_template.use_clustering = ENABLE_CLUSTERING; 5227 sdebug_driver_template.use_clustering = ENABLE_CLUSTERING;
5330 hpnt = scsi_host_alloc(&sdebug_driver_template, sizeof(sdbg_host)); 5228 hpnt = scsi_host_alloc(&sdebug_driver_template, sizeof(sdbg_host));
5331 if (NULL == hpnt) { 5229 if (NULL == hpnt) {
@@ -5336,37 +5234,37 @@ static int sdebug_driver_probe(struct device * dev)
5336 5234
5337 sdbg_host->shost = hpnt; 5235 sdbg_host->shost = hpnt;
5338 *((struct sdebug_host_info **)hpnt->hostdata) = sdbg_host; 5236 *((struct sdebug_host_info **)hpnt->hostdata) = sdbg_host;
5339 if ((hpnt->this_id >= 0) && (scsi_debug_num_tgts > hpnt->this_id)) 5237 if ((hpnt->this_id >= 0) && (sdebug_num_tgts > hpnt->this_id))
5340 hpnt->max_id = scsi_debug_num_tgts + 1; 5238 hpnt->max_id = sdebug_num_tgts + 1;
5341 else 5239 else
5342 hpnt->max_id = scsi_debug_num_tgts; 5240 hpnt->max_id = sdebug_num_tgts;
5343 /* = scsi_debug_max_luns; */ 5241 /* = sdebug_max_luns; */
5344 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; 5242 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1;
5345 5243
5346 host_prot = 0; 5244 host_prot = 0;
5347 5245
5348 switch (scsi_debug_dif) { 5246 switch (sdebug_dif) {
5349 5247
5350 case SD_DIF_TYPE1_PROTECTION: 5248 case SD_DIF_TYPE1_PROTECTION:
5351 host_prot = SHOST_DIF_TYPE1_PROTECTION; 5249 host_prot = SHOST_DIF_TYPE1_PROTECTION;
5352 if (scsi_debug_dix) 5250 if (sdebug_dix)
5353 host_prot |= SHOST_DIX_TYPE1_PROTECTION; 5251 host_prot |= SHOST_DIX_TYPE1_PROTECTION;
5354 break; 5252 break;
5355 5253
5356 case SD_DIF_TYPE2_PROTECTION: 5254 case SD_DIF_TYPE2_PROTECTION:
5357 host_prot = SHOST_DIF_TYPE2_PROTECTION; 5255 host_prot = SHOST_DIF_TYPE2_PROTECTION;
5358 if (scsi_debug_dix) 5256 if (sdebug_dix)
5359 host_prot |= SHOST_DIX_TYPE2_PROTECTION; 5257 host_prot |= SHOST_DIX_TYPE2_PROTECTION;
5360 break; 5258 break;
5361 5259
5362 case SD_DIF_TYPE3_PROTECTION: 5260 case SD_DIF_TYPE3_PROTECTION:
5363 host_prot = SHOST_DIF_TYPE3_PROTECTION; 5261 host_prot = SHOST_DIF_TYPE3_PROTECTION;
5364 if (scsi_debug_dix) 5262 if (sdebug_dix)
5365 host_prot |= SHOST_DIX_TYPE3_PROTECTION; 5263 host_prot |= SHOST_DIX_TYPE3_PROTECTION;
5366 break; 5264 break;
5367 5265
5368 default: 5266 default:
5369 if (scsi_debug_dix) 5267 if (sdebug_dix)
5370 host_prot |= SHOST_DIX_TYPE0_PROTECTION; 5268 host_prot |= SHOST_DIX_TYPE0_PROTECTION;
5371 break; 5269 break;
5372 } 5270 }
@@ -5382,23 +5280,13 @@ static int sdebug_driver_probe(struct device * dev)
5382 (host_prot & SHOST_DIX_TYPE2_PROTECTION) ? " DIX2" : "", 5280 (host_prot & SHOST_DIX_TYPE2_PROTECTION) ? " DIX2" : "",
5383 (host_prot & SHOST_DIX_TYPE3_PROTECTION) ? " DIX3" : ""); 5281 (host_prot & SHOST_DIX_TYPE3_PROTECTION) ? " DIX3" : "");
5384 5282
5385 if (scsi_debug_guard == 1) 5283 if (sdebug_guard == 1)
5386 scsi_host_set_guard(hpnt, SHOST_DIX_GUARD_IP); 5284 scsi_host_set_guard(hpnt, SHOST_DIX_GUARD_IP);
5387 else 5285 else
5388 scsi_host_set_guard(hpnt, SHOST_DIX_GUARD_CRC); 5286 scsi_host_set_guard(hpnt, SHOST_DIX_GUARD_CRC);
5389 5287
5390 opts = scsi_debug_opts; 5288 sdebug_verbose = !!(SDEBUG_OPT_NOISE & sdebug_opts);
5391 if (SCSI_DEBUG_OPT_RECOVERED_ERR & opts) 5289 sdebug_any_injecting_opt = !!(SDEBUG_OPT_ALL_INJECTING & sdebug_opts);
5392 sdebug_any_injecting_opt = true;
5393 else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & opts)
5394 sdebug_any_injecting_opt = true;
5395 else if (SCSI_DEBUG_OPT_DIF_ERR & opts)
5396 sdebug_any_injecting_opt = true;
5397 else if (SCSI_DEBUG_OPT_DIX_ERR & opts)
5398 sdebug_any_injecting_opt = true;
5399 else if (SCSI_DEBUG_OPT_SHORT_TRANSFER & opts)
5400 sdebug_any_injecting_opt = true;
5401
5402 error = scsi_add_host(hpnt, &sdbg_host->dev); 5290 error = scsi_add_host(hpnt, &sdbg_host->dev);
5403 if (error) { 5291 if (error) {
5404 pr_err("scsi_add_host failed\n"); 5292 pr_err("scsi_add_host failed\n");