diff options
author | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2006-07-03 10:41:12 -0400 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2006-07-03 10:41:12 -0400 |
commit | c4e00fac42f268ed0a547cdd1d12bb8399864040 (patch) | |
tree | 1a54d87be2066c49b71a03764fcb4fc7f9c68c41 /drivers/scsi/scsi_debug.c | |
parent | 29454dde27d8e340bb1987bad9aa504af7081eba (diff) | |
parent | d6b0c53723753fc0cfda63f56735b225c43e1e9a (diff) |
Merge ../scsi-misc-2.6
Conflicts:
drivers/scsi/nsp32.c
drivers/scsi/pcmcia/nsp_cs.c
Removal of randomness flag conflicts with SA_ -> IRQF_ global
replacement.
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/scsi_debug.c')
-rw-r--r-- | drivers/scsi/scsi_debug.c | 1223 |
1 files changed, 1028 insertions, 195 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index e1168860045c..9c63b00773c4 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c | |||
@@ -50,18 +50,22 @@ | |||
50 | #include "scsi_logging.h" | 50 | #include "scsi_logging.h" |
51 | #include "scsi_debug.h" | 51 | #include "scsi_debug.h" |
52 | 52 | ||
53 | #define SCSI_DEBUG_VERSION "1.75" | 53 | #define SCSI_DEBUG_VERSION "1.79" |
54 | static const char * scsi_debug_version_date = "20050113"; | 54 | static const char * scsi_debug_version_date = "20060604"; |
55 | 55 | ||
56 | /* Additional Sense Code (ASC) used */ | 56 | /* Additional Sense Code (ASC) used */ |
57 | #define NO_ADDED_SENSE 0x0 | 57 | #define NO_ADDITIONAL_SENSE 0x0 |
58 | #define LOGICAL_UNIT_NOT_READY 0x4 | ||
58 | #define UNRECOVERED_READ_ERR 0x11 | 59 | #define UNRECOVERED_READ_ERR 0x11 |
60 | #define PARAMETER_LIST_LENGTH_ERR 0x1a | ||
59 | #define INVALID_OPCODE 0x20 | 61 | #define INVALID_OPCODE 0x20 |
60 | #define ADDR_OUT_OF_RANGE 0x21 | 62 | #define ADDR_OUT_OF_RANGE 0x21 |
61 | #define INVALID_FIELD_IN_CDB 0x24 | 63 | #define INVALID_FIELD_IN_CDB 0x24 |
64 | #define INVALID_FIELD_IN_PARAM_LIST 0x26 | ||
62 | #define POWERON_RESET 0x29 | 65 | #define POWERON_RESET 0x29 |
63 | #define SAVING_PARAMS_UNSUP 0x39 | 66 | #define SAVING_PARAMS_UNSUP 0x39 |
64 | #define THRESHHOLD_EXCEEDED 0x5d | 67 | #define THRESHOLD_EXCEEDED 0x5d |
68 | #define LOW_POWER_COND_ON 0x5e | ||
65 | 69 | ||
66 | #define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */ | 70 | #define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */ |
67 | 71 | ||
@@ -80,6 +84,8 @@ static const char * scsi_debug_version_date = "20050113"; | |||
80 | #define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */ | 84 | #define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */ |
81 | #define DEF_PTYPE 0 | 85 | #define DEF_PTYPE 0 |
82 | #define DEF_D_SENSE 0 | 86 | #define DEF_D_SENSE 0 |
87 | #define DEF_NO_LUN_0 0 | ||
88 | #define DEF_VIRTUAL_GB 0 | ||
83 | 89 | ||
84 | /* bit mask values for scsi_debug_opts */ | 90 | /* bit mask values for scsi_debug_opts */ |
85 | #define SCSI_DEBUG_OPT_NOISE 1 | 91 | #define SCSI_DEBUG_OPT_NOISE 1 |
@@ -106,6 +112,7 @@ static const char * scsi_debug_version_date = "20050113"; | |||
106 | /* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1) | 112 | /* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1) |
107 | * or "peripheral device" addressing (value 0) */ | 113 | * or "peripheral device" addressing (value 0) */ |
108 | #define SAM2_LUN_ADDRESS_METHOD 0 | 114 | #define SAM2_LUN_ADDRESS_METHOD 0 |
115 | #define SAM2_WLUN_REPORT_LUNS 0xc101 | ||
109 | 116 | ||
110 | static int scsi_debug_add_host = DEF_NUM_HOST; | 117 | static int scsi_debug_add_host = DEF_NUM_HOST; |
111 | static int scsi_debug_delay = DEF_DELAY; | 118 | static int scsi_debug_delay = DEF_DELAY; |
@@ -118,13 +125,16 @@ static int scsi_debug_opts = DEF_OPTS; | |||
118 | static int scsi_debug_scsi_level = DEF_SCSI_LEVEL; | 125 | static int scsi_debug_scsi_level = DEF_SCSI_LEVEL; |
119 | static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */ | 126 | static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */ |
120 | static int scsi_debug_dsense = DEF_D_SENSE; | 127 | static int scsi_debug_dsense = DEF_D_SENSE; |
128 | static int scsi_debug_no_lun_0 = DEF_NO_LUN_0; | ||
129 | static int scsi_debug_virtual_gb = DEF_VIRTUAL_GB; | ||
121 | 130 | ||
122 | static int scsi_debug_cmnd_count = 0; | 131 | static int scsi_debug_cmnd_count = 0; |
123 | 132 | ||
124 | #define DEV_READONLY(TGT) (0) | 133 | #define DEV_READONLY(TGT) (0) |
125 | #define DEV_REMOVEABLE(TGT) (0) | 134 | #define DEV_REMOVEABLE(TGT) (0) |
126 | 135 | ||
127 | static unsigned long sdebug_store_size; /* in bytes */ | 136 | static unsigned int sdebug_store_size; /* in bytes */ |
137 | static unsigned int sdebug_store_sectors; | ||
128 | static sector_t sdebug_capacity; /* in sectors */ | 138 | static sector_t sdebug_capacity; /* in sectors */ |
129 | 139 | ||
130 | /* old BIOS stuff, kernel may get rid of them but some mode sense pages | 140 | /* old BIOS stuff, kernel may get rid of them but some mode sense pages |
@@ -149,7 +159,9 @@ struct sdebug_dev_info { | |||
149 | unsigned int target; | 159 | unsigned int target; |
150 | unsigned int lun; | 160 | unsigned int lun; |
151 | struct sdebug_host_info *sdbg_host; | 161 | struct sdebug_host_info *sdbg_host; |
162 | unsigned int wlun; | ||
152 | char reset; | 163 | char reset; |
164 | char stopped; | ||
153 | char used; | 165 | char used; |
154 | }; | 166 | }; |
155 | 167 | ||
@@ -193,11 +205,11 @@ static struct scsi_host_template sdebug_driver_template = { | |||
193 | .bios_param = scsi_debug_biosparam, | 205 | .bios_param = scsi_debug_biosparam, |
194 | .can_queue = SCSI_DEBUG_CANQUEUE, | 206 | .can_queue = SCSI_DEBUG_CANQUEUE, |
195 | .this_id = 7, | 207 | .this_id = 7, |
196 | .sg_tablesize = 64, | 208 | .sg_tablesize = 256, |
197 | .cmd_per_lun = 3, | 209 | .cmd_per_lun = 16, |
198 | .max_sectors = 4096, | 210 | .max_sectors = 0xffff, |
199 | .unchecked_isa_dma = 0, | 211 | .unchecked_isa_dma = 0, |
200 | .use_clustering = DISABLE_CLUSTERING, | 212 | .use_clustering = ENABLE_CLUSTERING, |
201 | .module = THIS_MODULE, | 213 | .module = THIS_MODULE, |
202 | }; | 214 | }; |
203 | 215 | ||
@@ -225,19 +237,32 @@ static struct device_driver sdebug_driverfs_driver = { | |||
225 | static const int check_condition_result = | 237 | static const int check_condition_result = |
226 | (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | 238 | (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; |
227 | 239 | ||
240 | static unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | ||
241 | 0, 0, 0x2, 0x4b}; | ||
242 | static unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0, | ||
243 | 0, 0, 0x0, 0x0}; | ||
244 | |||
228 | /* function declarations */ | 245 | /* function declarations */ |
229 | static int resp_inquiry(struct scsi_cmnd * SCpnt, int target, | 246 | static int resp_inquiry(struct scsi_cmnd * SCpnt, int target, |
230 | struct sdebug_dev_info * devip); | 247 | struct sdebug_dev_info * devip); |
231 | static int resp_requests(struct scsi_cmnd * SCpnt, | 248 | static int resp_requests(struct scsi_cmnd * SCpnt, |
232 | struct sdebug_dev_info * devip); | 249 | struct sdebug_dev_info * devip); |
250 | static int resp_start_stop(struct scsi_cmnd * scp, | ||
251 | struct sdebug_dev_info * devip); | ||
233 | static int resp_readcap(struct scsi_cmnd * SCpnt, | 252 | static int resp_readcap(struct scsi_cmnd * SCpnt, |
234 | struct sdebug_dev_info * devip); | 253 | struct sdebug_dev_info * devip); |
235 | static int resp_mode_sense(struct scsi_cmnd * SCpnt, int target, | 254 | static int resp_readcap16(struct scsi_cmnd * SCpnt, |
255 | struct sdebug_dev_info * devip); | ||
256 | static int resp_mode_sense(struct scsi_cmnd * scp, int target, | ||
236 | struct sdebug_dev_info * devip); | 257 | struct sdebug_dev_info * devip); |
237 | static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, | 258 | static int resp_mode_select(struct scsi_cmnd * scp, int mselect6, |
238 | int num, struct sdebug_dev_info * devip); | 259 | struct sdebug_dev_info * devip); |
239 | static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, | 260 | static int resp_log_sense(struct scsi_cmnd * scp, |
240 | int num, struct sdebug_dev_info * devip); | 261 | struct sdebug_dev_info * devip); |
262 | static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba, | ||
263 | unsigned int num, struct sdebug_dev_info * devip); | ||
264 | static int resp_write(struct scsi_cmnd * SCpnt, unsigned long long lba, | ||
265 | unsigned int num, struct sdebug_dev_info * devip); | ||
241 | static int resp_report_luns(struct scsi_cmnd * SCpnt, | 266 | static int resp_report_luns(struct scsi_cmnd * SCpnt, |
242 | struct sdebug_dev_info * devip); | 267 | struct sdebug_dev_info * devip); |
243 | static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, | 268 | static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, |
@@ -248,8 +273,8 @@ static void timer_intr_handler(unsigned long); | |||
248 | static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev); | 273 | static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev); |
249 | static void mk_sense_buffer(struct sdebug_dev_info * devip, int key, | 274 | static void mk_sense_buffer(struct sdebug_dev_info * devip, int key, |
250 | int asc, int asq); | 275 | int asc, int asq); |
251 | static int check_reset(struct scsi_cmnd * SCpnt, | 276 | static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only, |
252 | struct sdebug_dev_info * devip); | 277 | struct sdebug_dev_info * devip); |
253 | static int schedule_resp(struct scsi_cmnd * cmnd, | 278 | static int schedule_resp(struct scsi_cmnd * cmnd, |
254 | struct sdebug_dev_info * devip, | 279 | struct sdebug_dev_info * devip, |
255 | done_funct_t done, int scsi_result, int delta_jiff); | 280 | done_funct_t done, int scsi_result, int delta_jiff); |
@@ -257,8 +282,10 @@ static void __init sdebug_build_parts(unsigned char * ramp); | |||
257 | static void __init init_all_queued(void); | 282 | static void __init init_all_queued(void); |
258 | static void stop_all_queued(void); | 283 | static void stop_all_queued(void); |
259 | static int stop_queued_cmnd(struct scsi_cmnd * cmnd); | 284 | static int stop_queued_cmnd(struct scsi_cmnd * cmnd); |
260 | static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, | 285 | static int inquiry_evpd_83(unsigned char * arr, int target_dev_id, |
261 | const char * dev_id_str, int dev_id_str_len); | 286 | int dev_id_num, const char * dev_id_str, |
287 | int dev_id_str_len); | ||
288 | static int inquiry_evpd_88(unsigned char * arr, int target_dev_id); | ||
262 | static void do_create_driverfs_files(void); | 289 | static void do_create_driverfs_files(void); |
263 | static void do_remove_driverfs_files(void); | 290 | static void do_remove_driverfs_files(void); |
264 | 291 | ||
@@ -274,18 +301,22 @@ static | |||
274 | int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) | 301 | int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) |
275 | { | 302 | { |
276 | unsigned char *cmd = (unsigned char *) SCpnt->cmnd; | 303 | unsigned char *cmd = (unsigned char *) SCpnt->cmnd; |
277 | int block, upper_blk, num, k; | 304 | int len, k, j; |
305 | unsigned int num; | ||
306 | unsigned long long lba; | ||
278 | int errsts = 0; | 307 | int errsts = 0; |
279 | int target = scmd_id(SCpnt); | 308 | int target = SCpnt->device->id; |
280 | struct sdebug_dev_info * devip = NULL; | 309 | struct sdebug_dev_info * devip = NULL; |
281 | int inj_recovered = 0; | 310 | int inj_recovered = 0; |
311 | int delay_override = 0; | ||
282 | 312 | ||
283 | if (done == NULL) | 313 | if (done == NULL) |
284 | return 0; /* assume mid level reprocessing command */ | 314 | return 0; /* assume mid level reprocessing command */ |
285 | 315 | ||
316 | SCpnt->resid = 0; | ||
286 | if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) { | 317 | if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) { |
287 | printk(KERN_INFO "scsi_debug: cmd "); | 318 | printk(KERN_INFO "scsi_debug: cmd "); |
288 | for (k = 0, num = SCpnt->cmd_len; k < num; ++k) | 319 | for (k = 0, len = SCpnt->cmd_len; k < len; ++k) |
289 | printk("%02x ", (int)cmd[k]); | 320 | printk("%02x ", (int)cmd[k]); |
290 | printk("\n"); | 321 | printk("\n"); |
291 | } | 322 | } |
@@ -296,7 +327,8 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) | |||
296 | DID_NO_CONNECT << 16, 0); | 327 | DID_NO_CONNECT << 16, 0); |
297 | } | 328 | } |
298 | 329 | ||
299 | if (SCpnt->device->lun >= scsi_debug_max_luns) | 330 | if ((SCpnt->device->lun >= scsi_debug_max_luns) && |
331 | (SCpnt->device->lun != SAM2_WLUN_REPORT_LUNS)) | ||
300 | return schedule_resp(SCpnt, NULL, done, | 332 | return schedule_resp(SCpnt, NULL, done, |
301 | DID_NO_CONNECT << 16, 0); | 333 | DID_NO_CONNECT << 16, 0); |
302 | devip = devInfoReg(SCpnt->device); | 334 | devip = devInfoReg(SCpnt->device); |
@@ -315,118 +347,150 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) | |||
315 | inj_recovered = 1; /* to reads and writes below */ | 347 | inj_recovered = 1; /* to reads and writes below */ |
316 | } | 348 | } |
317 | 349 | ||
350 | if (devip->wlun) { | ||
351 | switch (*cmd) { | ||
352 | case INQUIRY: | ||
353 | case REQUEST_SENSE: | ||
354 | case TEST_UNIT_READY: | ||
355 | case REPORT_LUNS: | ||
356 | break; /* only allowable wlun commands */ | ||
357 | default: | ||
358 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | ||
359 | printk(KERN_INFO "scsi_debug: Opcode: 0x%x " | ||
360 | "not supported for wlun\n", *cmd); | ||
361 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
362 | INVALID_OPCODE, 0); | ||
363 | errsts = check_condition_result; | ||
364 | return schedule_resp(SCpnt, devip, done, errsts, | ||
365 | 0); | ||
366 | } | ||
367 | } | ||
368 | |||
318 | switch (*cmd) { | 369 | switch (*cmd) { |
319 | case INQUIRY: /* mandatory, ignore unit attention */ | 370 | case INQUIRY: /* mandatory, ignore unit attention */ |
371 | delay_override = 1; | ||
320 | errsts = resp_inquiry(SCpnt, target, devip); | 372 | errsts = resp_inquiry(SCpnt, target, devip); |
321 | break; | 373 | break; |
322 | case REQUEST_SENSE: /* mandatory, ignore unit attention */ | 374 | case REQUEST_SENSE: /* mandatory, ignore unit attention */ |
375 | delay_override = 1; | ||
323 | errsts = resp_requests(SCpnt, devip); | 376 | errsts = resp_requests(SCpnt, devip); |
324 | break; | 377 | break; |
325 | case REZERO_UNIT: /* actually this is REWIND for SSC */ | 378 | case REZERO_UNIT: /* actually this is REWIND for SSC */ |
326 | case START_STOP: | 379 | case START_STOP: |
327 | errsts = check_reset(SCpnt, devip); | 380 | errsts = resp_start_stop(SCpnt, devip); |
328 | break; | 381 | break; |
329 | case ALLOW_MEDIUM_REMOVAL: | 382 | case ALLOW_MEDIUM_REMOVAL: |
330 | if ((errsts = check_reset(SCpnt, devip))) | 383 | if ((errsts = check_readiness(SCpnt, 1, devip))) |
331 | break; | 384 | break; |
332 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 385 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
333 | printk(KERN_INFO "scsi_debug: Medium removal %s\n", | 386 | printk(KERN_INFO "scsi_debug: Medium removal %s\n", |
334 | cmd[4] ? "inhibited" : "enabled"); | 387 | cmd[4] ? "inhibited" : "enabled"); |
335 | break; | 388 | break; |
336 | case SEND_DIAGNOSTIC: /* mandatory */ | 389 | case SEND_DIAGNOSTIC: /* mandatory */ |
337 | errsts = check_reset(SCpnt, devip); | 390 | errsts = check_readiness(SCpnt, 1, devip); |
338 | break; | 391 | break; |
339 | case TEST_UNIT_READY: /* mandatory */ | 392 | case TEST_UNIT_READY: /* mandatory */ |
340 | errsts = check_reset(SCpnt, devip); | 393 | delay_override = 1; |
394 | errsts = check_readiness(SCpnt, 0, devip); | ||
341 | break; | 395 | break; |
342 | case RESERVE: | 396 | case RESERVE: |
343 | errsts = check_reset(SCpnt, devip); | 397 | errsts = check_readiness(SCpnt, 1, devip); |
344 | break; | 398 | break; |
345 | case RESERVE_10: | 399 | case RESERVE_10: |
346 | errsts = check_reset(SCpnt, devip); | 400 | errsts = check_readiness(SCpnt, 1, devip); |
347 | break; | 401 | break; |
348 | case RELEASE: | 402 | case RELEASE: |
349 | errsts = check_reset(SCpnt, devip); | 403 | errsts = check_readiness(SCpnt, 1, devip); |
350 | break; | 404 | break; |
351 | case RELEASE_10: | 405 | case RELEASE_10: |
352 | errsts = check_reset(SCpnt, devip); | 406 | errsts = check_readiness(SCpnt, 1, devip); |
353 | break; | 407 | break; |
354 | case READ_CAPACITY: | 408 | case READ_CAPACITY: |
355 | errsts = resp_readcap(SCpnt, devip); | 409 | errsts = resp_readcap(SCpnt, devip); |
356 | break; | 410 | break; |
411 | case SERVICE_ACTION_IN: | ||
412 | if (SAI_READ_CAPACITY_16 != cmd[1]) { | ||
413 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
414 | INVALID_OPCODE, 0); | ||
415 | errsts = check_condition_result; | ||
416 | break; | ||
417 | } | ||
418 | errsts = resp_readcap16(SCpnt, devip); | ||
419 | break; | ||
357 | case READ_16: | 420 | case READ_16: |
358 | case READ_12: | 421 | case READ_12: |
359 | case READ_10: | 422 | case READ_10: |
360 | case READ_6: | 423 | case READ_6: |
361 | if ((errsts = check_reset(SCpnt, devip))) | 424 | if ((errsts = check_readiness(SCpnt, 0, devip))) |
362 | break; | 425 | break; |
363 | upper_blk = 0; | ||
364 | if ((*cmd) == READ_16) { | 426 | if ((*cmd) == READ_16) { |
365 | upper_blk = cmd[5] + (cmd[4] << 8) + | 427 | for (lba = 0, j = 0; j < 8; ++j) { |
366 | (cmd[3] << 16) + (cmd[2] << 24); | 428 | if (j > 0) |
367 | block = cmd[9] + (cmd[8] << 8) + | 429 | lba <<= 8; |
368 | (cmd[7] << 16) + (cmd[6] << 24); | 430 | lba += cmd[2 + j]; |
431 | } | ||
369 | num = cmd[13] + (cmd[12] << 8) + | 432 | num = cmd[13] + (cmd[12] << 8) + |
370 | (cmd[11] << 16) + (cmd[10] << 24); | 433 | (cmd[11] << 16) + (cmd[10] << 24); |
371 | } else if ((*cmd) == READ_12) { | 434 | } else if ((*cmd) == READ_12) { |
372 | block = cmd[5] + (cmd[4] << 8) + | 435 | lba = cmd[5] + (cmd[4] << 8) + |
373 | (cmd[3] << 16) + (cmd[2] << 24); | 436 | (cmd[3] << 16) + (cmd[2] << 24); |
374 | num = cmd[9] + (cmd[8] << 8) + | 437 | num = cmd[9] + (cmd[8] << 8) + |
375 | (cmd[7] << 16) + (cmd[6] << 24); | 438 | (cmd[7] << 16) + (cmd[6] << 24); |
376 | } else if ((*cmd) == READ_10) { | 439 | } else if ((*cmd) == READ_10) { |
377 | block = cmd[5] + (cmd[4] << 8) + | 440 | lba = cmd[5] + (cmd[4] << 8) + |
378 | (cmd[3] << 16) + (cmd[2] << 24); | 441 | (cmd[3] << 16) + (cmd[2] << 24); |
379 | num = cmd[8] + (cmd[7] << 8); | 442 | num = cmd[8] + (cmd[7] << 8); |
380 | } else { | 443 | } else { /* READ (6) */ |
381 | block = cmd[3] + (cmd[2] << 8) + | 444 | lba = cmd[3] + (cmd[2] << 8) + |
382 | ((cmd[1] & 0x1f) << 16); | 445 | ((cmd[1] & 0x1f) << 16); |
383 | num = cmd[4]; | 446 | num = (0 == cmd[4]) ? 256 : cmd[4]; |
384 | } | 447 | } |
385 | errsts = resp_read(SCpnt, upper_blk, block, num, devip); | 448 | errsts = resp_read(SCpnt, lba, num, devip); |
386 | if (inj_recovered && (0 == errsts)) { | 449 | if (inj_recovered && (0 == errsts)) { |
387 | mk_sense_buffer(devip, RECOVERED_ERROR, | 450 | mk_sense_buffer(devip, RECOVERED_ERROR, |
388 | THRESHHOLD_EXCEEDED, 0); | 451 | THRESHOLD_EXCEEDED, 0); |
389 | errsts = check_condition_result; | 452 | errsts = check_condition_result; |
390 | } | 453 | } |
391 | break; | 454 | break; |
392 | case REPORT_LUNS: /* mandatory, ignore unit attention */ | 455 | case REPORT_LUNS: /* mandatory, ignore unit attention */ |
456 | delay_override = 1; | ||
393 | errsts = resp_report_luns(SCpnt, devip); | 457 | errsts = resp_report_luns(SCpnt, devip); |
394 | break; | 458 | break; |
395 | case VERIFY: /* 10 byte SBC-2 command */ | 459 | case VERIFY: /* 10 byte SBC-2 command */ |
396 | errsts = check_reset(SCpnt, devip); | 460 | errsts = check_readiness(SCpnt, 0, devip); |
397 | break; | 461 | break; |
398 | case WRITE_16: | 462 | case WRITE_16: |
399 | case WRITE_12: | 463 | case WRITE_12: |
400 | case WRITE_10: | 464 | case WRITE_10: |
401 | case WRITE_6: | 465 | case WRITE_6: |
402 | if ((errsts = check_reset(SCpnt, devip))) | 466 | if ((errsts = check_readiness(SCpnt, 0, devip))) |
403 | break; | 467 | break; |
404 | upper_blk = 0; | ||
405 | if ((*cmd) == WRITE_16) { | 468 | if ((*cmd) == WRITE_16) { |
406 | upper_blk = cmd[5] + (cmd[4] << 8) + | 469 | for (lba = 0, j = 0; j < 8; ++j) { |
407 | (cmd[3] << 16) + (cmd[2] << 24); | 470 | if (j > 0) |
408 | block = cmd[9] + (cmd[8] << 8) + | 471 | lba <<= 8; |
409 | (cmd[7] << 16) + (cmd[6] << 24); | 472 | lba += cmd[2 + j]; |
473 | } | ||
410 | num = cmd[13] + (cmd[12] << 8) + | 474 | num = cmd[13] + (cmd[12] << 8) + |
411 | (cmd[11] << 16) + (cmd[10] << 24); | 475 | (cmd[11] << 16) + (cmd[10] << 24); |
412 | } else if ((*cmd) == WRITE_12) { | 476 | } else if ((*cmd) == WRITE_12) { |
413 | block = cmd[5] + (cmd[4] << 8) + | 477 | lba = cmd[5] + (cmd[4] << 8) + |
414 | (cmd[3] << 16) + (cmd[2] << 24); | 478 | (cmd[3] << 16) + (cmd[2] << 24); |
415 | num = cmd[9] + (cmd[8] << 8) + | 479 | num = cmd[9] + (cmd[8] << 8) + |
416 | (cmd[7] << 16) + (cmd[6] << 24); | 480 | (cmd[7] << 16) + (cmd[6] << 24); |
417 | } else if ((*cmd) == WRITE_10) { | 481 | } else if ((*cmd) == WRITE_10) { |
418 | block = cmd[5] + (cmd[4] << 8) + | 482 | lba = cmd[5] + (cmd[4] << 8) + |
419 | (cmd[3] << 16) + (cmd[2] << 24); | 483 | (cmd[3] << 16) + (cmd[2] << 24); |
420 | num = cmd[8] + (cmd[7] << 8); | 484 | num = cmd[8] + (cmd[7] << 8); |
421 | } else { | 485 | } else { /* WRITE (6) */ |
422 | block = cmd[3] + (cmd[2] << 8) + | 486 | lba = cmd[3] + (cmd[2] << 8) + |
423 | ((cmd[1] & 0x1f) << 16); | 487 | ((cmd[1] & 0x1f) << 16); |
424 | num = cmd[4]; | 488 | num = (0 == cmd[4]) ? 256 : cmd[4]; |
425 | } | 489 | } |
426 | errsts = resp_write(SCpnt, upper_blk, block, num, devip); | 490 | errsts = resp_write(SCpnt, lba, num, devip); |
427 | if (inj_recovered && (0 == errsts)) { | 491 | if (inj_recovered && (0 == errsts)) { |
428 | mk_sense_buffer(devip, RECOVERED_ERROR, | 492 | mk_sense_buffer(devip, RECOVERED_ERROR, |
429 | THRESHHOLD_EXCEEDED, 0); | 493 | THRESHOLD_EXCEEDED, 0); |
430 | errsts = check_condition_result; | 494 | errsts = check_condition_result; |
431 | } | 495 | } |
432 | break; | 496 | break; |
@@ -434,20 +498,31 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) | |||
434 | case MODE_SENSE_10: | 498 | case MODE_SENSE_10: |
435 | errsts = resp_mode_sense(SCpnt, target, devip); | 499 | errsts = resp_mode_sense(SCpnt, target, devip); |
436 | break; | 500 | break; |
501 | case MODE_SELECT: | ||
502 | errsts = resp_mode_select(SCpnt, 1, devip); | ||
503 | break; | ||
504 | case MODE_SELECT_10: | ||
505 | errsts = resp_mode_select(SCpnt, 0, devip); | ||
506 | break; | ||
507 | case LOG_SENSE: | ||
508 | errsts = resp_log_sense(SCpnt, devip); | ||
509 | break; | ||
437 | case SYNCHRONIZE_CACHE: | 510 | case SYNCHRONIZE_CACHE: |
438 | errsts = check_reset(SCpnt, devip); | 511 | delay_override = 1; |
512 | errsts = check_readiness(SCpnt, 0, devip); | ||
439 | break; | 513 | break; |
440 | default: | 514 | default: |
441 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 515 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
442 | printk(KERN_INFO "scsi_debug: Opcode: 0x%x not " | 516 | printk(KERN_INFO "scsi_debug: Opcode: 0x%x not " |
443 | "supported\n", *cmd); | 517 | "supported\n", *cmd); |
444 | if ((errsts = check_reset(SCpnt, devip))) | 518 | if ((errsts = check_readiness(SCpnt, 1, devip))) |
445 | break; /* Unit attention takes precedence */ | 519 | break; /* Unit attention takes precedence */ |
446 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0); | 520 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0); |
447 | errsts = check_condition_result; | 521 | errsts = check_condition_result; |
448 | break; | 522 | break; |
449 | } | 523 | } |
450 | return schedule_resp(SCpnt, devip, done, errsts, scsi_debug_delay); | 524 | return schedule_resp(SCpnt, devip, done, errsts, |
525 | (delay_override ? 0 : scsi_debug_delay)); | ||
451 | } | 526 | } |
452 | 527 | ||
453 | static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) | 528 | static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) |
@@ -459,7 +534,8 @@ static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) | |||
459 | /* return -ENOTTY; // correct return but upsets fdisk */ | 534 | /* return -ENOTTY; // correct return but upsets fdisk */ |
460 | } | 535 | } |
461 | 536 | ||
462 | static int check_reset(struct scsi_cmnd * SCpnt, struct sdebug_dev_info * devip) | 537 | static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only, |
538 | struct sdebug_dev_info * devip) | ||
463 | { | 539 | { |
464 | if (devip->reset) { | 540 | if (devip->reset) { |
465 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 541 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
@@ -469,6 +545,14 @@ static int check_reset(struct scsi_cmnd * SCpnt, struct sdebug_dev_info * devip) | |||
469 | mk_sense_buffer(devip, UNIT_ATTENTION, POWERON_RESET, 0); | 545 | mk_sense_buffer(devip, UNIT_ATTENTION, POWERON_RESET, 0); |
470 | return check_condition_result; | 546 | return check_condition_result; |
471 | } | 547 | } |
548 | if ((0 == reset_only) && devip->stopped) { | ||
549 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | ||
550 | printk(KERN_INFO "scsi_debug: Reporting Not " | ||
551 | "ready: initializing command required\n"); | ||
552 | mk_sense_buffer(devip, NOT_READY, LOGICAL_UNIT_NOT_READY, | ||
553 | 0x2); | ||
554 | return check_condition_result; | ||
555 | } | ||
472 | return 0; | 556 | return 0; |
473 | } | 557 | } |
474 | 558 | ||
@@ -492,7 +576,10 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, | |||
492 | req_len = scp->request_bufflen; | 576 | req_len = scp->request_bufflen; |
493 | act_len = (req_len < arr_len) ? req_len : arr_len; | 577 | act_len = (req_len < arr_len) ? req_len : arr_len; |
494 | memcpy(scp->request_buffer, arr, act_len); | 578 | memcpy(scp->request_buffer, arr, act_len); |
495 | scp->resid = req_len - act_len; | 579 | if (scp->resid) |
580 | scp->resid -= act_len; | ||
581 | else | ||
582 | scp->resid = req_len - act_len; | ||
496 | return 0; | 583 | return 0; |
497 | } | 584 | } |
498 | sgpnt = (struct scatterlist *)scp->request_buffer; | 585 | sgpnt = (struct scatterlist *)scp->request_buffer; |
@@ -515,7 +602,10 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, | |||
515 | } | 602 | } |
516 | req_len += sgpnt->length; | 603 | req_len += sgpnt->length; |
517 | } | 604 | } |
518 | scp->resid = req_len - act_len; | 605 | if (scp->resid) |
606 | scp->resid -= act_len; | ||
607 | else | ||
608 | scp->resid = req_len - act_len; | ||
519 | return 0; | 609 | return 0; |
520 | } | 610 | } |
521 | 611 | ||
@@ -566,12 +656,14 @@ static const char * inq_vendor_id = "Linux "; | |||
566 | static const char * inq_product_id = "scsi_debug "; | 656 | static const char * inq_product_id = "scsi_debug "; |
567 | static const char * inq_product_rev = "0004"; | 657 | static const char * inq_product_rev = "0004"; |
568 | 658 | ||
569 | static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, | 659 | static int inquiry_evpd_83(unsigned char * arr, int target_dev_id, |
570 | const char * dev_id_str, int dev_id_str_len) | 660 | int dev_id_num, const char * dev_id_str, |
661 | int dev_id_str_len) | ||
571 | { | 662 | { |
572 | int num; | 663 | int num, port_a; |
664 | char b[32]; | ||
573 | 665 | ||
574 | /* Two identification descriptors: */ | 666 | port_a = target_dev_id + 1; |
575 | /* T10 vendor identifier field format (faked) */ | 667 | /* T10 vendor identifier field format (faked) */ |
576 | arr[0] = 0x2; /* ASCII */ | 668 | arr[0] = 0x2; /* ASCII */ |
577 | arr[1] = 0x1; | 669 | arr[1] = 0x1; |
@@ -582,25 +674,246 @@ static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, | |||
582 | num = 8 + 16 + dev_id_str_len; | 674 | num = 8 + 16 + dev_id_str_len; |
583 | arr[3] = num; | 675 | arr[3] = num; |
584 | num += 4; | 676 | num += 4; |
585 | /* NAA IEEE registered identifier (faked) */ | 677 | if (dev_id_num >= 0) { |
586 | arr[num] = 0x1; /* binary */ | 678 | /* NAA-5, Logical unit identifier (binary) */ |
587 | arr[num + 1] = 0x3; | 679 | arr[num++] = 0x1; /* binary (not necessarily sas) */ |
588 | arr[num + 2] = 0x0; | 680 | arr[num++] = 0x3; /* PIV=0, lu, naa */ |
589 | arr[num + 3] = 0x8; | 681 | arr[num++] = 0x0; |
590 | arr[num + 4] = 0x51; /* ieee company id=0x123456 (faked) */ | 682 | arr[num++] = 0x8; |
591 | arr[num + 5] = 0x23; | 683 | arr[num++] = 0x53; /* naa-5 ieee company id=0x333333 (fake) */ |
592 | arr[num + 6] = 0x45; | 684 | arr[num++] = 0x33; |
593 | arr[num + 7] = 0x60; | 685 | arr[num++] = 0x33; |
594 | arr[num + 8] = (dev_id_num >> 24); | 686 | arr[num++] = 0x30; |
595 | arr[num + 9] = (dev_id_num >> 16) & 0xff; | 687 | arr[num++] = (dev_id_num >> 24); |
596 | arr[num + 10] = (dev_id_num >> 8) & 0xff; | 688 | arr[num++] = (dev_id_num >> 16) & 0xff; |
597 | arr[num + 11] = dev_id_num & 0xff; | 689 | arr[num++] = (dev_id_num >> 8) & 0xff; |
598 | return num + 12; | 690 | arr[num++] = dev_id_num & 0xff; |
691 | /* Target relative port number */ | ||
692 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
693 | arr[num++] = 0x94; /* PIV=1, target port, rel port */ | ||
694 | arr[num++] = 0x0; /* reserved */ | ||
695 | arr[num++] = 0x4; /* length */ | ||
696 | arr[num++] = 0x0; /* reserved */ | ||
697 | arr[num++] = 0x0; /* reserved */ | ||
698 | arr[num++] = 0x0; | ||
699 | arr[num++] = 0x1; /* relative port A */ | ||
700 | } | ||
701 | /* NAA-5, Target port identifier */ | ||
702 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
703 | arr[num++] = 0x93; /* piv=1, target port, naa */ | ||
704 | arr[num++] = 0x0; | ||
705 | arr[num++] = 0x8; | ||
706 | arr[num++] = 0x52; /* naa-5, company id=0x222222 (fake) */ | ||
707 | arr[num++] = 0x22; | ||
708 | arr[num++] = 0x22; | ||
709 | arr[num++] = 0x20; | ||
710 | arr[num++] = (port_a >> 24); | ||
711 | arr[num++] = (port_a >> 16) & 0xff; | ||
712 | arr[num++] = (port_a >> 8) & 0xff; | ||
713 | arr[num++] = port_a & 0xff; | ||
714 | /* NAA-5, Target device identifier */ | ||
715 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
716 | arr[num++] = 0xa3; /* piv=1, target device, naa */ | ||
717 | arr[num++] = 0x0; | ||
718 | arr[num++] = 0x8; | ||
719 | arr[num++] = 0x52; /* naa-5, company id=0x222222 (fake) */ | ||
720 | arr[num++] = 0x22; | ||
721 | arr[num++] = 0x22; | ||
722 | arr[num++] = 0x20; | ||
723 | arr[num++] = (target_dev_id >> 24); | ||
724 | arr[num++] = (target_dev_id >> 16) & 0xff; | ||
725 | arr[num++] = (target_dev_id >> 8) & 0xff; | ||
726 | arr[num++] = target_dev_id & 0xff; | ||
727 | /* SCSI name string: Target device identifier */ | ||
728 | arr[num++] = 0x63; /* proto=sas, UTF-8 */ | ||
729 | arr[num++] = 0xa8; /* piv=1, target device, SCSI name string */ | ||
730 | arr[num++] = 0x0; | ||
731 | arr[num++] = 24; | ||
732 | memcpy(arr + num, "naa.52222220", 12); | ||
733 | num += 12; | ||
734 | snprintf(b, sizeof(b), "%08X", target_dev_id); | ||
735 | memcpy(arr + num, b, 8); | ||
736 | num += 8; | ||
737 | memset(arr + num, 0, 4); | ||
738 | num += 4; | ||
739 | return num; | ||
740 | } | ||
741 | |||
742 | |||
743 | static unsigned char vpd84_data[] = { | ||
744 | /* from 4th byte */ 0x22,0x22,0x22,0x0,0xbb,0x0, | ||
745 | 0x22,0x22,0x22,0x0,0xbb,0x1, | ||
746 | 0x22,0x22,0x22,0x0,0xbb,0x2, | ||
747 | }; | ||
748 | |||
749 | static int inquiry_evpd_84(unsigned char * arr) | ||
750 | { | ||
751 | memcpy(arr, vpd84_data, sizeof(vpd84_data)); | ||
752 | return sizeof(vpd84_data); | ||
753 | } | ||
754 | |||
755 | static int inquiry_evpd_85(unsigned char * arr) | ||
756 | { | ||
757 | int num = 0; | ||
758 | const char * na1 = "https://www.kernel.org/config"; | ||
759 | const char * na2 = "http://www.kernel.org/log"; | ||
760 | int plen, olen; | ||
761 | |||
762 | arr[num++] = 0x1; /* lu, storage config */ | ||
763 | arr[num++] = 0x0; /* reserved */ | ||
764 | arr[num++] = 0x0; | ||
765 | olen = strlen(na1); | ||
766 | plen = olen + 1; | ||
767 | if (plen % 4) | ||
768 | plen = ((plen / 4) + 1) * 4; | ||
769 | arr[num++] = plen; /* length, null termianted, padded */ | ||
770 | memcpy(arr + num, na1, olen); | ||
771 | memset(arr + num + olen, 0, plen - olen); | ||
772 | num += plen; | ||
773 | |||
774 | arr[num++] = 0x4; /* lu, logging */ | ||
775 | arr[num++] = 0x0; /* reserved */ | ||
776 | arr[num++] = 0x0; | ||
777 | olen = strlen(na2); | ||
778 | plen = olen + 1; | ||
779 | if (plen % 4) | ||
780 | plen = ((plen / 4) + 1) * 4; | ||
781 | arr[num++] = plen; /* length, null terminated, padded */ | ||
782 | memcpy(arr + num, na2, olen); | ||
783 | memset(arr + num + olen, 0, plen - olen); | ||
784 | num += plen; | ||
785 | |||
786 | return num; | ||
787 | } | ||
788 | |||
789 | /* SCSI ports VPD page */ | ||
790 | static int inquiry_evpd_88(unsigned char * arr, int target_dev_id) | ||
791 | { | ||
792 | int num = 0; | ||
793 | int port_a, port_b; | ||
794 | |||
795 | port_a = target_dev_id + 1; | ||
796 | port_b = port_a + 1; | ||
797 | arr[num++] = 0x0; /* reserved */ | ||
798 | arr[num++] = 0x0; /* reserved */ | ||
799 | arr[num++] = 0x0; | ||
800 | arr[num++] = 0x1; /* relative port 1 (primary) */ | ||
801 | memset(arr + num, 0, 6); | ||
802 | num += 6; | ||
803 | arr[num++] = 0x0; | ||
804 | arr[num++] = 12; /* length tp descriptor */ | ||
805 | /* naa-5 target port identifier (A) */ | ||
806 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
807 | arr[num++] = 0x93; /* PIV=1, target port, NAA */ | ||
808 | arr[num++] = 0x0; /* reserved */ | ||
809 | arr[num++] = 0x8; /* length */ | ||
810 | arr[num++] = 0x52; /* NAA-5, company_id=0x222222 (fake) */ | ||
811 | arr[num++] = 0x22; | ||
812 | arr[num++] = 0x22; | ||
813 | arr[num++] = 0x20; | ||
814 | arr[num++] = (port_a >> 24); | ||
815 | arr[num++] = (port_a >> 16) & 0xff; | ||
816 | arr[num++] = (port_a >> 8) & 0xff; | ||
817 | arr[num++] = port_a & 0xff; | ||
818 | |||
819 | arr[num++] = 0x0; /* reserved */ | ||
820 | arr[num++] = 0x0; /* reserved */ | ||
821 | arr[num++] = 0x0; | ||
822 | arr[num++] = 0x2; /* relative port 2 (secondary) */ | ||
823 | memset(arr + num, 0, 6); | ||
824 | num += 6; | ||
825 | arr[num++] = 0x0; | ||
826 | arr[num++] = 12; /* length tp descriptor */ | ||
827 | /* naa-5 target port identifier (B) */ | ||
828 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
829 | arr[num++] = 0x93; /* PIV=1, target port, NAA */ | ||
830 | arr[num++] = 0x0; /* reserved */ | ||
831 | arr[num++] = 0x8; /* length */ | ||
832 | arr[num++] = 0x52; /* NAA-5, company_id=0x222222 (fake) */ | ||
833 | arr[num++] = 0x22; | ||
834 | arr[num++] = 0x22; | ||
835 | arr[num++] = 0x20; | ||
836 | arr[num++] = (port_b >> 24); | ||
837 | arr[num++] = (port_b >> 16) & 0xff; | ||
838 | arr[num++] = (port_b >> 8) & 0xff; | ||
839 | arr[num++] = port_b & 0xff; | ||
840 | |||
841 | return num; | ||
842 | } | ||
843 | |||
844 | |||
845 | static unsigned char vpd89_data[] = { | ||
846 | /* from 4th byte */ 0,0,0,0, | ||
847 | 'l','i','n','u','x',' ',' ',' ', | ||
848 | 'S','A','T',' ','s','c','s','i','_','d','e','b','u','g',' ',' ', | ||
849 | '1','2','3','4', | ||
850 | 0x34,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, | ||
851 | 0xec,0,0,0, | ||
852 | 0x5a,0xc,0xff,0x3f,0x37,0xc8,0x10,0,0,0,0,0,0x3f,0,0,0, | ||
853 | 0,0,0,0,0x58,0x58,0x58,0x58,0x58,0x58,0x58,0x58,0x20,0x20,0x20,0x20, | ||
854 | 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0,0,0,0x40,0x4,0,0x2e,0x33, | ||
855 | 0x38,0x31,0x20,0x20,0x20,0x20,0x54,0x53,0x38,0x33,0x30,0x30,0x33,0x31, | ||
856 | 0x53,0x41, | ||
857 | 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
858 | 0x20,0x20, | ||
859 | 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
860 | 0x10,0x80, | ||
861 | 0,0,0,0x2f,0,0,0,0x2,0,0x2,0x7,0,0xff,0xff,0x1,0, | ||
862 | 0x3f,0,0xc1,0xff,0x3e,0,0x10,0x1,0xb0,0xf8,0x50,0x9,0,0,0x7,0, | ||
863 | 0x3,0,0x78,0,0x78,0,0xf0,0,0x78,0,0,0,0,0,0,0, | ||
864 | 0,0,0,0,0,0,0,0,0x2,0,0,0,0,0,0,0, | ||
865 | 0x7e,0,0x1b,0,0x6b,0x34,0x1,0x7d,0x3,0x40,0x69,0x34,0x1,0x3c,0x3,0x40, | ||
866 | 0x7f,0x40,0,0,0,0,0xfe,0xfe,0,0,0,0,0,0xfe,0,0, | ||
867 | 0,0,0,0,0,0,0,0,0xb0,0xf8,0x50,0x9,0,0,0,0, | ||
868 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
869 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
870 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
871 | 0x1,0,0xb0,0xf8,0x50,0x9,0xb0,0xf8,0x50,0x9,0x20,0x20,0x2,0,0xb6,0x42, | ||
872 | 0,0x80,0x8a,0,0x6,0x3c,0xa,0x3c,0xff,0xff,0xc6,0x7,0,0x1,0,0x8, | ||
873 | 0xf0,0xf,0,0x10,0x2,0,0x30,0,0,0,0,0,0,0,0x6,0xfe, | ||
874 | 0,0,0x2,0,0x50,0,0x8a,0,0x4f,0x95,0,0,0x21,0,0xb,0, | ||
875 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
876 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
877 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
878 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
879 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
880 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
881 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
882 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
883 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
884 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
885 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
886 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xa5,0x51, | ||
887 | }; | ||
888 | |||
889 | static int inquiry_evpd_89(unsigned char * arr) | ||
890 | { | ||
891 | memcpy(arr, vpd89_data, sizeof(vpd89_data)); | ||
892 | return sizeof(vpd89_data); | ||
893 | } | ||
894 | |||
895 | |||
896 | static unsigned char vpdb0_data[] = { | ||
897 | /* from 4th byte */ 0,0,0,4, | ||
898 | 0,0,0x4,0, | ||
899 | 0,0,0,64, | ||
900 | }; | ||
901 | |||
902 | static int inquiry_evpd_b0(unsigned char * arr) | ||
903 | { | ||
904 | memcpy(arr, vpdb0_data, sizeof(vpdb0_data)); | ||
905 | if (sdebug_store_sectors > 0x400) { | ||
906 | arr[4] = (sdebug_store_sectors >> 24) & 0xff; | ||
907 | arr[5] = (sdebug_store_sectors >> 16) & 0xff; | ||
908 | arr[6] = (sdebug_store_sectors >> 8) & 0xff; | ||
909 | arr[7] = sdebug_store_sectors & 0xff; | ||
910 | } | ||
911 | return sizeof(vpdb0_data); | ||
599 | } | 912 | } |
600 | 913 | ||
601 | 914 | ||
602 | #define SDEBUG_LONG_INQ_SZ 96 | 915 | #define SDEBUG_LONG_INQ_SZ 96 |
603 | #define SDEBUG_MAX_INQ_ARR_SZ 128 | 916 | #define SDEBUG_MAX_INQ_ARR_SZ 584 |
604 | 917 | ||
605 | static int resp_inquiry(struct scsi_cmnd * scp, int target, | 918 | static int resp_inquiry(struct scsi_cmnd * scp, int target, |
606 | struct sdebug_dev_info * devip) | 919 | struct sdebug_dev_info * devip) |
@@ -608,64 +921,113 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target, | |||
608 | unsigned char pq_pdt; | 921 | unsigned char pq_pdt; |
609 | unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ]; | 922 | unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ]; |
610 | unsigned char *cmd = (unsigned char *)scp->cmnd; | 923 | unsigned char *cmd = (unsigned char *)scp->cmnd; |
611 | int alloc_len; | 924 | int alloc_len, n; |
612 | 925 | ||
613 | alloc_len = (cmd[3] << 8) + cmd[4]; | 926 | alloc_len = (cmd[3] << 8) + cmd[4]; |
614 | memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ); | 927 | memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ); |
615 | pq_pdt = (scsi_debug_ptype & 0x1f); | 928 | if (devip->wlun) |
929 | pq_pdt = 0x1e; /* present, wlun */ | ||
930 | else if (scsi_debug_no_lun_0 && (0 == devip->lun)) | ||
931 | pq_pdt = 0x7f; /* not present, no device type */ | ||
932 | else | ||
933 | pq_pdt = (scsi_debug_ptype & 0x1f); | ||
616 | arr[0] = pq_pdt; | 934 | arr[0] = pq_pdt; |
617 | if (0x2 & cmd[1]) { /* CMDDT bit set */ | 935 | if (0x2 & cmd[1]) { /* CMDDT bit set */ |
618 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | 936 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, |
619 | 0); | 937 | 0); |
620 | return check_condition_result; | 938 | return check_condition_result; |
621 | } else if (0x1 & cmd[1]) { /* EVPD bit set */ | 939 | } else if (0x1 & cmd[1]) { /* EVPD bit set */ |
622 | int dev_id_num, len; | 940 | int lu_id_num, target_dev_id, len; |
623 | char dev_id_str[6]; | 941 | char lu_id_str[6]; |
942 | int host_no = devip->sdbg_host->shost->host_no; | ||
624 | 943 | ||
625 | dev_id_num = ((devip->sdbg_host->shost->host_no + 1) * 2000) + | 944 | lu_id_num = devip->wlun ? -1 : (((host_no + 1) * 2000) + |
626 | (devip->target * 1000) + devip->lun; | 945 | (devip->target * 1000) + devip->lun); |
627 | len = scnprintf(dev_id_str, 6, "%d", dev_id_num); | 946 | target_dev_id = ((host_no + 1) * 2000) + |
947 | (devip->target * 1000) - 3; | ||
948 | len = scnprintf(lu_id_str, 6, "%d", lu_id_num); | ||
628 | if (0 == cmd[2]) { /* supported vital product data pages */ | 949 | if (0 == cmd[2]) { /* supported vital product data pages */ |
629 | arr[3] = 3; | 950 | arr[1] = cmd[2]; /*sanity */ |
630 | arr[4] = 0x0; /* this page */ | 951 | n = 4; |
631 | arr[5] = 0x80; /* unit serial number */ | 952 | arr[n++] = 0x0; /* this page */ |
632 | arr[6] = 0x83; /* device identification */ | 953 | arr[n++] = 0x80; /* unit serial number */ |
954 | arr[n++] = 0x83; /* device identification */ | ||
955 | arr[n++] = 0x84; /* software interface ident. */ | ||
956 | arr[n++] = 0x85; /* management network addresses */ | ||
957 | arr[n++] = 0x86; /* extended inquiry */ | ||
958 | arr[n++] = 0x87; /* mode page policy */ | ||
959 | arr[n++] = 0x88; /* SCSI ports */ | ||
960 | arr[n++] = 0x89; /* ATA information */ | ||
961 | arr[n++] = 0xb0; /* Block limits (SBC) */ | ||
962 | arr[3] = n - 4; /* number of supported VPD pages */ | ||
633 | } else if (0x80 == cmd[2]) { /* unit serial number */ | 963 | } else if (0x80 == cmd[2]) { /* unit serial number */ |
634 | arr[1] = 0x80; | 964 | arr[1] = cmd[2]; /*sanity */ |
635 | arr[3] = len; | 965 | arr[3] = len; |
636 | memcpy(&arr[4], dev_id_str, len); | 966 | memcpy(&arr[4], lu_id_str, len); |
637 | } else if (0x83 == cmd[2]) { /* device identification */ | 967 | } else if (0x83 == cmd[2]) { /* device identification */ |
638 | arr[1] = 0x83; | 968 | arr[1] = cmd[2]; /*sanity */ |
639 | arr[3] = inquiry_evpd_83(&arr[4], dev_id_num, | 969 | arr[3] = inquiry_evpd_83(&arr[4], target_dev_id, |
640 | dev_id_str, len); | 970 | lu_id_num, lu_id_str, len); |
971 | } else if (0x84 == cmd[2]) { /* Software interface ident. */ | ||
972 | arr[1] = cmd[2]; /*sanity */ | ||
973 | arr[3] = inquiry_evpd_84(&arr[4]); | ||
974 | } else if (0x85 == cmd[2]) { /* Management network addresses */ | ||
975 | arr[1] = cmd[2]; /*sanity */ | ||
976 | arr[3] = inquiry_evpd_85(&arr[4]); | ||
977 | } else if (0x86 == cmd[2]) { /* extended inquiry */ | ||
978 | arr[1] = cmd[2]; /*sanity */ | ||
979 | arr[3] = 0x3c; /* number of following entries */ | ||
980 | arr[4] = 0x0; /* no protection stuff */ | ||
981 | arr[5] = 0x7; /* head of q, ordered + simple q's */ | ||
982 | } else if (0x87 == cmd[2]) { /* mode page policy */ | ||
983 | arr[1] = cmd[2]; /*sanity */ | ||
984 | arr[3] = 0x8; /* number of following entries */ | ||
985 | arr[4] = 0x2; /* disconnect-reconnect mp */ | ||
986 | arr[6] = 0x80; /* mlus, shared */ | ||
987 | arr[8] = 0x18; /* protocol specific lu */ | ||
988 | arr[10] = 0x82; /* mlus, per initiator port */ | ||
989 | } else if (0x88 == cmd[2]) { /* SCSI Ports */ | ||
990 | arr[1] = cmd[2]; /*sanity */ | ||
991 | arr[3] = inquiry_evpd_88(&arr[4], target_dev_id); | ||
992 | } else if (0x89 == cmd[2]) { /* ATA information */ | ||
993 | arr[1] = cmd[2]; /*sanity */ | ||
994 | n = inquiry_evpd_89(&arr[4]); | ||
995 | arr[2] = (n >> 8); | ||
996 | arr[3] = (n & 0xff); | ||
997 | } else if (0xb0 == cmd[2]) { /* Block limits (SBC) */ | ||
998 | arr[1] = cmd[2]; /*sanity */ | ||
999 | arr[3] = inquiry_evpd_b0(&arr[4]); | ||
641 | } else { | 1000 | } else { |
642 | /* Illegal request, invalid field in cdb */ | 1001 | /* Illegal request, invalid field in cdb */ |
643 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | 1002 | mk_sense_buffer(devip, ILLEGAL_REQUEST, |
644 | INVALID_FIELD_IN_CDB, 0); | 1003 | INVALID_FIELD_IN_CDB, 0); |
645 | return check_condition_result; | 1004 | return check_condition_result; |
646 | } | 1005 | } |
1006 | len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len); | ||
647 | return fill_from_dev_buffer(scp, arr, | 1007 | return fill_from_dev_buffer(scp, arr, |
648 | min(alloc_len, SDEBUG_MAX_INQ_ARR_SZ)); | 1008 | min(len, SDEBUG_MAX_INQ_ARR_SZ)); |
649 | } | 1009 | } |
650 | /* drops through here for a standard inquiry */ | 1010 | /* drops through here for a standard inquiry */ |
651 | arr[1] = DEV_REMOVEABLE(target) ? 0x80 : 0; /* Removable disk */ | 1011 | arr[1] = DEV_REMOVEABLE(target) ? 0x80 : 0; /* Removable disk */ |
652 | arr[2] = scsi_debug_scsi_level; | 1012 | arr[2] = scsi_debug_scsi_level; |
653 | arr[3] = 2; /* response_data_format==2 */ | 1013 | arr[3] = 2; /* response_data_format==2 */ |
654 | arr[4] = SDEBUG_LONG_INQ_SZ - 5; | 1014 | arr[4] = SDEBUG_LONG_INQ_SZ - 5; |
655 | arr[6] = 0x1; /* claim: ADDR16 */ | 1015 | arr[6] = 0x10; /* claim: MultiP */ |
656 | /* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */ | 1016 | /* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */ |
657 | arr[7] = 0x3a; /* claim: WBUS16, SYNC, LINKED + CMDQUE */ | 1017 | arr[7] = 0xa; /* claim: LINKED + CMDQUE */ |
658 | memcpy(&arr[8], inq_vendor_id, 8); | 1018 | memcpy(&arr[8], inq_vendor_id, 8); |
659 | memcpy(&arr[16], inq_product_id, 16); | 1019 | memcpy(&arr[16], inq_product_id, 16); |
660 | memcpy(&arr[32], inq_product_rev, 4); | 1020 | memcpy(&arr[32], inq_product_rev, 4); |
661 | /* version descriptors (2 bytes each) follow */ | 1021 | /* version descriptors (2 bytes each) follow */ |
662 | arr[58] = 0x0; arr[59] = 0x40; /* SAM-2 */ | 1022 | arr[58] = 0x0; arr[59] = 0x77; /* SAM-3 ANSI */ |
663 | arr[60] = 0x3; arr[61] = 0x0; /* SPC-3 */ | 1023 | arr[60] = 0x3; arr[61] = 0x14; /* SPC-3 ANSI */ |
1024 | n = 62; | ||
664 | if (scsi_debug_ptype == 0) { | 1025 | if (scsi_debug_ptype == 0) { |
665 | arr[62] = 0x1; arr[63] = 0x80; /* SBC */ | 1026 | arr[n++] = 0x3; arr[n++] = 0x3d; /* SBC-2 ANSI */ |
666 | } else if (scsi_debug_ptype == 1) { | 1027 | } else if (scsi_debug_ptype == 1) { |
667 | arr[62] = 0x2; arr[63] = 0x00; /* SSC */ | 1028 | arr[n++] = 0x3; arr[n++] = 0x60; /* SSC-2 no version */ |
668 | } | 1029 | } |
1030 | arr[n++] = 0xc; arr[n++] = 0xf; /* SAS-1.1 rev 10 */ | ||
669 | return fill_from_dev_buffer(scp, arr, | 1031 | return fill_from_dev_buffer(scp, arr, |
670 | min(alloc_len, SDEBUG_LONG_INQ_SZ)); | 1032 | min(alloc_len, SDEBUG_LONG_INQ_SZ)); |
671 | } | 1033 | } |
@@ -676,46 +1038,141 @@ static int resp_requests(struct scsi_cmnd * scp, | |||
676 | unsigned char * sbuff; | 1038 | unsigned char * sbuff; |
677 | unsigned char *cmd = (unsigned char *)scp->cmnd; | 1039 | unsigned char *cmd = (unsigned char *)scp->cmnd; |
678 | unsigned char arr[SDEBUG_SENSE_LEN]; | 1040 | unsigned char arr[SDEBUG_SENSE_LEN]; |
1041 | int want_dsense; | ||
679 | int len = 18; | 1042 | int len = 18; |
680 | 1043 | ||
681 | memset(arr, 0, SDEBUG_SENSE_LEN); | 1044 | memset(arr, 0, sizeof(arr)); |
682 | if (devip->reset == 1) | 1045 | if (devip->reset == 1) |
683 | mk_sense_buffer(devip, 0, NO_ADDED_SENSE, 0); | 1046 | mk_sense_buffer(devip, 0, NO_ADDITIONAL_SENSE, 0); |
1047 | want_dsense = !!(cmd[1] & 1) || scsi_debug_dsense; | ||
684 | sbuff = devip->sense_buff; | 1048 | sbuff = devip->sense_buff; |
685 | if ((cmd[1] & 1) && (! scsi_debug_dsense)) { | 1049 | if ((iec_m_pg[2] & 0x4) && (6 == (iec_m_pg[3] & 0xf))) { |
686 | /* DESC bit set and sense_buff in fixed format */ | 1050 | if (want_dsense) { |
687 | arr[0] = 0x72; | 1051 | arr[0] = 0x72; |
688 | arr[1] = sbuff[2]; /* sense key */ | 1052 | arr[1] = 0x0; /* NO_SENSE in sense_key */ |
689 | arr[2] = sbuff[12]; /* asc */ | 1053 | arr[2] = THRESHOLD_EXCEEDED; |
690 | arr[3] = sbuff[13]; /* ascq */ | 1054 | arr[3] = 0xff; /* TEST set and MRIE==6 */ |
691 | len = 8; | 1055 | } else { |
692 | } else | 1056 | arr[0] = 0x70; |
1057 | arr[2] = 0x0; /* NO_SENSE in sense_key */ | ||
1058 | arr[7] = 0xa; /* 18 byte sense buffer */ | ||
1059 | arr[12] = THRESHOLD_EXCEEDED; | ||
1060 | arr[13] = 0xff; /* TEST set and MRIE==6 */ | ||
1061 | } | ||
1062 | } else if (devip->stopped) { | ||
1063 | if (want_dsense) { | ||
1064 | arr[0] = 0x72; | ||
1065 | arr[1] = 0x0; /* NO_SENSE in sense_key */ | ||
1066 | arr[2] = LOW_POWER_COND_ON; | ||
1067 | arr[3] = 0x0; /* TEST set and MRIE==6 */ | ||
1068 | } else { | ||
1069 | arr[0] = 0x70; | ||
1070 | arr[2] = 0x0; /* NO_SENSE in sense_key */ | ||
1071 | arr[7] = 0xa; /* 18 byte sense buffer */ | ||
1072 | arr[12] = LOW_POWER_COND_ON; | ||
1073 | arr[13] = 0x0; /* TEST set and MRIE==6 */ | ||
1074 | } | ||
1075 | } else { | ||
693 | memcpy(arr, sbuff, SDEBUG_SENSE_LEN); | 1076 | memcpy(arr, sbuff, SDEBUG_SENSE_LEN); |
694 | mk_sense_buffer(devip, 0, NO_ADDED_SENSE, 0); | 1077 | if ((cmd[1] & 1) && (! scsi_debug_dsense)) { |
1078 | /* DESC bit set and sense_buff in fixed format */ | ||
1079 | memset(arr, 0, sizeof(arr)); | ||
1080 | arr[0] = 0x72; | ||
1081 | arr[1] = sbuff[2]; /* sense key */ | ||
1082 | arr[2] = sbuff[12]; /* asc */ | ||
1083 | arr[3] = sbuff[13]; /* ascq */ | ||
1084 | len = 8; | ||
1085 | } | ||
1086 | } | ||
1087 | mk_sense_buffer(devip, 0, NO_ADDITIONAL_SENSE, 0); | ||
695 | return fill_from_dev_buffer(scp, arr, len); | 1088 | return fill_from_dev_buffer(scp, arr, len); |
696 | } | 1089 | } |
697 | 1090 | ||
1091 | static int resp_start_stop(struct scsi_cmnd * scp, | ||
1092 | struct sdebug_dev_info * devip) | ||
1093 | { | ||
1094 | unsigned char *cmd = (unsigned char *)scp->cmnd; | ||
1095 | int power_cond, errsts, start; | ||
1096 | |||
1097 | if ((errsts = check_readiness(scp, 1, devip))) | ||
1098 | return errsts; | ||
1099 | power_cond = (cmd[4] & 0xf0) >> 4; | ||
1100 | if (power_cond) { | ||
1101 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | ||
1102 | 0); | ||
1103 | return check_condition_result; | ||
1104 | } | ||
1105 | start = cmd[4] & 1; | ||
1106 | if (start == devip->stopped) | ||
1107 | devip->stopped = !start; | ||
1108 | return 0; | ||
1109 | } | ||
1110 | |||
698 | #define SDEBUG_READCAP_ARR_SZ 8 | 1111 | #define SDEBUG_READCAP_ARR_SZ 8 |
699 | static int resp_readcap(struct scsi_cmnd * scp, | 1112 | static int resp_readcap(struct scsi_cmnd * scp, |
700 | struct sdebug_dev_info * devip) | 1113 | struct sdebug_dev_info * devip) |
701 | { | 1114 | { |
702 | unsigned char arr[SDEBUG_READCAP_ARR_SZ]; | 1115 | unsigned char arr[SDEBUG_READCAP_ARR_SZ]; |
703 | unsigned long capac; | 1116 | unsigned int capac; |
704 | int errsts; | 1117 | int errsts; |
705 | 1118 | ||
706 | if ((errsts = check_reset(scp, devip))) | 1119 | if ((errsts = check_readiness(scp, 1, devip))) |
707 | return errsts; | 1120 | return errsts; |
1121 | /* following just in case virtual_gb changed */ | ||
1122 | if (scsi_debug_virtual_gb > 0) { | ||
1123 | sdebug_capacity = 2048 * 1024; | ||
1124 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
1125 | } else | ||
1126 | sdebug_capacity = sdebug_store_sectors; | ||
708 | memset(arr, 0, SDEBUG_READCAP_ARR_SZ); | 1127 | memset(arr, 0, SDEBUG_READCAP_ARR_SZ); |
709 | capac = (unsigned long)sdebug_capacity - 1; | 1128 | if (sdebug_capacity < 0xffffffff) { |
710 | arr[0] = (capac >> 24); | 1129 | capac = (unsigned int)sdebug_capacity - 1; |
711 | arr[1] = (capac >> 16) & 0xff; | 1130 | arr[0] = (capac >> 24); |
712 | arr[2] = (capac >> 8) & 0xff; | 1131 | arr[1] = (capac >> 16) & 0xff; |
713 | arr[3] = capac & 0xff; | 1132 | arr[2] = (capac >> 8) & 0xff; |
1133 | arr[3] = capac & 0xff; | ||
1134 | } else { | ||
1135 | arr[0] = 0xff; | ||
1136 | arr[1] = 0xff; | ||
1137 | arr[2] = 0xff; | ||
1138 | arr[3] = 0xff; | ||
1139 | } | ||
714 | arr[6] = (SECT_SIZE_PER(target) >> 8) & 0xff; | 1140 | arr[6] = (SECT_SIZE_PER(target) >> 8) & 0xff; |
715 | arr[7] = SECT_SIZE_PER(target) & 0xff; | 1141 | arr[7] = SECT_SIZE_PER(target) & 0xff; |
716 | return fill_from_dev_buffer(scp, arr, SDEBUG_READCAP_ARR_SZ); | 1142 | return fill_from_dev_buffer(scp, arr, SDEBUG_READCAP_ARR_SZ); |
717 | } | 1143 | } |
718 | 1144 | ||
1145 | #define SDEBUG_READCAP16_ARR_SZ 32 | ||
1146 | static int resp_readcap16(struct scsi_cmnd * scp, | ||
1147 | struct sdebug_dev_info * devip) | ||
1148 | { | ||
1149 | unsigned char *cmd = (unsigned char *)scp->cmnd; | ||
1150 | unsigned char arr[SDEBUG_READCAP16_ARR_SZ]; | ||
1151 | unsigned long long capac; | ||
1152 | int errsts, k, alloc_len; | ||
1153 | |||
1154 | if ((errsts = check_readiness(scp, 1, devip))) | ||
1155 | return errsts; | ||
1156 | alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8) | ||
1157 | + cmd[13]); | ||
1158 | /* following just in case virtual_gb changed */ | ||
1159 | if (scsi_debug_virtual_gb > 0) { | ||
1160 | sdebug_capacity = 2048 * 1024; | ||
1161 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
1162 | } else | ||
1163 | sdebug_capacity = sdebug_store_sectors; | ||
1164 | memset(arr, 0, SDEBUG_READCAP16_ARR_SZ); | ||
1165 | capac = sdebug_capacity - 1; | ||
1166 | for (k = 0; k < 8; ++k, capac >>= 8) | ||
1167 | arr[7 - k] = capac & 0xff; | ||
1168 | arr[8] = (SECT_SIZE_PER(target) >> 24) & 0xff; | ||
1169 | arr[9] = (SECT_SIZE_PER(target) >> 16) & 0xff; | ||
1170 | arr[10] = (SECT_SIZE_PER(target) >> 8) & 0xff; | ||
1171 | arr[11] = SECT_SIZE_PER(target) & 0xff; | ||
1172 | return fill_from_dev_buffer(scp, arr, | ||
1173 | min(alloc_len, SDEBUG_READCAP16_ARR_SZ)); | ||
1174 | } | ||
1175 | |||
719 | /* <<Following mode page info copied from ST318451LW>> */ | 1176 | /* <<Following mode page info copied from ST318451LW>> */ |
720 | 1177 | ||
721 | static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target) | 1178 | static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target) |
@@ -771,27 +1228,98 @@ static int resp_caching_pg(unsigned char * p, int pcontrol, int target) | |||
771 | 1228 | ||
772 | static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target) | 1229 | static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target) |
773 | { /* Control mode page for mode_sense */ | 1230 | { /* Control mode page for mode_sense */ |
774 | unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | 1231 | unsigned char ch_ctrl_m_pg[] = {/* 0xa, 10, */ 0x6, 0, 0, 0, 0, 0, |
1232 | 0, 0, 0, 0}; | ||
1233 | unsigned char d_ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | ||
775 | 0, 0, 0x2, 0x4b}; | 1234 | 0, 0, 0x2, 0x4b}; |
776 | 1235 | ||
777 | if (scsi_debug_dsense) | 1236 | if (scsi_debug_dsense) |
778 | ctrl_m_pg[2] |= 0x4; | 1237 | ctrl_m_pg[2] |= 0x4; |
1238 | else | ||
1239 | ctrl_m_pg[2] &= ~0x4; | ||
779 | memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg)); | 1240 | memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg)); |
780 | if (1 == pcontrol) | 1241 | if (1 == pcontrol) |
781 | memset(p + 2, 0, sizeof(ctrl_m_pg) - 2); | 1242 | memcpy(p + 2, ch_ctrl_m_pg, sizeof(ch_ctrl_m_pg)); |
1243 | else if (2 == pcontrol) | ||
1244 | memcpy(p, d_ctrl_m_pg, sizeof(d_ctrl_m_pg)); | ||
782 | return sizeof(ctrl_m_pg); | 1245 | return sizeof(ctrl_m_pg); |
783 | } | 1246 | } |
784 | 1247 | ||
1248 | |||
785 | static int resp_iec_m_pg(unsigned char * p, int pcontrol, int target) | 1249 | static int resp_iec_m_pg(unsigned char * p, int pcontrol, int target) |
786 | { /* Informational Exceptions control mode page for mode_sense */ | 1250 | { /* Informational Exceptions control mode page for mode_sense */ |
787 | unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0, | 1251 | unsigned char ch_iec_m_pg[] = {/* 0x1c, 0xa, */ 0x4, 0xf, 0, 0, 0, 0, |
788 | 0, 0, 0x0, 0x0}; | 1252 | 0, 0, 0x0, 0x0}; |
1253 | unsigned char d_iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0, | ||
1254 | 0, 0, 0x0, 0x0}; | ||
1255 | |||
789 | memcpy(p, iec_m_pg, sizeof(iec_m_pg)); | 1256 | memcpy(p, iec_m_pg, sizeof(iec_m_pg)); |
790 | if (1 == pcontrol) | 1257 | if (1 == pcontrol) |
791 | memset(p + 2, 0, sizeof(iec_m_pg) - 2); | 1258 | memcpy(p + 2, ch_iec_m_pg, sizeof(ch_iec_m_pg)); |
1259 | else if (2 == pcontrol) | ||
1260 | memcpy(p, d_iec_m_pg, sizeof(d_iec_m_pg)); | ||
792 | return sizeof(iec_m_pg); | 1261 | return sizeof(iec_m_pg); |
793 | } | 1262 | } |
794 | 1263 | ||
1264 | static int resp_sas_sf_m_pg(unsigned char * p, int pcontrol, int target) | ||
1265 | { /* SAS SSP mode page - short format for mode_sense */ | ||
1266 | unsigned char sas_sf_m_pg[] = {0x19, 0x6, | ||
1267 | 0x6, 0x0, 0x7, 0xd0, 0x0, 0x0}; | ||
1268 | |||
1269 | memcpy(p, sas_sf_m_pg, sizeof(sas_sf_m_pg)); | ||
1270 | if (1 == pcontrol) | ||
1271 | memset(p + 2, 0, sizeof(sas_sf_m_pg) - 2); | ||
1272 | return sizeof(sas_sf_m_pg); | ||
1273 | } | ||
1274 | |||
1275 | |||
1276 | static int resp_sas_pcd_m_spg(unsigned char * p, int pcontrol, int target, | ||
1277 | int target_dev_id) | ||
1278 | { /* SAS phy control and discover mode page for mode_sense */ | ||
1279 | unsigned char sas_pcd_m_pg[] = {0x59, 0x1, 0, 0x64, 0, 0x6, 0, 2, | ||
1280 | 0, 0, 0, 0, 0x10, 0x9, 0x8, 0x0, | ||
1281 | 0x52, 0x22, 0x22, 0x20, 0x0, 0x0, 0x0, 0x0, | ||
1282 | 0x51, 0x11, 0x11, 0x10, 0x0, 0x0, 0x0, 0x1, | ||
1283 | 0x2, 0, 0, 0, 0, 0, 0, 0, | ||
1284 | 0x88, 0x99, 0, 0, 0, 0, 0, 0, | ||
1285 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
1286 | 0, 1, 0, 0, 0x10, 0x9, 0x8, 0x0, | ||
1287 | 0x52, 0x22, 0x22, 0x20, 0x0, 0x0, 0x0, 0x0, | ||
1288 | 0x51, 0x11, 0x11, 0x10, 0x0, 0x0, 0x0, 0x1, | ||
1289 | 0x3, 0, 0, 0, 0, 0, 0, 0, | ||
1290 | 0x88, 0x99, 0, 0, 0, 0, 0, 0, | ||
1291 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
1292 | }; | ||
1293 | int port_a, port_b; | ||
1294 | |||
1295 | port_a = target_dev_id + 1; | ||
1296 | port_b = port_a + 1; | ||
1297 | memcpy(p, sas_pcd_m_pg, sizeof(sas_pcd_m_pg)); | ||
1298 | p[20] = (port_a >> 24); | ||
1299 | p[21] = (port_a >> 16) & 0xff; | ||
1300 | p[22] = (port_a >> 8) & 0xff; | ||
1301 | p[23] = port_a & 0xff; | ||
1302 | p[48 + 20] = (port_b >> 24); | ||
1303 | p[48 + 21] = (port_b >> 16) & 0xff; | ||
1304 | p[48 + 22] = (port_b >> 8) & 0xff; | ||
1305 | p[48 + 23] = port_b & 0xff; | ||
1306 | if (1 == pcontrol) | ||
1307 | memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4); | ||
1308 | return sizeof(sas_pcd_m_pg); | ||
1309 | } | ||
1310 | |||
1311 | static int resp_sas_sha_m_spg(unsigned char * p, int pcontrol) | ||
1312 | { /* SAS SSP shared protocol specific port mode subpage */ | ||
1313 | unsigned char sas_sha_m_pg[] = {0x59, 0x2, 0, 0xc, 0, 0x6, 0x10, 0, | ||
1314 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
1315 | }; | ||
1316 | |||
1317 | memcpy(p, sas_sha_m_pg, sizeof(sas_sha_m_pg)); | ||
1318 | if (1 == pcontrol) | ||
1319 | memset(p + 4, 0, sizeof(sas_sha_m_pg) - 4); | ||
1320 | return sizeof(sas_sha_m_pg); | ||
1321 | } | ||
1322 | |||
795 | #define SDEBUG_MAX_MSENSE_SZ 256 | 1323 | #define SDEBUG_MAX_MSENSE_SZ 256 |
796 | 1324 | ||
797 | static int resp_mode_sense(struct scsi_cmnd * scp, int target, | 1325 | static int resp_mode_sense(struct scsi_cmnd * scp, int target, |
@@ -800,12 +1328,12 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
800 | unsigned char dbd; | 1328 | unsigned char dbd; |
801 | int pcontrol, pcode, subpcode; | 1329 | int pcontrol, pcode, subpcode; |
802 | unsigned char dev_spec; | 1330 | unsigned char dev_spec; |
803 | int alloc_len, msense_6, offset, len, errsts; | 1331 | int alloc_len, msense_6, offset, len, errsts, target_dev_id; |
804 | unsigned char * ap; | 1332 | unsigned char * ap; |
805 | unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; | 1333 | unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; |
806 | unsigned char *cmd = (unsigned char *)scp->cmnd; | 1334 | unsigned char *cmd = (unsigned char *)scp->cmnd; |
807 | 1335 | ||
808 | if ((errsts = check_reset(scp, devip))) | 1336 | if ((errsts = check_readiness(scp, 1, devip))) |
809 | return errsts; | 1337 | return errsts; |
810 | dbd = cmd[1] & 0x8; | 1338 | dbd = cmd[1] & 0x8; |
811 | pcontrol = (cmd[2] & 0xc0) >> 6; | 1339 | pcontrol = (cmd[2] & 0xc0) >> 6; |
@@ -819,6 +1347,8 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
819 | 0); | 1347 | 0); |
820 | return check_condition_result; | 1348 | return check_condition_result; |
821 | } | 1349 | } |
1350 | target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) + | ||
1351 | (devip->target * 1000) - 3; | ||
822 | dev_spec = DEV_READONLY(target) ? 0x80 : 0x0; | 1352 | dev_spec = DEV_READONLY(target) ? 0x80 : 0x0; |
823 | if (msense_6) { | 1353 | if (msense_6) { |
824 | arr[2] = dev_spec; | 1354 | arr[2] = dev_spec; |
@@ -829,7 +1359,8 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
829 | } | 1359 | } |
830 | ap = arr + offset; | 1360 | ap = arr + offset; |
831 | 1361 | ||
832 | if (0 != subpcode) { /* TODO: Control Extension page */ | 1362 | if ((subpcode > 0x0) && (subpcode < 0xff) && (0x19 != pcode)) { |
1363 | /* TODO: Control Extension page */ | ||
833 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | 1364 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, |
834 | 0); | 1365 | 0); |
835 | return check_condition_result; | 1366 | return check_condition_result; |
@@ -855,17 +1386,45 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
855 | len = resp_ctrl_m_pg(ap, pcontrol, target); | 1386 | len = resp_ctrl_m_pg(ap, pcontrol, target); |
856 | offset += len; | 1387 | offset += len; |
857 | break; | 1388 | break; |
1389 | case 0x19: /* if spc==1 then sas phy, control+discover */ | ||
1390 | if ((subpcode > 0x2) && (subpcode < 0xff)) { | ||
1391 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1392 | INVALID_FIELD_IN_CDB, 0); | ||
1393 | return check_condition_result; | ||
1394 | } | ||
1395 | len = 0; | ||
1396 | if ((0x0 == subpcode) || (0xff == subpcode)) | ||
1397 | len += resp_sas_sf_m_pg(ap + len, pcontrol, target); | ||
1398 | if ((0x1 == subpcode) || (0xff == subpcode)) | ||
1399 | len += resp_sas_pcd_m_spg(ap + len, pcontrol, target, | ||
1400 | target_dev_id); | ||
1401 | if ((0x2 == subpcode) || (0xff == subpcode)) | ||
1402 | len += resp_sas_sha_m_spg(ap + len, pcontrol); | ||
1403 | offset += len; | ||
1404 | break; | ||
858 | case 0x1c: /* Informational Exceptions Mode page, all devices */ | 1405 | case 0x1c: /* Informational Exceptions Mode page, all devices */ |
859 | len = resp_iec_m_pg(ap, pcontrol, target); | 1406 | len = resp_iec_m_pg(ap, pcontrol, target); |
860 | offset += len; | 1407 | offset += len; |
861 | break; | 1408 | break; |
862 | case 0x3f: /* Read all Mode pages */ | 1409 | case 0x3f: /* Read all Mode pages */ |
863 | len = resp_err_recov_pg(ap, pcontrol, target); | 1410 | if ((0 == subpcode) || (0xff == subpcode)) { |
864 | len += resp_disconnect_pg(ap + len, pcontrol, target); | 1411 | len = resp_err_recov_pg(ap, pcontrol, target); |
865 | len += resp_format_pg(ap + len, pcontrol, target); | 1412 | len += resp_disconnect_pg(ap + len, pcontrol, target); |
866 | len += resp_caching_pg(ap + len, pcontrol, target); | 1413 | len += resp_format_pg(ap + len, pcontrol, target); |
867 | len += resp_ctrl_m_pg(ap + len, pcontrol, target); | 1414 | len += resp_caching_pg(ap + len, pcontrol, target); |
868 | len += resp_iec_m_pg(ap + len, pcontrol, target); | 1415 | len += resp_ctrl_m_pg(ap + len, pcontrol, target); |
1416 | len += resp_sas_sf_m_pg(ap + len, pcontrol, target); | ||
1417 | if (0xff == subpcode) { | ||
1418 | len += resp_sas_pcd_m_spg(ap + len, pcontrol, | ||
1419 | target, target_dev_id); | ||
1420 | len += resp_sas_sha_m_spg(ap + len, pcontrol); | ||
1421 | } | ||
1422 | len += resp_iec_m_pg(ap + len, pcontrol, target); | ||
1423 | } else { | ||
1424 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1425 | INVALID_FIELD_IN_CDB, 0); | ||
1426 | return check_condition_result; | ||
1427 | } | ||
869 | offset += len; | 1428 | offset += len; |
870 | break; | 1429 | break; |
871 | default: | 1430 | default: |
@@ -882,71 +1441,274 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
882 | return fill_from_dev_buffer(scp, arr, min(alloc_len, offset)); | 1441 | return fill_from_dev_buffer(scp, arr, min(alloc_len, offset)); |
883 | } | 1442 | } |
884 | 1443 | ||
885 | static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, | 1444 | #define SDEBUG_MAX_MSELECT_SZ 512 |
886 | int num, struct sdebug_dev_info * devip) | 1445 | |
1446 | static int resp_mode_select(struct scsi_cmnd * scp, int mselect6, | ||
1447 | struct sdebug_dev_info * devip) | ||
1448 | { | ||
1449 | int pf, sp, ps, md_len, bd_len, off, spf, pg_len; | ||
1450 | int param_len, res, errsts, mpage; | ||
1451 | unsigned char arr[SDEBUG_MAX_MSELECT_SZ]; | ||
1452 | unsigned char *cmd = (unsigned char *)scp->cmnd; | ||
1453 | |||
1454 | if ((errsts = check_readiness(scp, 1, devip))) | ||
1455 | return errsts; | ||
1456 | memset(arr, 0, sizeof(arr)); | ||
1457 | pf = cmd[1] & 0x10; | ||
1458 | sp = cmd[1] & 0x1; | ||
1459 | param_len = mselect6 ? cmd[4] : ((cmd[7] << 8) + cmd[8]); | ||
1460 | if ((0 == pf) || sp || (param_len > SDEBUG_MAX_MSELECT_SZ)) { | ||
1461 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1462 | INVALID_FIELD_IN_CDB, 0); | ||
1463 | return check_condition_result; | ||
1464 | } | ||
1465 | res = fetch_to_dev_buffer(scp, arr, param_len); | ||
1466 | if (-1 == res) | ||
1467 | return (DID_ERROR << 16); | ||
1468 | else if ((res < param_len) && | ||
1469 | (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) | ||
1470 | printk(KERN_INFO "scsi_debug: mode_select: cdb indicated=%d, " | ||
1471 | " IO sent=%d bytes\n", param_len, res); | ||
1472 | md_len = mselect6 ? (arr[0] + 1) : ((arr[0] << 8) + arr[1] + 2); | ||
1473 | bd_len = mselect6 ? arr[3] : ((arr[6] << 8) + arr[7]); | ||
1474 | if ((md_len > 2) || (0 != bd_len)) { | ||
1475 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1476 | INVALID_FIELD_IN_PARAM_LIST, 0); | ||
1477 | return check_condition_result; | ||
1478 | } | ||
1479 | off = bd_len + (mselect6 ? 4 : 8); | ||
1480 | mpage = arr[off] & 0x3f; | ||
1481 | ps = !!(arr[off] & 0x80); | ||
1482 | if (ps) { | ||
1483 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1484 | INVALID_FIELD_IN_PARAM_LIST, 0); | ||
1485 | return check_condition_result; | ||
1486 | } | ||
1487 | spf = !!(arr[off] & 0x40); | ||
1488 | pg_len = spf ? ((arr[off + 2] << 8) + arr[off + 3] + 4) : | ||
1489 | (arr[off + 1] + 2); | ||
1490 | if ((pg_len + off) > param_len) { | ||
1491 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1492 | PARAMETER_LIST_LENGTH_ERR, 0); | ||
1493 | return check_condition_result; | ||
1494 | } | ||
1495 | switch (mpage) { | ||
1496 | case 0xa: /* Control Mode page */ | ||
1497 | if (ctrl_m_pg[1] == arr[off + 1]) { | ||
1498 | memcpy(ctrl_m_pg + 2, arr + off + 2, | ||
1499 | sizeof(ctrl_m_pg) - 2); | ||
1500 | scsi_debug_dsense = !!(ctrl_m_pg[2] & 0x4); | ||
1501 | return 0; | ||
1502 | } | ||
1503 | break; | ||
1504 | case 0x1c: /* Informational Exceptions Mode page */ | ||
1505 | if (iec_m_pg[1] == arr[off + 1]) { | ||
1506 | memcpy(iec_m_pg + 2, arr + off + 2, | ||
1507 | sizeof(iec_m_pg) - 2); | ||
1508 | return 0; | ||
1509 | } | ||
1510 | break; | ||
1511 | default: | ||
1512 | break; | ||
1513 | } | ||
1514 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1515 | INVALID_FIELD_IN_PARAM_LIST, 0); | ||
1516 | return check_condition_result; | ||
1517 | } | ||
1518 | |||
1519 | static int resp_temp_l_pg(unsigned char * arr) | ||
1520 | { | ||
1521 | unsigned char temp_l_pg[] = {0x0, 0x0, 0x3, 0x2, 0x0, 38, | ||
1522 | 0x0, 0x1, 0x3, 0x2, 0x0, 65, | ||
1523 | }; | ||
1524 | |||
1525 | memcpy(arr, temp_l_pg, sizeof(temp_l_pg)); | ||
1526 | return sizeof(temp_l_pg); | ||
1527 | } | ||
1528 | |||
1529 | static int resp_ie_l_pg(unsigned char * arr) | ||
1530 | { | ||
1531 | unsigned char ie_l_pg[] = {0x0, 0x0, 0x3, 0x3, 0x0, 0x0, 38, | ||
1532 | }; | ||
1533 | |||
1534 | memcpy(arr, ie_l_pg, sizeof(ie_l_pg)); | ||
1535 | if (iec_m_pg[2] & 0x4) { /* TEST bit set */ | ||
1536 | arr[4] = THRESHOLD_EXCEEDED; | ||
1537 | arr[5] = 0xff; | ||
1538 | } | ||
1539 | return sizeof(ie_l_pg); | ||
1540 | } | ||
1541 | |||
1542 | #define SDEBUG_MAX_LSENSE_SZ 512 | ||
1543 | |||
1544 | static int resp_log_sense(struct scsi_cmnd * scp, | ||
1545 | struct sdebug_dev_info * devip) | ||
1546 | { | ||
1547 | int ppc, sp, pcontrol, pcode, alloc_len, errsts, len, n; | ||
1548 | unsigned char arr[SDEBUG_MAX_LSENSE_SZ]; | ||
1549 | unsigned char *cmd = (unsigned char *)scp->cmnd; | ||
1550 | |||
1551 | if ((errsts = check_readiness(scp, 1, devip))) | ||
1552 | return errsts; | ||
1553 | memset(arr, 0, sizeof(arr)); | ||
1554 | ppc = cmd[1] & 0x2; | ||
1555 | sp = cmd[1] & 0x1; | ||
1556 | if (ppc || sp) { | ||
1557 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1558 | INVALID_FIELD_IN_CDB, 0); | ||
1559 | return check_condition_result; | ||
1560 | } | ||
1561 | pcontrol = (cmd[2] & 0xc0) >> 6; | ||
1562 | pcode = cmd[2] & 0x3f; | ||
1563 | alloc_len = (cmd[7] << 8) + cmd[8]; | ||
1564 | arr[0] = pcode; | ||
1565 | switch (pcode) { | ||
1566 | case 0x0: /* Supported log pages log page */ | ||
1567 | n = 4; | ||
1568 | arr[n++] = 0x0; /* this page */ | ||
1569 | arr[n++] = 0xd; /* Temperature */ | ||
1570 | arr[n++] = 0x2f; /* Informational exceptions */ | ||
1571 | arr[3] = n - 4; | ||
1572 | break; | ||
1573 | case 0xd: /* Temperature log page */ | ||
1574 | arr[3] = resp_temp_l_pg(arr + 4); | ||
1575 | break; | ||
1576 | case 0x2f: /* Informational exceptions log page */ | ||
1577 | arr[3] = resp_ie_l_pg(arr + 4); | ||
1578 | break; | ||
1579 | default: | ||
1580 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1581 | INVALID_FIELD_IN_CDB, 0); | ||
1582 | return check_condition_result; | ||
1583 | } | ||
1584 | len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len); | ||
1585 | return fill_from_dev_buffer(scp, arr, | ||
1586 | min(len, SDEBUG_MAX_INQ_ARR_SZ)); | ||
1587 | } | ||
1588 | |||
1589 | static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba, | ||
1590 | unsigned int num, struct sdebug_dev_info * devip) | ||
887 | { | 1591 | { |
888 | unsigned long iflags; | 1592 | unsigned long iflags; |
1593 | unsigned int block, from_bottom; | ||
1594 | unsigned long long u; | ||
889 | int ret; | 1595 | int ret; |
890 | 1596 | ||
891 | if (upper_blk || (block + num > sdebug_capacity)) { | 1597 | if (lba + num > sdebug_capacity) { |
892 | mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, | 1598 | mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, |
893 | 0); | 1599 | 0); |
894 | return check_condition_result; | 1600 | return check_condition_result; |
895 | } | 1601 | } |
1602 | /* transfer length excessive (tie in to block limits VPD page) */ | ||
1603 | if (num > sdebug_store_sectors) { | ||
1604 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | ||
1605 | 0); | ||
1606 | return check_condition_result; | ||
1607 | } | ||
896 | if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && | 1608 | if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && |
897 | (block <= OPT_MEDIUM_ERR_ADDR) && | 1609 | (lba <= OPT_MEDIUM_ERR_ADDR) && |
898 | ((block + num) > OPT_MEDIUM_ERR_ADDR)) { | 1610 | ((lba + num) > OPT_MEDIUM_ERR_ADDR)) { |
1611 | /* claim unrecoverable read error */ | ||
899 | mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR, | 1612 | mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR, |
900 | 0); | 1613 | 0); |
901 | /* claim unrecoverable read error */ | 1614 | /* set info field and valid bit for fixed descriptor */ |
1615 | if (0x70 == (devip->sense_buff[0] & 0x7f)) { | ||
1616 | devip->sense_buff[0] |= 0x80; /* Valid bit */ | ||
1617 | ret = OPT_MEDIUM_ERR_ADDR; | ||
1618 | devip->sense_buff[3] = (ret >> 24) & 0xff; | ||
1619 | devip->sense_buff[4] = (ret >> 16) & 0xff; | ||
1620 | devip->sense_buff[5] = (ret >> 8) & 0xff; | ||
1621 | devip->sense_buff[6] = ret & 0xff; | ||
1622 | } | ||
902 | return check_condition_result; | 1623 | return check_condition_result; |
903 | } | 1624 | } |
904 | read_lock_irqsave(&atomic_rw, iflags); | 1625 | read_lock_irqsave(&atomic_rw, iflags); |
905 | ret = fill_from_dev_buffer(SCpnt, fake_storep + (block * SECT_SIZE), | 1626 | if ((lba + num) <= sdebug_store_sectors) |
906 | num * SECT_SIZE); | 1627 | ret = fill_from_dev_buffer(SCpnt, |
1628 | fake_storep + (lba * SECT_SIZE), | ||
1629 | num * SECT_SIZE); | ||
1630 | else { | ||
1631 | /* modulo when one arg is 64 bits needs do_div() */ | ||
1632 | u = lba; | ||
1633 | block = do_div(u, sdebug_store_sectors); | ||
1634 | from_bottom = 0; | ||
1635 | if ((block + num) > sdebug_store_sectors) | ||
1636 | from_bottom = (block + num) - sdebug_store_sectors; | ||
1637 | ret = fill_from_dev_buffer(SCpnt, | ||
1638 | fake_storep + (block * SECT_SIZE), | ||
1639 | (num - from_bottom) * SECT_SIZE); | ||
1640 | if ((0 == ret) && (from_bottom > 0)) | ||
1641 | ret = fill_from_dev_buffer(SCpnt, fake_storep, | ||
1642 | from_bottom * SECT_SIZE); | ||
1643 | } | ||
907 | read_unlock_irqrestore(&atomic_rw, iflags); | 1644 | read_unlock_irqrestore(&atomic_rw, iflags); |
908 | return ret; | 1645 | return ret; |
909 | } | 1646 | } |
910 | 1647 | ||
911 | static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, | 1648 | static int resp_write(struct scsi_cmnd * SCpnt, unsigned long long lba, |
912 | int num, struct sdebug_dev_info * devip) | 1649 | unsigned int num, struct sdebug_dev_info * devip) |
913 | { | 1650 | { |
914 | unsigned long iflags; | 1651 | unsigned long iflags; |
1652 | unsigned int block, to_bottom; | ||
1653 | unsigned long long u; | ||
915 | int res; | 1654 | int res; |
916 | 1655 | ||
917 | if (upper_blk || (block + num > sdebug_capacity)) { | 1656 | if (lba + num > sdebug_capacity) { |
918 | mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, | 1657 | mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, |
919 | 0); | 1658 | 0); |
920 | return check_condition_result; | 1659 | return check_condition_result; |
921 | } | 1660 | } |
1661 | /* transfer length excessive (tie in to block limits VPD page) */ | ||
1662 | if (num > sdebug_store_sectors) { | ||
1663 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | ||
1664 | 0); | ||
1665 | return check_condition_result; | ||
1666 | } | ||
922 | 1667 | ||
923 | write_lock_irqsave(&atomic_rw, iflags); | 1668 | write_lock_irqsave(&atomic_rw, iflags); |
924 | res = fetch_to_dev_buffer(SCpnt, fake_storep + (block * SECT_SIZE), | 1669 | if ((lba + num) <= sdebug_store_sectors) |
925 | num * SECT_SIZE); | 1670 | res = fetch_to_dev_buffer(SCpnt, |
1671 | fake_storep + (lba * SECT_SIZE), | ||
1672 | num * SECT_SIZE); | ||
1673 | else { | ||
1674 | /* modulo when one arg is 64 bits needs do_div() */ | ||
1675 | u = lba; | ||
1676 | block = do_div(u, sdebug_store_sectors); | ||
1677 | to_bottom = 0; | ||
1678 | if ((block + num) > sdebug_store_sectors) | ||
1679 | to_bottom = (block + num) - sdebug_store_sectors; | ||
1680 | res = fetch_to_dev_buffer(SCpnt, | ||
1681 | fake_storep + (block * SECT_SIZE), | ||
1682 | (num - to_bottom) * SECT_SIZE); | ||
1683 | if ((0 == res) && (to_bottom > 0)) | ||
1684 | res = fetch_to_dev_buffer(SCpnt, fake_storep, | ||
1685 | to_bottom * SECT_SIZE); | ||
1686 | } | ||
926 | write_unlock_irqrestore(&atomic_rw, iflags); | 1687 | write_unlock_irqrestore(&atomic_rw, iflags); |
927 | if (-1 == res) | 1688 | if (-1 == res) |
928 | return (DID_ERROR << 16); | 1689 | return (DID_ERROR << 16); |
929 | else if ((res < (num * SECT_SIZE)) && | 1690 | else if ((res < (num * SECT_SIZE)) && |
930 | (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) | 1691 | (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) |
931 | printk(KERN_INFO "scsi_debug: write: cdb indicated=%d, " | 1692 | printk(KERN_INFO "scsi_debug: write: cdb indicated=%u, " |
932 | " IO sent=%d bytes\n", num * SECT_SIZE, res); | 1693 | " IO sent=%d bytes\n", num * SECT_SIZE, res); |
933 | return 0; | 1694 | return 0; |
934 | } | 1695 | } |
935 | 1696 | ||
936 | #define SDEBUG_RLUN_ARR_SZ 128 | 1697 | #define SDEBUG_RLUN_ARR_SZ 256 |
937 | 1698 | ||
938 | static int resp_report_luns(struct scsi_cmnd * scp, | 1699 | static int resp_report_luns(struct scsi_cmnd * scp, |
939 | struct sdebug_dev_info * devip) | 1700 | struct sdebug_dev_info * devip) |
940 | { | 1701 | { |
941 | unsigned int alloc_len; | 1702 | unsigned int alloc_len; |
942 | int lun_cnt, i, upper; | 1703 | int lun_cnt, i, upper, num, n, wlun, lun; |
943 | unsigned char *cmd = (unsigned char *)scp->cmnd; | 1704 | unsigned char *cmd = (unsigned char *)scp->cmnd; |
944 | int select_report = (int)cmd[2]; | 1705 | int select_report = (int)cmd[2]; |
945 | struct scsi_lun *one_lun; | 1706 | struct scsi_lun *one_lun; |
946 | unsigned char arr[SDEBUG_RLUN_ARR_SZ]; | 1707 | unsigned char arr[SDEBUG_RLUN_ARR_SZ]; |
1708 | unsigned char * max_addr; | ||
947 | 1709 | ||
948 | alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24); | 1710 | alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24); |
949 | if ((alloc_len < 16) || (select_report > 2)) { | 1711 | if ((alloc_len < 4) || (select_report > 2)) { |
950 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | 1712 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, |
951 | 0); | 1713 | 0); |
952 | return check_condition_result; | 1714 | return check_condition_result; |
@@ -954,18 +1716,37 @@ static int resp_report_luns(struct scsi_cmnd * scp, | |||
954 | /* can produce response with up to 16k luns (lun 0 to lun 16383) */ | 1716 | /* can produce response with up to 16k luns (lun 0 to lun 16383) */ |
955 | memset(arr, 0, SDEBUG_RLUN_ARR_SZ); | 1717 | memset(arr, 0, SDEBUG_RLUN_ARR_SZ); |
956 | lun_cnt = scsi_debug_max_luns; | 1718 | lun_cnt = scsi_debug_max_luns; |
957 | arr[2] = ((sizeof(struct scsi_lun) * lun_cnt) >> 8) & 0xff; | 1719 | if (1 == select_report) |
958 | arr[3] = (sizeof(struct scsi_lun) * lun_cnt) & 0xff; | 1720 | lun_cnt = 0; |
959 | lun_cnt = min((int)((SDEBUG_RLUN_ARR_SZ - 8) / | 1721 | else if (scsi_debug_no_lun_0 && (lun_cnt > 0)) |
960 | sizeof(struct scsi_lun)), lun_cnt); | 1722 | --lun_cnt; |
1723 | wlun = (select_report > 0) ? 1 : 0; | ||
1724 | num = lun_cnt + wlun; | ||
1725 | arr[2] = ((sizeof(struct scsi_lun) * num) >> 8) & 0xff; | ||
1726 | arr[3] = (sizeof(struct scsi_lun) * num) & 0xff; | ||
1727 | n = min((int)((SDEBUG_RLUN_ARR_SZ - 8) / | ||
1728 | sizeof(struct scsi_lun)), num); | ||
1729 | if (n < num) { | ||
1730 | wlun = 0; | ||
1731 | lun_cnt = n; | ||
1732 | } | ||
961 | one_lun = (struct scsi_lun *) &arr[8]; | 1733 | one_lun = (struct scsi_lun *) &arr[8]; |
962 | for (i = 0; i < lun_cnt; i++) { | 1734 | max_addr = arr + SDEBUG_RLUN_ARR_SZ; |
963 | upper = (i >> 8) & 0x3f; | 1735 | for (i = 0, lun = (scsi_debug_no_lun_0 ? 1 : 0); |
1736 | ((i < lun_cnt) && ((unsigned char *)(one_lun + i) < max_addr)); | ||
1737 | i++, lun++) { | ||
1738 | upper = (lun >> 8) & 0x3f; | ||
964 | if (upper) | 1739 | if (upper) |
965 | one_lun[i].scsi_lun[0] = | 1740 | one_lun[i].scsi_lun[0] = |
966 | (upper | (SAM2_LUN_ADDRESS_METHOD << 6)); | 1741 | (upper | (SAM2_LUN_ADDRESS_METHOD << 6)); |
967 | one_lun[i].scsi_lun[1] = i & 0xff; | 1742 | one_lun[i].scsi_lun[1] = lun & 0xff; |
1743 | } | ||
1744 | if (wlun) { | ||
1745 | one_lun[i].scsi_lun[0] = (SAM2_WLUN_REPORT_LUNS >> 8) & 0xff; | ||
1746 | one_lun[i].scsi_lun[1] = SAM2_WLUN_REPORT_LUNS & 0xff; | ||
1747 | i++; | ||
968 | } | 1748 | } |
1749 | alloc_len = (unsigned char *)(one_lun + i) - arr; | ||
969 | return fill_from_dev_buffer(scp, arr, | 1750 | return fill_from_dev_buffer(scp, arr, |
970 | min((int)alloc_len, SDEBUG_RLUN_ARR_SZ)); | 1751 | min((int)alloc_len, SDEBUG_RLUN_ARR_SZ)); |
971 | } | 1752 | } |
@@ -1001,7 +1782,8 @@ static void timer_intr_handler(unsigned long indx) | |||
1001 | static int scsi_debug_slave_alloc(struct scsi_device * sdp) | 1782 | static int scsi_debug_slave_alloc(struct scsi_device * sdp) |
1002 | { | 1783 | { |
1003 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 1784 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
1004 | sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_alloc\n"); | 1785 | printk(KERN_INFO "scsi_debug: slave_alloc <%u %u %u %u>\n", |
1786 | sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); | ||
1005 | return 0; | 1787 | return 0; |
1006 | } | 1788 | } |
1007 | 1789 | ||
@@ -1010,7 +1792,8 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp) | |||
1010 | struct sdebug_dev_info * devip; | 1792 | struct sdebug_dev_info * devip; |
1011 | 1793 | ||
1012 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 1794 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
1013 | sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_configure\n"); | 1795 | printk(KERN_INFO "scsi_debug: slave_configure <%u %u %u %u>\n", |
1796 | sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); | ||
1014 | if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) | 1797 | if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) |
1015 | sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN; | 1798 | sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN; |
1016 | devip = devInfoReg(sdp); | 1799 | devip = devInfoReg(sdp); |
@@ -1018,6 +1801,7 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp) | |||
1018 | if (sdp->host->cmd_per_lun) | 1801 | if (sdp->host->cmd_per_lun) |
1019 | scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING, | 1802 | scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING, |
1020 | sdp->host->cmd_per_lun); | 1803 | sdp->host->cmd_per_lun); |
1804 | blk_queue_max_segment_size(sdp->request_queue, 256 * 1024); | ||
1021 | return 0; | 1805 | return 0; |
1022 | } | 1806 | } |
1023 | 1807 | ||
@@ -1027,7 +1811,8 @@ static void scsi_debug_slave_destroy(struct scsi_device * sdp) | |||
1027 | (struct sdebug_dev_info *)sdp->hostdata; | 1811 | (struct sdebug_dev_info *)sdp->hostdata; |
1028 | 1812 | ||
1029 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 1813 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
1030 | sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_destroy\n"); | 1814 | printk(KERN_INFO "scsi_debug: slave_destroy <%u %u %u %u>\n", |
1815 | sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); | ||
1031 | if (devip) { | 1816 | if (devip) { |
1032 | /* make this slot avaliable for re-use */ | 1817 | /* make this slot avaliable for re-use */ |
1033 | devip->used = 0; | 1818 | devip->used = 0; |
@@ -1084,6 +1869,8 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev) | |||
1084 | open_devip->sense_buff[0] = 0x70; | 1869 | open_devip->sense_buff[0] = 0x70; |
1085 | open_devip->sense_buff[7] = 0xa; | 1870 | open_devip->sense_buff[7] = 0xa; |
1086 | } | 1871 | } |
1872 | if (sdev->lun == SAM2_WLUN_REPORT_LUNS) | ||
1873 | open_devip->wlun = SAM2_WLUN_REPORT_LUNS & 0xff; | ||
1087 | return open_devip; | 1874 | return open_devip; |
1088 | } | 1875 | } |
1089 | return NULL; | 1876 | return NULL; |
@@ -1272,7 +2059,7 @@ static void __init sdebug_build_parts(unsigned char * ramp) | |||
1272 | printk(KERN_WARNING "scsi_debug:build_parts: reducing " | 2059 | printk(KERN_WARNING "scsi_debug:build_parts: reducing " |
1273 | "partitions to %d\n", SDEBUG_MAX_PARTS); | 2060 | "partitions to %d\n", SDEBUG_MAX_PARTS); |
1274 | } | 2061 | } |
1275 | num_sectors = (int)(sdebug_store_size / SECT_SIZE); | 2062 | num_sectors = (int)sdebug_store_sectors; |
1276 | sectors_per_part = (num_sectors - sdebug_sectors_per) | 2063 | sectors_per_part = (num_sectors - sdebug_sectors_per) |
1277 | / scsi_debug_num_parts; | 2064 | / scsi_debug_num_parts; |
1278 | heads_by_sects = sdebug_heads * sdebug_sectors_per; | 2065 | heads_by_sects = sdebug_heads * sdebug_sectors_per; |
@@ -1315,9 +2102,9 @@ static int schedule_resp(struct scsi_cmnd * cmnd, | |||
1315 | if (scsi_result) { | 2102 | if (scsi_result) { |
1316 | struct scsi_device * sdp = cmnd->device; | 2103 | struct scsi_device * sdp = cmnd->device; |
1317 | 2104 | ||
1318 | sdev_printk(KERN_INFO, sdp, | 2105 | printk(KERN_INFO "scsi_debug: <%u %u %u %u> " |
1319 | "non-zero result=0x%x\n", | 2106 | "non-zero result=0x%x\n", sdp->host->host_no, |
1320 | scsi_result); | 2107 | sdp->channel, sdp->id, sdp->lun, scsi_result); |
1321 | } | 2108 | } |
1322 | } | 2109 | } |
1323 | if (cmnd && devip) { | 2110 | if (cmnd && devip) { |
@@ -1364,21 +2151,19 @@ static int schedule_resp(struct scsi_cmnd * cmnd, | |||
1364 | } | 2151 | } |
1365 | } | 2152 | } |
1366 | 2153 | ||
1367 | /* Set 'perm' (4th argument) to 0 to disable module_param's definition | 2154 | module_param_named(add_host, scsi_debug_add_host, int, S_IRUGO | S_IWUSR); |
1368 | * of sysfs parameters (which module_param doesn't yet support). | 2155 | module_param_named(delay, scsi_debug_delay, int, S_IRUGO | S_IWUSR); |
1369 | * Sysfs parameters defined explicitly below. | 2156 | module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, S_IRUGO); |
1370 | */ | 2157 | module_param_named(dsense, scsi_debug_dsense, int, S_IRUGO | S_IWUSR); |
1371 | module_param_named(add_host, scsi_debug_add_host, int, 0); /* perm=0644 */ | 2158 | module_param_named(every_nth, scsi_debug_every_nth, int, S_IRUGO | S_IWUSR); |
1372 | module_param_named(delay, scsi_debug_delay, int, 0); /* perm=0644 */ | 2159 | module_param_named(max_luns, scsi_debug_max_luns, int, S_IRUGO | S_IWUSR); |
1373 | module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, 0); | 2160 | module_param_named(no_lun_0, scsi_debug_no_lun_0, int, S_IRUGO | S_IWUSR); |
1374 | module_param_named(dsense, scsi_debug_dsense, int, 0); | 2161 | module_param_named(num_parts, scsi_debug_num_parts, int, S_IRUGO); |
1375 | module_param_named(every_nth, scsi_debug_every_nth, int, 0); | 2162 | module_param_named(num_tgts, scsi_debug_num_tgts, int, S_IRUGO | S_IWUSR); |
1376 | module_param_named(max_luns, scsi_debug_max_luns, int, 0); | 2163 | module_param_named(opts, scsi_debug_opts, int, S_IRUGO | S_IWUSR); |
1377 | module_param_named(num_parts, scsi_debug_num_parts, int, 0); | 2164 | module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR); |
1378 | module_param_named(num_tgts, scsi_debug_num_tgts, int, 0); | 2165 | module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO); |
1379 | module_param_named(opts, scsi_debug_opts, int, 0); /* perm=0644 */ | 2166 | module_param_named(virtual_gb, scsi_debug_virtual_gb, int, S_IRUGO | S_IWUSR); |
1380 | module_param_named(ptype, scsi_debug_ptype, int, 0); | ||
1381 | module_param_named(scsi_level, scsi_debug_scsi_level, int, 0); | ||
1382 | 2167 | ||
1383 | MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); | 2168 | MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); |
1384 | MODULE_DESCRIPTION("SCSI debug adapter driver"); | 2169 | MODULE_DESCRIPTION("SCSI debug adapter driver"); |
@@ -1387,15 +2172,17 @@ MODULE_VERSION(SCSI_DEBUG_VERSION); | |||
1387 | 2172 | ||
1388 | MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)"); | 2173 | MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)"); |
1389 | MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)"); | 2174 | MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)"); |
1390 | MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs"); | 2175 | MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs(def=8)"); |
1391 | MODULE_PARM_DESC(dsense, "use descriptor sense format(def: fixed)"); | 2176 | MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)"); |
1392 | MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)"); | 2177 | MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)"); |
1393 | MODULE_PARM_DESC(max_luns, "number of SCSI LUNs per target to simulate"); | 2178 | MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)"); |
2179 | MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)"); | ||
1394 | MODULE_PARM_DESC(num_parts, "number of partitions(def=0)"); | 2180 | MODULE_PARM_DESC(num_parts, "number of partitions(def=0)"); |
1395 | MODULE_PARM_DESC(num_tgts, "number of SCSI targets per host to simulate"); | 2181 | MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)"); |
1396 | MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->..."); | 2182 | MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->... (def=0)"); |
1397 | MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); | 2183 | MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); |
1398 | MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); | 2184 | MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); |
2185 | MODULE_PARM_DESC(virtual_gb, "virtual gigabyte size (def=0 -> use dev_size_mb)"); | ||
1399 | 2186 | ||
1400 | 2187 | ||
1401 | static char sdebug_info[256]; | 2188 | static char sdebug_info[256]; |
@@ -1547,6 +2334,24 @@ static ssize_t sdebug_dsense_store(struct device_driver * ddp, | |||
1547 | DRIVER_ATTR(dsense, S_IRUGO | S_IWUSR, sdebug_dsense_show, | 2334 | DRIVER_ATTR(dsense, S_IRUGO | S_IWUSR, sdebug_dsense_show, |
1548 | sdebug_dsense_store); | 2335 | sdebug_dsense_store); |
1549 | 2336 | ||
2337 | static ssize_t sdebug_no_lun_0_show(struct device_driver * ddp, char * buf) | ||
2338 | { | ||
2339 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_lun_0); | ||
2340 | } | ||
2341 | static ssize_t sdebug_no_lun_0_store(struct device_driver * ddp, | ||
2342 | const char * buf, size_t count) | ||
2343 | { | ||
2344 | int n; | ||
2345 | |||
2346 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { | ||
2347 | scsi_debug_no_lun_0 = n; | ||
2348 | return count; | ||
2349 | } | ||
2350 | return -EINVAL; | ||
2351 | } | ||
2352 | DRIVER_ATTR(no_lun_0, S_IRUGO | S_IWUSR, sdebug_no_lun_0_show, | ||
2353 | sdebug_no_lun_0_store); | ||
2354 | |||
1550 | static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf) | 2355 | static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf) |
1551 | { | 2356 | { |
1552 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); | 2357 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); |
@@ -1622,6 +2427,29 @@ static ssize_t sdebug_scsi_level_show(struct device_driver * ddp, char * buf) | |||
1622 | } | 2427 | } |
1623 | DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL); | 2428 | DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL); |
1624 | 2429 | ||
2430 | static ssize_t sdebug_virtual_gb_show(struct device_driver * ddp, char * buf) | ||
2431 | { | ||
2432 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_virtual_gb); | ||
2433 | } | ||
2434 | static ssize_t sdebug_virtual_gb_store(struct device_driver * ddp, | ||
2435 | const char * buf, size_t count) | ||
2436 | { | ||
2437 | int n; | ||
2438 | |||
2439 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { | ||
2440 | scsi_debug_virtual_gb = n; | ||
2441 | if (scsi_debug_virtual_gb > 0) { | ||
2442 | sdebug_capacity = 2048 * 1024; | ||
2443 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
2444 | } else | ||
2445 | sdebug_capacity = sdebug_store_sectors; | ||
2446 | return count; | ||
2447 | } | ||
2448 | return -EINVAL; | ||
2449 | } | ||
2450 | DRIVER_ATTR(virtual_gb, S_IRUGO | S_IWUSR, sdebug_virtual_gb_show, | ||
2451 | sdebug_virtual_gb_store); | ||
2452 | |||
1625 | static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf) | 2453 | static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf) |
1626 | { | 2454 | { |
1627 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); | 2455 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); |
@@ -1691,14 +2519,19 @@ static void do_remove_driverfs_files(void) | |||
1691 | 2519 | ||
1692 | static int __init scsi_debug_init(void) | 2520 | static int __init scsi_debug_init(void) |
1693 | { | 2521 | { |
1694 | unsigned long sz; | 2522 | unsigned int sz; |
1695 | int host_to_add; | 2523 | int host_to_add; |
1696 | int k; | 2524 | int k; |
1697 | 2525 | ||
1698 | if (scsi_debug_dev_size_mb < 1) | 2526 | if (scsi_debug_dev_size_mb < 1) |
1699 | scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */ | 2527 | scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */ |
1700 | sdebug_store_size = (unsigned long)scsi_debug_dev_size_mb * 1048576; | 2528 | sdebug_store_size = (unsigned int)scsi_debug_dev_size_mb * 1048576; |
1701 | sdebug_capacity = sdebug_store_size / SECT_SIZE; | 2529 | sdebug_store_sectors = sdebug_store_size / SECT_SIZE; |
2530 | if (scsi_debug_virtual_gb > 0) { | ||
2531 | sdebug_capacity = 2048 * 1024; | ||
2532 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
2533 | } else | ||
2534 | sdebug_capacity = sdebug_store_sectors; | ||
1702 | 2535 | ||
1703 | /* play around with geometry, don't waste too much on track 0 */ | 2536 | /* play around with geometry, don't waste too much on track 0 */ |
1704 | sdebug_heads = 8; | 2537 | sdebug_heads = 8; |
@@ -1812,7 +2645,7 @@ static int sdebug_add_adapter(void) | |||
1812 | struct sdebug_dev_info *sdbg_devinfo; | 2645 | struct sdebug_dev_info *sdbg_devinfo; |
1813 | struct list_head *lh, *lh_sf; | 2646 | struct list_head *lh, *lh_sf; |
1814 | 2647 | ||
1815 | sdbg_host = kzalloc(sizeof(*sdbg_host), GFP_KERNEL); | 2648 | sdbg_host = kzalloc(sizeof(*sdbg_host),GFP_KERNEL); |
1816 | 2649 | ||
1817 | if (NULL == sdbg_host) { | 2650 | if (NULL == sdbg_host) { |
1818 | printk(KERN_ERR "%s: out of memory at line %d\n", | 2651 | printk(KERN_ERR "%s: out of memory at line %d\n", |
@@ -1824,7 +2657,7 @@ static int sdebug_add_adapter(void) | |||
1824 | 2657 | ||
1825 | devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns; | 2658 | devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns; |
1826 | for (k = 0; k < devs_per_host; k++) { | 2659 | for (k = 0; k < devs_per_host; k++) { |
1827 | sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo), GFP_KERNEL); | 2660 | sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo),GFP_KERNEL); |
1828 | if (NULL == sdbg_devinfo) { | 2661 | if (NULL == sdbg_devinfo) { |
1829 | printk(KERN_ERR "%s: out of memory at line %d\n", | 2662 | printk(KERN_ERR "%s: out of memory at line %d\n", |
1830 | __FUNCTION__, __LINE__); | 2663 | __FUNCTION__, __LINE__); |
@@ -1905,7 +2738,7 @@ static int sdebug_driver_probe(struct device * dev) | |||
1905 | hpnt->max_id = scsi_debug_num_tgts + 1; | 2738 | hpnt->max_id = scsi_debug_num_tgts + 1; |
1906 | else | 2739 | else |
1907 | hpnt->max_id = scsi_debug_num_tgts; | 2740 | hpnt->max_id = scsi_debug_num_tgts; |
1908 | hpnt->max_lun = scsi_debug_max_luns; | 2741 | hpnt->max_lun = SAM2_WLUN_REPORT_LUNS; /* = scsi_debug_max_luns; */ |
1909 | 2742 | ||
1910 | error = scsi_add_host(hpnt, &sdbg_host->dev); | 2743 | error = scsi_add_host(hpnt, &sdbg_host->dev); |
1911 | if (error) { | 2744 | if (error) { |
@@ -1959,7 +2792,7 @@ static void sdebug_max_tgts_luns(void) | |||
1959 | hpnt->max_id = scsi_debug_num_tgts + 1; | 2792 | hpnt->max_id = scsi_debug_num_tgts + 1; |
1960 | else | 2793 | else |
1961 | hpnt->max_id = scsi_debug_num_tgts; | 2794 | hpnt->max_id = scsi_debug_num_tgts; |
1962 | hpnt->max_lun = scsi_debug_max_luns; | 2795 | hpnt->max_lun = SAM2_WLUN_REPORT_LUNS; /* scsi_debug_max_luns; */ |
1963 | } | 2796 | } |
1964 | spin_unlock(&sdebug_host_list_lock); | 2797 | spin_unlock(&sdebug_host_list_lock); |
1965 | } | 2798 | } |