aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/scsi_debug.c1464
1 files changed, 1047 insertions, 417 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 6ed43fd19a22..d19c0e3c7f48 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -42,6 +42,10 @@
42#include <linux/scatterlist.h> 42#include <linux/scatterlist.h>
43#include <linux/blkdev.h> 43#include <linux/blkdev.h>
44#include <linux/crc-t10dif.h> 44#include <linux/crc-t10dif.h>
45#include <linux/spinlock.h>
46#include <linux/interrupt.h>
47#include <linux/atomic.h>
48#include <linux/hrtimer.h>
45 49
46#include <net/checksum.h> 50#include <net/checksum.h>
47 51
@@ -53,13 +57,16 @@
53#include <scsi/scsi_host.h> 57#include <scsi/scsi_host.h>
54#include <scsi/scsicam.h> 58#include <scsi/scsicam.h>
55#include <scsi/scsi_eh.h> 59#include <scsi/scsi_eh.h>
60#include <scsi/scsi_tcq.h>
56#include <scsi/scsi_dbg.h> 61#include <scsi/scsi_dbg.h>
57 62
58#include "sd.h" 63#include "sd.h"
59#include "scsi_logging.h" 64#include "scsi_logging.h"
60 65
61#define SCSI_DEBUG_VERSION "1.82" 66#define SCSI_DEBUG_VERSION "1.84"
62static const char * scsi_debug_version_date = "20100324"; 67static const char *scsi_debug_version_date = "20140706";
68
69#define MY_NAME "scsi_debug"
63 70
64/* Additional Sense Code (ASC) */ 71/* Additional Sense Code (ASC) */
65#define NO_ADDITIONAL_SENSE 0x0 72#define NO_ADDITIONAL_SENSE 0x0
@@ -72,7 +79,11 @@ static const char * scsi_debug_version_date = "20100324";
72#define INVALID_COMMAND_OPCODE 0x20 79#define INVALID_COMMAND_OPCODE 0x20
73#define INVALID_FIELD_IN_CDB 0x24 80#define INVALID_FIELD_IN_CDB 0x24
74#define INVALID_FIELD_IN_PARAM_LIST 0x26 81#define INVALID_FIELD_IN_PARAM_LIST 0x26
75#define POWERON_RESET 0x29 82#define UA_RESET_ASC 0x29
83#define UA_CHANGED_ASC 0x2a
84#define POWER_ON_RESET_ASCQ 0x0
85#define BUS_RESET_ASCQ 0x2 /* scsi bus reset occurred */
86#define MODE_CHANGED_ASCQ 0x1 /* mode parameters changed */
76#define SAVING_PARAMS_UNSUP 0x39 87#define SAVING_PARAMS_UNSUP 0x39
77#define TRANSPORT_PROBLEM 0x4b 88#define TRANSPORT_PROBLEM 0x4b
78#define THRESHOLD_EXCEEDED 0x5d 89#define THRESHOLD_EXCEEDED 0x5d
@@ -81,7 +92,6 @@ static const char * scsi_debug_version_date = "20100324";
81/* Additional Sense Code Qualifier (ASCQ) */ 92/* Additional Sense Code Qualifier (ASCQ) */
82#define ACK_NAK_TO 0x3 93#define ACK_NAK_TO 0x3
83 94
84#define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */
85 95
86/* Default values for driver parameters */ 96/* Default values for driver parameters */
87#define DEF_NUM_HOST 1 97#define DEF_NUM_HOST 1
@@ -91,7 +101,7 @@ static const char * scsi_debug_version_date = "20100324";
91 * (id 0) containing 1 logical unit (lun 0). That is 1 device. 101 * (id 0) containing 1 logical unit (lun 0). That is 1 device.
92 */ 102 */
93#define DEF_ATO 1 103#define DEF_ATO 1
94#define DEF_DELAY 1 104#define DEF_DELAY 1 /* if > 0 unit is a jiffy */
95#define DEF_DEV_SIZE_MB 8 105#define DEF_DEV_SIZE_MB 8
96#define DEF_DIF 0 106#define DEF_DIF 0
97#define DEF_DIX 0 107#define DEF_DIX 0
@@ -99,11 +109,13 @@ static const char * scsi_debug_version_date = "20100324";
99#define DEF_EVERY_NTH 0 109#define DEF_EVERY_NTH 0
100#define DEF_FAKE_RW 0 110#define DEF_FAKE_RW 0
101#define DEF_GUARD 0 111#define DEF_GUARD 0
112#define DEF_HOST_LOCK 0
102#define DEF_LBPU 0 113#define DEF_LBPU 0
103#define DEF_LBPWS 0 114#define DEF_LBPWS 0
104#define DEF_LBPWS10 0 115#define DEF_LBPWS10 0
105#define DEF_LBPRZ 1 116#define DEF_LBPRZ 1
106#define DEF_LOWEST_ALIGNED 0 117#define DEF_LOWEST_ALIGNED 0
118#define DEF_NDELAY 0 /* if > 0 unit is a nanosecond */
107#define DEF_NO_LUN_0 0 119#define DEF_NO_LUN_0 0
108#define DEF_NUM_PARTS 0 120#define DEF_NUM_PARTS 0
109#define DEF_OPTS 0 121#define DEF_OPTS 0
@@ -113,6 +125,7 @@ static const char * scsi_debug_version_date = "20100324";
113#define DEF_REMOVABLE false 125#define DEF_REMOVABLE false
114#define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */ 126#define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */
115#define DEF_SECTOR_SIZE 512 127#define DEF_SECTOR_SIZE 512
128#define DEF_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */
116#define DEF_UNMAP_ALIGNMENT 0 129#define DEF_UNMAP_ALIGNMENT 0
117#define DEF_UNMAP_GRANULARITY 1 130#define DEF_UNMAP_GRANULARITY 1
118#define DEF_UNMAP_MAX_BLOCKS 0xFFFFFFFF 131#define DEF_UNMAP_MAX_BLOCKS 0xFFFFFFFF
@@ -120,6 +133,7 @@ static const char * scsi_debug_version_date = "20100324";
120#define DEF_VIRTUAL_GB 0 133#define DEF_VIRTUAL_GB 0
121#define DEF_VPD_USE_HOSTNO 1 134#define DEF_VPD_USE_HOSTNO 1
122#define DEF_WRITESAME_LENGTH 0xFFFF 135#define DEF_WRITESAME_LENGTH 0xFFFF
136#define DELAY_OVERRIDDEN -9999
123 137
124/* bit mask values for scsi_debug_opts */ 138/* bit mask values for scsi_debug_opts */
125#define SCSI_DEBUG_OPT_NOISE 1 139#define SCSI_DEBUG_OPT_NOISE 1
@@ -130,7 +144,14 @@ static const char * scsi_debug_version_date = "20100324";
130#define SCSI_DEBUG_OPT_DIF_ERR 32 144#define SCSI_DEBUG_OPT_DIF_ERR 32
131#define SCSI_DEBUG_OPT_DIX_ERR 64 145#define SCSI_DEBUG_OPT_DIX_ERR 64
132#define SCSI_DEBUG_OPT_MAC_TIMEOUT 128 146#define SCSI_DEBUG_OPT_MAC_TIMEOUT 128
133#define SCSI_DEBUG_OPT_SHORT_TRANSFER 256 147#define SCSI_DEBUG_OPT_SHORT_TRANSFER 0x100
148#define SCSI_DEBUG_OPT_Q_NOISE 0x200
149#define SCSI_DEBUG_OPT_ALL_TSF 0x400
150#define SCSI_DEBUG_OPT_RARE_TSF 0x800
151#define SCSI_DEBUG_OPT_N_WCE 0x1000
152#define SCSI_DEBUG_OPT_RESET_NOISE 0x2000
153#define SCSI_DEBUG_OPT_NO_CDB_NOISE 0x4000
154#define SCSI_DEBUG_OPT_ALL_NOISE (0x1 | 0x200 | 0x2000)
134/* When "every_nth" > 0 then modulo "every_nth" commands: 155/* When "every_nth" > 0 then modulo "every_nth" commands:
135 * - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set 156 * - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set
136 * - a RECOVERED_ERROR is simulated on successful read and write 157 * - a RECOVERED_ERROR is simulated on successful read and write
@@ -148,6 +169,19 @@ static const char * scsi_debug_version_date = "20100324";
148 * writing a new value (other than -1 or 1) to every_nth via sysfs). 169 * writing a new value (other than -1 or 1) to every_nth via sysfs).
149 */ 170 */
150 171
172/* As indicated in SAM-5 and SPC-4 Unit Attentions (UAs)are returned in
173 * priority order. In the subset implemented here lower numbers have higher
174 * priority. The UA numbers should be a sequence starting from 0 with
175 * SDEBUG_NUM_UAS being 1 higher than the highest numbered UA. */
176#define SDEBUG_UA_POR 0 /* Power on, reset, or bus device reset */
177#define SDEBUG_UA_BUS_RESET 1
178#define SDEBUG_UA_MODE_CHANGED 2
179#define SDEBUG_NUM_UAS 3
180
181/* for check_readiness() */
182#define UAS_ONLY 1
183#define UAS_TUR 0
184
151/* when 1==SCSI_DEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this 185/* when 1==SCSI_DEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this
152 * sector on read commands: */ 186 * sector on read commands: */
153#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */ 187#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */
@@ -158,9 +192,19 @@ static const char * scsi_debug_version_date = "20100324";
158#define SAM2_LUN_ADDRESS_METHOD 0 192#define SAM2_LUN_ADDRESS_METHOD 0
159#define SAM2_WLUN_REPORT_LUNS 0xc101 193#define SAM2_WLUN_REPORT_LUNS 0xc101
160 194
161/* Can queue up to this number of commands. Typically commands that 195/* SCSI_DEBUG_CANQUEUE is the maximum number of commands that can be queued
162 * that have a non-zero delay are queued. */ 196 * (for response) at one time. Can be reduced by max_queue option. Command
163#define SCSI_DEBUG_CANQUEUE 255 197 * responses are not queued when delay=0 and ndelay=0. The per-device
198 * DEF_CMD_PER_LUN can be changed via sysfs:
199 * /sys/class/scsi_device/<h:c:t:l>/device/queue_depth but cannot exceed
200 * SCSI_DEBUG_CANQUEUE. */
201#define SCSI_DEBUG_CANQUEUE_WORDS 9 /* a WORD is bits in a long */
202#define SCSI_DEBUG_CANQUEUE (SCSI_DEBUG_CANQUEUE_WORDS * BITS_PER_LONG)
203#define DEF_CMD_PER_LUN 255
204
205#if DEF_CMD_PER_LUN > SCSI_DEBUG_CANQUEUE
206#warning "Expect DEF_CMD_PER_LUN <= SCSI_DEBUG_CANQUEUE"
207#endif
164 208
165static int scsi_debug_add_host = DEF_NUM_HOST; 209static int scsi_debug_add_host = DEF_NUM_HOST;
166static int scsi_debug_ato = DEF_ATO; 210static int scsi_debug_ato = DEF_ATO;
@@ -175,6 +219,8 @@ static unsigned int scsi_debug_guard = DEF_GUARD;
175static int scsi_debug_lowest_aligned = DEF_LOWEST_ALIGNED; 219static int scsi_debug_lowest_aligned = DEF_LOWEST_ALIGNED;
176static int scsi_debug_max_luns = DEF_MAX_LUNS; 220static int scsi_debug_max_luns = DEF_MAX_LUNS;
177static int scsi_debug_max_queue = SCSI_DEBUG_CANQUEUE; 221static int scsi_debug_max_queue = SCSI_DEBUG_CANQUEUE;
222static atomic_t retired_max_queue; /* if > 0 then was prior max_queue */
223static int scsi_debug_ndelay = DEF_NDELAY;
178static int scsi_debug_no_lun_0 = DEF_NO_LUN_0; 224static int scsi_debug_no_lun_0 = DEF_NO_LUN_0;
179static int scsi_debug_no_uld = 0; 225static int scsi_debug_no_uld = 0;
180static int scsi_debug_num_parts = DEF_NUM_PARTS; 226static int scsi_debug_num_parts = DEF_NUM_PARTS;
@@ -198,8 +244,11 @@ static unsigned int scsi_debug_unmap_max_desc = DEF_UNMAP_MAX_DESC;
198static unsigned int scsi_debug_write_same_length = DEF_WRITESAME_LENGTH; 244static unsigned int scsi_debug_write_same_length = DEF_WRITESAME_LENGTH;
199static bool scsi_debug_removable = DEF_REMOVABLE; 245static bool scsi_debug_removable = DEF_REMOVABLE;
200static bool scsi_debug_clustering; 246static bool scsi_debug_clustering;
247static bool scsi_debug_host_lock = DEF_HOST_LOCK;
201