diff options
Diffstat (limited to 'drivers/scsi/scsi_debug.c')
-rw-r--r-- | drivers/scsi/scsi_debug.c | 1456 |
1 files changed, 1236 insertions, 220 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 5a5d2af8ee4..9c0f35820e3 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * linux/kernel/scsi_debug.c | ||
3 | * vvvvvvvvvvvvvvvvvvvvvvv Original vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv | 2 | * vvvvvvvvvvvvvvvvvvvvvvv Original vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv |
4 | * Copyright (C) 1992 Eric Youngdale | 3 | * Copyright (C) 1992 Eric Youngdale |
5 | * Simulate a host adapter with 2 disks attached. Do a lot of checking | 4 | * Simulate a host adapter with 2 disks attached. Do a lot of checking |
@@ -8,7 +7,9 @@ | |||
8 | * ^^^^^^^^^^^^^^^^^^^^^^^ Original ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 7 | * ^^^^^^^^^^^^^^^^^^^^^^^ Original ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
9 | * | 8 | * |
10 | * This version is more generic, simulating a variable number of disk | 9 | * This version is more generic, simulating a variable number of disk |
11 | * (or disk like devices) sharing a common amount of RAM | 10 | * (or disk like devices) sharing a common amount of RAM. To be more |
11 | * realistic, the simulated devices have the transport attributes of | ||
12 | * SAS disks. | ||
12 | * | 13 | * |
13 | * | 14 | * |
14 | * For documentation see http://www.torque.net/sg/sdebug26.html | 15 | * For documentation see http://www.torque.net/sg/sdebug26.html |
@@ -24,7 +25,6 @@ | |||
24 | * module options to "modprobe scsi_debug num_tgts=2" [20021221] | 25 | * module options to "modprobe scsi_debug num_tgts=2" [20021221] |
25 | */ | 26 | */ |
26 | 27 | ||
27 | #include <linux/config.h> | ||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | 29 | ||
30 | #include <linux/kernel.h> | 30 | #include <linux/kernel.h> |
@@ -51,18 +51,22 @@ | |||
51 | #include "scsi_logging.h" | 51 | #include "scsi_logging.h" |
52 | #include "scsi_debug.h" | 52 | #include "scsi_debug.h" |
53 | 53 | ||
54 | #define SCSI_DEBUG_VERSION "1.75" | 54 | #define SCSI_DEBUG_VERSION "1.80" |
55 | static const char * scsi_debug_version_date = "20050113"; | 55 | static const char * scsi_debug_version_date = "20060914"; |
56 | 56 | ||
57 | /* Additional Sense Code (ASC) used */ | 57 | /* Additional Sense Code (ASC) used */ |
58 | #define NO_ADDED_SENSE 0x0 | 58 | #define NO_ADDITIONAL_SENSE 0x0 |
59 | #define LOGICAL_UNIT_NOT_READY 0x4 | ||
59 | #define UNRECOVERED_READ_ERR 0x11 | 60 | #define UNRECOVERED_READ_ERR 0x11 |
61 | #define PARAMETER_LIST_LENGTH_ERR 0x1a | ||
60 | #define INVALID_OPCODE 0x20 | 62 | #define INVALID_OPCODE 0x20 |
61 | #define ADDR_OUT_OF_RANGE 0x21 | 63 | #define ADDR_OUT_OF_RANGE 0x21 |
62 | #define INVALID_FIELD_IN_CDB 0x24 | 64 | #define INVALID_FIELD_IN_CDB 0x24 |
65 | #define INVALID_FIELD_IN_PARAM_LIST 0x26 | ||
63 | #define POWERON_RESET 0x29 | 66 | #define POWERON_RESET 0x29 |
64 | #define SAVING_PARAMS_UNSUP 0x39 | 67 | #define SAVING_PARAMS_UNSUP 0x39 |
65 | #define THRESHHOLD_EXCEEDED 0x5d | 68 | #define THRESHOLD_EXCEEDED 0x5d |
69 | #define LOW_POWER_COND_ON 0x5e | ||
66 | 70 | ||
67 | #define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */ | 71 | #define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */ |
68 | 72 | ||
@@ -81,6 +85,10 @@ static const char * scsi_debug_version_date = "20050113"; | |||
81 | #define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */ | 85 | #define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */ |
82 | #define DEF_PTYPE 0 | 86 | #define DEF_PTYPE 0 |
83 | #define DEF_D_SENSE 0 | 87 | #define DEF_D_SENSE 0 |
88 | #define DEF_NO_LUN_0 0 | ||
89 | #define DEF_VIRTUAL_GB 0 | ||
90 | #define DEF_FAKE_RW 0 | ||
91 | #define DEF_VPD_USE_HOSTNO 1 | ||
84 | 92 | ||
85 | /* bit mask values for scsi_debug_opts */ | 93 | /* bit mask values for scsi_debug_opts */ |
86 | #define SCSI_DEBUG_OPT_NOISE 1 | 94 | #define SCSI_DEBUG_OPT_NOISE 1 |
@@ -107,6 +115,7 @@ static const char * scsi_debug_version_date = "20050113"; | |||
107 | /* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1) | 115 | /* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1) |
108 | * or "peripheral device" addressing (value 0) */ | 116 | * or "peripheral device" addressing (value 0) */ |
109 | #define SAM2_LUN_ADDRESS_METHOD 0 | 117 | #define SAM2_LUN_ADDRESS_METHOD 0 |
118 | #define SAM2_WLUN_REPORT_LUNS 0xc101 | ||
110 | 119 | ||
111 | static int scsi_debug_add_host = DEF_NUM_HOST; | 120 | static int scsi_debug_add_host = DEF_NUM_HOST; |
112 | static int scsi_debug_delay = DEF_DELAY; | 121 | static int scsi_debug_delay = DEF_DELAY; |
@@ -119,13 +128,18 @@ static int scsi_debug_opts = DEF_OPTS; | |||
119 | static int scsi_debug_scsi_level = DEF_SCSI_LEVEL; | 128 | static int scsi_debug_scsi_level = DEF_SCSI_LEVEL; |
120 | static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */ | 129 | static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */ |
121 | static int scsi_debug_dsense = DEF_D_SENSE; | 130 | static int scsi_debug_dsense = DEF_D_SENSE; |
131 | static int scsi_debug_no_lun_0 = DEF_NO_LUN_0; | ||
132 | static int scsi_debug_virtual_gb = DEF_VIRTUAL_GB; | ||
133 | static int scsi_debug_fake_rw = DEF_FAKE_RW; | ||
134 | static int scsi_debug_vpd_use_hostno = DEF_VPD_USE_HOSTNO; | ||
122 | 135 | ||
123 | static int scsi_debug_cmnd_count = 0; | 136 | static int scsi_debug_cmnd_count = 0; |
124 | 137 | ||
125 | #define DEV_READONLY(TGT) (0) | 138 | #define DEV_READONLY(TGT) (0) |
126 | #define DEV_REMOVEABLE(TGT) (0) | 139 | #define DEV_REMOVEABLE(TGT) (0) |
127 | 140 | ||
128 | static unsigned long sdebug_store_size; /* in bytes */ | 141 | static unsigned int sdebug_store_size; /* in bytes */ |
142 | static unsigned int sdebug_store_sectors; | ||
129 | static sector_t sdebug_capacity; /* in sectors */ | 143 | static sector_t sdebug_capacity; /* in sectors */ |
130 | 144 | ||
131 | /* old BIOS stuff, kernel may get rid of them but some mode sense pages | 145 | /* old BIOS stuff, kernel may get rid of them but some mode sense pages |
@@ -150,7 +164,9 @@ struct sdebug_dev_info { | |||
150 | unsigned int target; | 164 | unsigned int target; |
151 | unsigned int lun; | 165 | unsigned int lun; |
152 | struct sdebug_host_info *sdbg_host; | 166 | struct sdebug_host_info *sdbg_host; |
167 | unsigned int wlun; | ||
153 | char reset; | 168 | char reset; |
169 | char stopped; | ||
154 | char used; | 170 | char used; |
155 | }; | 171 | }; |
156 | 172 | ||
@@ -194,11 +210,11 @@ static struct scsi_host_template sdebug_driver_template = { | |||
194 | .bios_param = scsi_debug_biosparam, | 210 | .bios_param = scsi_debug_biosparam, |
195 | .can_queue = SCSI_DEBUG_CANQUEUE, | 211 | .can_queue = SCSI_DEBUG_CANQUEUE, |
196 | .this_id = 7, | 212 | .this_id = 7, |
197 | .sg_tablesize = 64, | 213 | .sg_tablesize = 256, |
198 | .cmd_per_lun = 3, | 214 | .cmd_per_lun = 16, |
199 | .max_sectors = 4096, | 215 | .max_sectors = 0xffff, |
200 | .unchecked_isa_dma = 0, | 216 | .unchecked_isa_dma = 0, |
201 | .use_clustering = DISABLE_CLUSTERING, | 217 | .use_clustering = ENABLE_CLUSTERING, |
202 | .module = THIS_MODULE, | 218 | .module = THIS_MODULE, |
203 | }; | 219 | }; |
204 | 220 | ||
@@ -226,19 +242,32 @@ static struct device_driver sdebug_driverfs_driver = { | |||
226 | static const int check_condition_result = | 242 | static const int check_condition_result = |
227 | (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | 243 | (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; |
228 | 244 | ||
245 | static unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | ||
246 | 0, 0, 0x2, 0x4b}; | ||
247 | static unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0, | ||
248 | 0, 0, 0x0, 0x0}; | ||
249 | |||
229 | /* function declarations */ | 250 | /* function declarations */ |
230 | static int resp_inquiry(struct scsi_cmnd * SCpnt, int target, | 251 | static int resp_inquiry(struct scsi_cmnd * SCpnt, int target, |
231 | struct sdebug_dev_info * devip); | 252 | struct sdebug_dev_info * devip); |
232 | static int resp_requests(struct scsi_cmnd * SCpnt, | 253 | static int resp_requests(struct scsi_cmnd * SCpnt, |
233 | struct sdebug_dev_info * devip); | 254 | struct sdebug_dev_info * devip); |
255 | static int resp_start_stop(struct scsi_cmnd * scp, | ||
256 | struct sdebug_dev_info * devip); | ||
234 | static int resp_readcap(struct scsi_cmnd * SCpnt, | 257 | static int resp_readcap(struct scsi_cmnd * SCpnt, |
235 | struct sdebug_dev_info * devip); | 258 | struct sdebug_dev_info * devip); |
236 | static int resp_mode_sense(struct scsi_cmnd * SCpnt, int target, | 259 | static int resp_readcap16(struct scsi_cmnd * SCpnt, |
260 | struct sdebug_dev_info * devip); | ||
261 | static int resp_mode_sense(struct scsi_cmnd * scp, int target, | ||
237 | struct sdebug_dev_info * devip); | 262 | struct sdebug_dev_info * devip); |
238 | static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, | 263 | static int resp_mode_select(struct scsi_cmnd * scp, int mselect6, |
239 | int num, struct sdebug_dev_info * devip); | 264 | struct sdebug_dev_info * devip); |
240 | static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, | 265 | static int resp_log_sense(struct scsi_cmnd * scp, |
241 | int num, struct sdebug_dev_info * devip); | 266 | struct sdebug_dev_info * devip); |
267 | static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba, | ||
268 | unsigned int num, struct sdebug_dev_info * devip); | ||
269 | static int resp_write(struct scsi_cmnd * SCpnt, unsigned long long lba, | ||
270 | unsigned int num, struct sdebug_dev_info * devip); | ||
242 | static int resp_report_luns(struct scsi_cmnd * SCpnt, | 271 | static int resp_report_luns(struct scsi_cmnd * SCpnt, |
243 | struct sdebug_dev_info * devip); | 272 | struct sdebug_dev_info * devip); |
244 | static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, | 273 | static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, |
@@ -249,8 +278,8 @@ static void timer_intr_handler(unsigned long); | |||
249 | static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev); | 278 | static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev); |
250 | static void mk_sense_buffer(struct sdebug_dev_info * devip, int key, | 279 | static void mk_sense_buffer(struct sdebug_dev_info * devip, int key, |
251 | int asc, int asq); | 280 | int asc, int asq); |
252 | static int check_reset(struct scsi_cmnd * SCpnt, | 281 | static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only, |
253 | struct sdebug_dev_info * devip); | 282 | struct sdebug_dev_info * devip); |
254 | static int schedule_resp(struct scsi_cmnd * cmnd, | 283 | static int schedule_resp(struct scsi_cmnd * cmnd, |
255 | struct sdebug_dev_info * devip, | 284 | struct sdebug_dev_info * devip, |
256 | done_funct_t done, int scsi_result, int delta_jiff); | 285 | done_funct_t done, int scsi_result, int delta_jiff); |
@@ -258,9 +287,11 @@ static void __init sdebug_build_parts(unsigned char * ramp); | |||
258 | static void __init init_all_queued(void); | 287 | static void __init init_all_queued(void); |
259 | static void stop_all_queued(void); | 288 | static void stop_all_queued(void); |
260 | static int stop_queued_cmnd(struct scsi_cmnd * cmnd); | 289 | static int stop_queued_cmnd(struct scsi_cmnd * cmnd); |
261 | static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, | 290 | static int inquiry_evpd_83(unsigned char * arr, int target_dev_id, |
262 | const char * dev_id_str, int dev_id_str_len); | 291 | int dev_id_num, const char * dev_id_str, |
263 | static void do_create_driverfs_files(void); | 292 | int dev_id_str_len); |
293 | static int inquiry_evpd_88(unsigned char * arr, int target_dev_id); | ||
294 | static int do_create_driverfs_files(void); | ||
264 | static void do_remove_driverfs_files(void); | 295 | static void do_remove_driverfs_files(void); |
265 | 296 | ||
266 | static int sdebug_add_adapter(void); | 297 | static int sdebug_add_adapter(void); |
@@ -275,18 +306,22 @@ static | |||
275 | int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) | 306 | int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) |
276 | { | 307 | { |
277 | unsigned char *cmd = (unsigned char *) SCpnt->cmnd; | 308 | unsigned char *cmd = (unsigned char *) SCpnt->cmnd; |
278 | int block, upper_blk, num, k; | 309 | int len, k, j; |
310 | unsigned int num; | ||
311 | unsigned long long lba; | ||
279 | int errsts = 0; | 312 | int errsts = 0; |
280 | int target = scmd_id(SCpnt); | 313 | int target = SCpnt->device->id; |
281 | struct sdebug_dev_info * devip = NULL; | 314 | struct sdebug_dev_info * devip = NULL; |
282 | int inj_recovered = 0; | 315 | int inj_recovered = 0; |
316 | int delay_override = 0; | ||
283 | 317 | ||
284 | if (done == NULL) | 318 | if (done == NULL) |
285 | return 0; /* assume mid level reprocessing command */ | 319 | return 0; /* assume mid level reprocessing command */ |
286 | 320 | ||
321 | SCpnt->resid = 0; | ||
287 | if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) { | 322 | if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) { |
288 | printk(KERN_INFO "scsi_debug: cmd "); | 323 | printk(KERN_INFO "scsi_debug: cmd "); |
289 | for (k = 0, num = SCpnt->cmd_len; k < num; ++k) | 324 | for (k = 0, len = SCpnt->cmd_len; k < len; ++k) |
290 | printk("%02x ", (int)cmd[k]); | 325 | printk("%02x ", (int)cmd[k]); |
291 | printk("\n"); | 326 | printk("\n"); |
292 | } | 327 | } |
@@ -297,7 +332,8 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) | |||
297 | DID_NO_CONNECT << 16, 0); | 332 | DID_NO_CONNECT << 16, 0); |
298 | } | 333 | } |
299 | 334 | ||
300 | if (SCpnt->device->lun >= scsi_debug_max_luns) | 335 | if ((SCpnt->device->lun >= scsi_debug_max_luns) && |
336 | (SCpnt->device->lun != SAM2_WLUN_REPORT_LUNS)) | ||
301 | return schedule_resp(SCpnt, NULL, done, | 337 | return schedule_resp(SCpnt, NULL, done, |
302 | DID_NO_CONNECT << 16, 0); | 338 | DID_NO_CONNECT << 16, 0); |
303 | devip = devInfoReg(SCpnt->device); | 339 | devip = devInfoReg(SCpnt->device); |
@@ -316,118 +352,154 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) | |||
316 | inj_recovered = 1; /* to reads and writes below */ | 352 | inj_recovered = 1; /* to reads and writes below */ |
317 | } | 353 | } |
318 | 354 | ||
355 | if (devip->wlun) { | ||
356 | switch (*cmd) { | ||
357 | case INQUIRY: | ||
358 | case REQUEST_SENSE: | ||
359 | case TEST_UNIT_READY: | ||
360 | case REPORT_LUNS: | ||
361 | break; /* only allowable wlun commands */ | ||
362 | default: | ||
363 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | ||
364 | printk(KERN_INFO "scsi_debug: Opcode: 0x%x " | ||
365 | "not supported for wlun\n", *cmd); | ||
366 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
367 | INVALID_OPCODE, 0); | ||
368 | errsts = check_condition_result; | ||
369 | return schedule_resp(SCpnt, devip, done, errsts, | ||
370 | 0); | ||
371 | } | ||
372 | } | ||
373 | |||
319 | switch (*cmd) { | 374 | switch (*cmd) { |
320 | case INQUIRY: /* mandatory, ignore unit attention */ | 375 | case INQUIRY: /* mandatory, ignore unit attention */ |
376 | delay_override = 1; | ||
321 | errsts = resp_inquiry(SCpnt, target, devip); | 377 | errsts = resp_inquiry(SCpnt, target, devip); |
322 | break; | 378 | break; |
323 | case REQUEST_SENSE: /* mandatory, ignore unit attention */ | 379 | case REQUEST_SENSE: /* mandatory, ignore unit attention */ |
380 | delay_override = 1; | ||
324 | errsts = resp_requests(SCpnt, devip); | 381 | errsts = resp_requests(SCpnt, devip); |
325 | break; | 382 | break; |
326 | case REZERO_UNIT: /* actually this is REWIND for SSC */ | 383 | case REZERO_UNIT: /* actually this is REWIND for SSC */ |
327 | case START_STOP: | 384 | case START_STOP: |
328 | errsts = check_reset(SCpnt, devip); | 385 | errsts = resp_start_stop(SCpnt, devip); |
329 | break; | 386 | break; |
330 | case ALLOW_MEDIUM_REMOVAL: | 387 | case ALLOW_MEDIUM_REMOVAL: |
331 | if ((errsts = check_reset(SCpnt, devip))) | 388 | if ((errsts = check_readiness(SCpnt, 1, devip))) |
332 | break; | 389 | break; |
333 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 390 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
334 | printk(KERN_INFO "scsi_debug: Medium removal %s\n", | 391 | printk(KERN_INFO "scsi_debug: Medium removal %s\n", |
335 | cmd[4] ? "inhibited" : "enabled"); | 392 | cmd[4] ? "inhibited" : "enabled"); |
336 | break; | 393 | break; |
337 | case SEND_DIAGNOSTIC: /* mandatory */ | 394 | case SEND_DIAGNOSTIC: /* mandatory */ |
338 | errsts = check_reset(SCpnt, devip); | 395 | errsts = check_readiness(SCpnt, 1, devip); |
339 | break; | 396 | break; |
340 | case TEST_UNIT_READY: /* mandatory */ | 397 | case TEST_UNIT_READY: /* mandatory */ |
341 | errsts = check_reset(SCpnt, devip); | 398 | delay_override = 1; |
399 | errsts = check_readiness(SCpnt, 0, devip); | ||
342 | break; | 400 | break; |
343 | case RESERVE: | 401 | case RESERVE: |
344 | errsts = check_reset(SCpnt, devip); | 402 | errsts = check_readiness(SCpnt, 1, devip); |
345 | break; | 403 | break; |
346 | case RESERVE_10: | 404 | case RESERVE_10: |
347 | errsts = check_reset(SCpnt, devip); | 405 | errsts = check_readiness(SCpnt, 1, devip); |
348 | break; | 406 | break; |
349 | case RELEASE: | 407 | case RELEASE: |
350 | errsts = check_reset(SCpnt, devip); | 408 | errsts = check_readiness(SCpnt, 1, devip); |
351 | break; | 409 | break; |
352 | case RELEASE_10: | 410 | case RELEASE_10: |
353 | errsts = check_reset(SCpnt, devip); | 411 | errsts = check_readiness(SCpnt, 1, devip); |
354 | break; | 412 | break; |
355 | case READ_CAPACITY: | 413 | case READ_CAPACITY: |
356 | errsts = resp_readcap(SCpnt, devip); | 414 | errsts = resp_readcap(SCpnt, devip); |
357 | break; | 415 | break; |
416 | case SERVICE_ACTION_IN: | ||
417 | if (SAI_READ_CAPACITY_16 != cmd[1]) { | ||
418 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
419 | INVALID_OPCODE, 0); | ||
420 | errsts = check_condition_result; | ||
421 | break; | ||
422 | } | ||
423 | errsts = resp_readcap16(SCpnt, devip); | ||
424 | break; | ||
358 | case READ_16: | 425 | case READ_16: |
359 | case READ_12: | 426 | case READ_12: |
360 | case READ_10: | 427 | case READ_10: |
361 | case READ_6: | 428 | case READ_6: |
362 | if ((errsts = check_reset(SCpnt, devip))) | 429 | if ((errsts = check_readiness(SCpnt, 0, devip))) |
430 | break; | ||
431 | if (scsi_debug_fake_rw) | ||
363 | break; | 432 | break; |
364 | upper_blk = 0; | ||
365 | if ((*cmd) == READ_16) { | 433 | if ((*cmd) == READ_16) { |
366 | upper_blk = cmd[5] + (cmd[4] << 8) + | 434 | for (lba = 0, j = 0; j < 8; ++j) { |
367 | (cmd[3] << 16) + (cmd[2] << 24); | 435 | if (j > 0) |
368 | block = cmd[9] + (cmd[8] << 8) + | 436 | lba <<= 8; |
369 | (cmd[7] << 16) + (cmd[6] << 24); | 437 | lba += cmd[2 + j]; |
438 | } | ||
370 | num = cmd[13] + (cmd[12] << 8) + | 439 | num = cmd[13] + (cmd[12] << 8) + |
371 | (cmd[11] << 16) + (cmd[10] << 24); | 440 | (cmd[11] << 16) + (cmd[10] << 24); |
372 | } else if ((*cmd) == READ_12) { | 441 | } else if ((*cmd) == READ_12) { |
373 | block = cmd[5] + (cmd[4] << 8) + | 442 | lba = cmd[5] + (cmd[4] << 8) + |
374 | (cmd[3] << 16) + (cmd[2] << 24); | 443 | (cmd[3] << 16) + (cmd[2] << 24); |
375 | num = cmd[9] + (cmd[8] << 8) + | 444 | num = cmd[9] + (cmd[8] << 8) + |
376 | (cmd[7] << 16) + (cmd[6] << 24); | 445 | (cmd[7] << 16) + (cmd[6] << 24); |
377 | } else if ((*cmd) == READ_10) { | 446 | } else if ((*cmd) == READ_10) { |
378 | block = cmd[5] + (cmd[4] << 8) + | 447 | lba = cmd[5] + (cmd[4] << 8) + |
379 | (cmd[3] << 16) + (cmd[2] << 24); | 448 | (cmd[3] << 16) + (cmd[2] << 24); |
380 | num = cmd[8] + (cmd[7] << 8); | 449 | num = cmd[8] + (cmd[7] << 8); |
381 | } else { | 450 | } else { /* READ (6) */ |
382 | block = cmd[3] + (cmd[2] << 8) + | 451 | lba = cmd[3] + (cmd[2] << 8) + |
383 | ((cmd[1] & 0x1f) << 16); | 452 | ((cmd[1] & 0x1f) << 16); |
384 | num = cmd[4]; | 453 | num = (0 == cmd[4]) ? 256 : cmd[4]; |
385 | } | 454 | } |
386 | errsts = resp_read(SCpnt, upper_blk, block, num, devip); | 455 | errsts = resp_read(SCpnt, lba, num, devip); |
387 | if (inj_recovered && (0 == errsts)) { | 456 | if (inj_recovered && (0 == errsts)) { |
388 | mk_sense_buffer(devip, RECOVERED_ERROR, | 457 | mk_sense_buffer(devip, RECOVERED_ERROR, |
389 | THRESHHOLD_EXCEEDED, 0); | 458 | THRESHOLD_EXCEEDED, 0); |
390 | errsts = check_condition_result; | 459 | errsts = check_condition_result; |
391 | } | 460 | } |
392 | break; | 461 | break; |
393 | case REPORT_LUNS: /* mandatory, ignore unit attention */ | 462 | case REPORT_LUNS: /* mandatory, ignore unit attention */ |
463 | delay_override = 1; | ||
394 | errsts = resp_report_luns(SCpnt, devip); | 464 | errsts = resp_report_luns(SCpnt, devip); |
395 | break; | 465 | break; |
396 | case VERIFY: /* 10 byte SBC-2 command */ | 466 | case VERIFY: /* 10 byte SBC-2 command */ |
397 | errsts = check_reset(SCpnt, devip); | 467 | errsts = check_readiness(SCpnt, 0, devip); |
398 | break; | 468 | break; |
399 | case WRITE_16: | 469 | case WRITE_16: |
400 | case WRITE_12: | 470 | case WRITE_12: |
401 | case WRITE_10: | 471 | case WRITE_10: |
402 | case WRITE_6: | 472 | case WRITE_6: |
403 | if ((errsts = check_reset(SCpnt, devip))) | 473 | if ((errsts = check_readiness(SCpnt, 0, devip))) |
474 | break; | ||
475 | if (scsi_debug_fake_rw) | ||
404 | break; | 476 | break; |
405 | upper_blk = 0; | ||
406 | if ((*cmd) == WRITE_16) { | 477 | if ((*cmd) == WRITE_16) { |
407 | upper_blk = cmd[5] + (cmd[4] << 8) + | 478 | for (lba = 0, j = 0; j < 8; ++j) { |
408 | (cmd[3] << 16) + (cmd[2] << 24); | 479 | if (j > 0) |
409 | block = cmd[9] + (cmd[8] << 8) + | 480 | lba <<= 8; |
410 | (cmd[7] << 16) + (cmd[6] << 24); | 481 | lba += cmd[2 + j]; |
482 | } | ||
411 | num = cmd[13] + (cmd[12] << 8) + | 483 | num = cmd[13] + (cmd[12] << 8) + |
412 | (cmd[11] << 16) + (cmd[10] << 24); | 484 | (cmd[11] << 16) + (cmd[10] << 24); |
413 | } else if ((*cmd) == WRITE_12) { | 485 | } else if ((*cmd) == WRITE_12) { |
414 | block = cmd[5] + (cmd[4] << 8) + | 486 | lba = cmd[5] + (cmd[4] << 8) + |
415 | (cmd[3] << 16) + (cmd[2] << 24); | 487 | (cmd[3] << 16) + (cmd[2] << 24); |
416 | num = cmd[9] + (cmd[8] << 8) + | 488 | num = cmd[9] + (cmd[8] << 8) + |
417 | (cmd[7] << 16) + (cmd[6] << 24); | 489 | (cmd[7] << 16) + (cmd[6] << 24); |
418 | } else if ((*cmd) == WRITE_10) { | 490 | } else if ((*cmd) == WRITE_10) { |
419 | block = cmd[5] + (cmd[4] << 8) + | 491 | lba = cmd[5] + (cmd[4] << 8) + |
420 | (cmd[3] << 16) + (cmd[2] << 24); | 492 | (cmd[3] << 16) + (cmd[2] << 24); |
421 | num = cmd[8] + (cmd[7] << 8); | 493 | num = cmd[8] + (cmd[7] << 8); |
422 | } else { | 494 | } else { /* WRITE (6) */ |
423 | block = cmd[3] + (cmd[2] << 8) + | 495 | lba = cmd[3] + (cmd[2] << 8) + |
424 | ((cmd[1] & 0x1f) << 16); | 496 | ((cmd[1] & 0x1f) << 16); |
425 | num = cmd[4]; | 497 | num = (0 == cmd[4]) ? 256 : cmd[4]; |
426 | } | 498 | } |
427 | errsts = resp_write(SCpnt, upper_blk, block, num, devip); | 499 | errsts = resp_write(SCpnt, lba, num, devip); |
428 | if (inj_recovered && (0 == errsts)) { | 500 | if (inj_recovered && (0 == errsts)) { |
429 | mk_sense_buffer(devip, RECOVERED_ERROR, | 501 | mk_sense_buffer(devip, RECOVERED_ERROR, |
430 | THRESHHOLD_EXCEEDED, 0); | 502 | THRESHOLD_EXCEEDED, 0); |
431 | errsts = check_condition_result; | 503 | errsts = check_condition_result; |
432 | } | 504 | } |
433 | break; | 505 | break; |
@@ -435,20 +507,31 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) | |||
435 | case MODE_SENSE_10: | 507 | case MODE_SENSE_10: |
436 | errsts = resp_mode_sense(SCpnt, target, devip); | 508 | errsts = resp_mode_sense(SCpnt, target, devip); |
437 | break; | 509 | break; |
510 | case MODE_SELECT: | ||
511 | errsts = resp_mode_select(SCpnt, 1, devip); | ||
512 | break; | ||
513 | case MODE_SELECT_10: | ||
514 | errsts = resp_mode_select(SCpnt, 0, devip); | ||
515 | break; | ||
516 | case LOG_SENSE: | ||
517 | errsts = resp_log_sense(SCpnt, devip); | ||
518 | break; | ||
438 | case SYNCHRONIZE_CACHE: | 519 | case SYNCHRONIZE_CACHE: |
439 | errsts = check_reset(SCpnt, devip); | 520 | delay_override = 1; |
521 | errsts = check_readiness(SCpnt, 0, devip); | ||
440 | break; | 522 | break; |
441 | default: | 523 | default: |
442 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 524 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
443 | printk(KERN_INFO "scsi_debug: Opcode: 0x%x not " | 525 | printk(KERN_INFO "scsi_debug: Opcode: 0x%x not " |
444 | "supported\n", *cmd); | 526 | "supported\n", *cmd); |
445 | if ((errsts = check_reset(SCpnt, devip))) | 527 | if ((errsts = check_readiness(SCpnt, 1, devip))) |
446 | break; /* Unit attention takes precedence */ | 528 | break; /* Unit attention takes precedence */ |
447 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0); | 529 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0); |
448 | errsts = check_condition_result; | 530 | errsts = check_condition_result; |
449 | break; | 531 | break; |
450 | } | 532 | } |
451 | return schedule_resp(SCpnt, devip, done, errsts, scsi_debug_delay); | 533 | return schedule_resp(SCpnt, devip, done, errsts, |
534 | (delay_override ? 0 : scsi_debug_delay)); | ||
452 | } | 535 | } |
453 | 536 | ||
454 | static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) | 537 | static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) |
@@ -460,7 +543,8 @@ static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) | |||
460 | /* return -ENOTTY; // correct return but upsets fdisk */ | 543 | /* return -ENOTTY; // correct return but upsets fdisk */ |
461 | } | 544 | } |
462 | 545 | ||
463 | static int check_reset(struct scsi_cmnd * SCpnt, struct sdebug_dev_info * devip) | 546 | static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only, |
547 | struct sdebug_dev_info * devip) | ||
464 | { | 548 | { |
465 | if (devip->reset) { | 549 | if (devip->reset) { |
466 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 550 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
@@ -470,6 +554,14 @@ static int check_reset(struct scsi_cmnd * SCpnt, struct sdebug_dev_info * devip) | |||
470 | mk_sense_buffer(devip, UNIT_ATTENTION, POWERON_RESET, 0); | 554 | mk_sense_buffer(devip, UNIT_ATTENTION, POWERON_RESET, 0); |
471 | return check_condition_result; | 555 | return check_condition_result; |
472 | } | 556 | } |
557 | if ((0 == reset_only) && devip->stopped) { | ||
558 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | ||
559 | printk(KERN_INFO "scsi_debug: Reporting Not " | ||
560 | "ready: initializing command required\n"); | ||
561 | mk_sense_buffer(devip, NOT_READY, LOGICAL_UNIT_NOT_READY, | ||
562 | 0x2); | ||
563 | return check_condition_result; | ||
564 | } | ||
473 | return 0; | 565 | return 0; |
474 | } | 566 | } |
475 | 567 | ||
@@ -493,7 +585,10 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, | |||
493 | req_len = scp->request_bufflen; | 585 | req_len = scp->request_bufflen; |
494 | act_len = (req_len < arr_len) ? req_len : arr_len; | 586 | act_len = (req_len < arr_len) ? req_len : arr_len; |
495 | memcpy(scp->request_buffer, arr, act_len); | 587 | memcpy(scp->request_buffer, arr, act_len); |
496 | scp->resid = req_len - act_len; | 588 | if (scp->resid) |
589 | scp->resid -= act_len; | ||
590 | else | ||
591 | scp->resid = req_len - act_len; | ||
497 | return 0; | 592 | return 0; |
498 | } | 593 | } |
499 | sgpnt = (struct scatterlist *)scp->request_buffer; | 594 | sgpnt = (struct scatterlist *)scp->request_buffer; |
@@ -516,7 +611,10 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, | |||
516 | } | 611 | } |
517 | req_len += sgpnt->length; | 612 | req_len += sgpnt->length; |
518 | } | 613 | } |
519 | scp->resid = req_len - act_len; | 614 | if (scp->resid) |
615 | scp->resid -= act_len; | ||
616 | else | ||
617 | scp->resid = req_len - act_len; | ||
520 | return 0; | 618 | return 0; |
521 | } | 619 | } |
522 | 620 | ||
@@ -567,12 +665,14 @@ static const char * inq_vendor_id = "Linux "; | |||
567 | static const char * inq_product_id = "scsi_debug "; | 665 | static const char * inq_product_id = "scsi_debug "; |
568 | static const char * inq_product_rev = "0004"; | 666 | static const char * inq_product_rev = "0004"; |
569 | 667 | ||
570 | static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, | 668 | static int inquiry_evpd_83(unsigned char * arr, int target_dev_id, |
571 | const char * dev_id_str, int dev_id_str_len) | 669 | int dev_id_num, const char * dev_id_str, |
670 | int dev_id_str_len) | ||
572 | { | 671 | { |
573 | int num; | 672 | int num, port_a; |
673 | char b[32]; | ||
574 | 674 | ||
575 | /* Two identification descriptors: */ | 675 | port_a = target_dev_id + 1; |
576 | /* T10 vendor identifier field format (faked) */ | 676 | /* T10 vendor identifier field format (faked) */ |
577 | arr[0] = 0x2; /* ASCII */ | 677 | arr[0] = 0x2; /* ASCII */ |
578 | arr[1] = 0x1; | 678 | arr[1] = 0x1; |
@@ -583,25 +683,246 @@ static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, | |||
583 | num = 8 + 16 + dev_id_str_len; | 683 | num = 8 + 16 + dev_id_str_len; |
584 | arr[3] = num; | 684 | arr[3] = num; |
585 | num += 4; | 685 | num += 4; |
586 | /* NAA IEEE registered identifier (faked) */ | 686 | if (dev_id_num >= 0) { |
587 | arr[num] = 0x1; /* binary */ | 687 | /* NAA-5, Logical unit identifier (binary) */ |
588 | arr[num + 1] = 0x3; | 688 | arr[num++] = 0x1; /* binary (not necessarily sas) */ |
589 | arr[num + 2] = 0x0; | 689 | arr[num++] = 0x3; /* PIV=0, lu, naa */ |
590 | arr[num + 3] = 0x8; | 690 | arr[num++] = 0x0; |
591 | arr[num + 4] = 0x51; /* ieee company id=0x123456 (faked) */ | 691 | arr[num++] = 0x8; |
592 | arr[num + 5] = 0x23; | 692 | arr[num++] = 0x53; /* naa-5 ieee company id=0x333333 (fake) */ |
593 | arr[num + 6] = 0x45; | 693 | arr[num++] = 0x33; |
594 | arr[num + 7] = 0x60; | 694 | arr[num++] = 0x33; |
595 | arr[num + 8] = (dev_id_num >> 24); | 695 | arr[num++] = 0x30; |
596 | arr[num + 9] = (dev_id_num >> 16) & 0xff; | 696 | arr[num++] = (dev_id_num >> 24); |
597 | arr[num + 10] = (dev_id_num >> 8) & 0xff; | 697 | arr[num++] = (dev_id_num >> 16) & 0xff; |
598 | arr[num + 11] = dev_id_num & 0xff; | 698 | arr[num++] = (dev_id_num >> 8) & 0xff; |
599 | return num + 12; | 699 | arr[num++] = dev_id_num & 0xff; |
700 | /* Target relative port number */ | ||
701 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
702 | arr[num++] = 0x94; /* PIV=1, target port, rel port */ | ||
703 | arr[num++] = 0x0; /* reserved */ | ||
704 | arr[num++] = 0x4; /* length */ | ||
705 | arr[num++] = 0x0; /* reserved */ | ||
706 | arr[num++] = 0x0; /* reserved */ | ||
707 | arr[num++] = 0x0; | ||
708 | arr[num++] = 0x1; /* relative port A */ | ||
709 | } | ||
710 | /* NAA-5, Target port identifier */ | ||
711 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
712 | arr[num++] = 0x93; /* piv=1, target port, naa */ | ||
713 | arr[num++] = 0x0; | ||
714 | arr[num++] = 0x8; | ||
715 | arr[num++] = 0x52; /* naa-5, company id=0x222222 (fake) */ | ||
716 | arr[num++] = 0x22; | ||
717 | arr[num++] = 0x22; | ||
718 | arr[num++] = 0x20; | ||
719 | arr[num++] = (port_a >> 24); | ||
720 | arr[num++] = (port_a >> 16) & 0xff; | ||
721 | arr[num++] = (port_a >> 8) & 0xff; | ||
722 | arr[num++] = port_a & 0xff; | ||
723 | /* NAA-5, Target device identifier */ | ||
724 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
725 | arr[num++] = 0xa3; /* piv=1, target device, naa */ | ||
726 | arr[num++] = 0x0; | ||
727 | arr[num++] = 0x8; | ||
728 | arr[num++] = 0x52; /* naa-5, company id=0x222222 (fake) */ | ||
729 | arr[num++] = 0x22; | ||
730 | arr[num++] = 0x22; | ||
731 | arr[num++] = 0x20; | ||
732 | arr[num++] = (target_dev_id >> 24); | ||
733 | arr[num++] = (target_dev_id >> 16) & 0xff; | ||
734 | arr[num++] = (target_dev_id >> 8) & 0xff; | ||
735 | arr[num++] = target_dev_id & 0xff; | ||
736 | /* SCSI name string: Target device identifier */ | ||
737 | arr[num++] = 0x63; /* proto=sas, UTF-8 */ | ||
738 | arr[num++] = 0xa8; /* piv=1, target device, SCSI name string */ | ||
739 | arr[num++] = 0x0; | ||
740 | arr[num++] = 24; | ||
741 | memcpy(arr + num, "naa.52222220", 12); | ||
742 | num += 12; | ||
743 | snprintf(b, sizeof(b), "%08X", target_dev_id); | ||
744 | memcpy(arr + num, b, 8); | ||
745 | num += 8; | ||
746 | memset(arr + num, 0, 4); | ||
747 | num += 4; | ||
748 | return num; | ||
749 | } | ||
750 | |||
751 | |||
752 | static unsigned char vpd84_data[] = { | ||
753 | /* from 4th byte */ 0x22,0x22,0x22,0x0,0xbb,0x0, | ||
754 | 0x22,0x22,0x22,0x0,0xbb,0x1, | ||
755 | 0x22,0x22,0x22,0x0,0xbb,0x2, | ||
756 | }; | ||
757 | |||
758 | static int inquiry_evpd_84(unsigned char * arr) | ||
759 | { | ||
760 | memcpy(arr, vpd84_data, sizeof(vpd84_data)); | ||
761 | return sizeof(vpd84_data); | ||
762 | } | ||
763 | |||
764 | static int inquiry_evpd_85(unsigned char * arr) | ||
765 | { | ||
766 | int num = 0; | ||
767 | const char * na1 = "https://www.kernel.org/config"; | ||
768 | const char * na2 = "http://www.kernel.org/log"; | ||
769 | int plen, olen; | ||
770 | |||
771 | arr[num++] = 0x1; /* lu, storage config */ | ||
772 | arr[num++] = 0x0; /* reserved */ | ||
773 | arr[num++] = 0x0; | ||
774 | olen = strlen(na1); | ||
775 | plen = olen + 1; | ||
776 | if (plen % 4) | ||
777 | plen = ((plen / 4) + 1) * 4; | ||
778 | arr[num++] = plen; /* length, null termianted, padded */ | ||
779 | memcpy(arr + num, na1, olen); | ||
780 | memset(arr + num + olen, 0, plen - olen); | ||
781 | num += plen; | ||
782 | |||
783 | arr[num++] = 0x4; /* lu, logging */ | ||
784 | arr[num++] = 0x0; /* reserved */ | ||
785 | arr[num++] = 0x0; | ||
786 | olen = strlen(na2); | ||
787 | plen = olen + 1; | ||
788 | if (plen % 4) | ||
789 | plen = ((plen / 4) + 1) * 4; | ||
790 | arr[num++] = plen; /* length, null terminated, padded */ | ||
791 | memcpy(arr + num, na2, olen); | ||
792 | memset(arr + num + olen, 0, plen - olen); | ||
793 | num += plen; | ||
794 | |||
795 | return num; | ||
796 | } | ||
797 | |||
798 | /* SCSI ports VPD page */ | ||
799 | static int inquiry_evpd_88(unsigned char * arr, int target_dev_id) | ||
800 | { | ||
801 | int num = 0; | ||
802 | int port_a, port_b; | ||
803 | |||
804 | port_a = target_dev_id + 1; | ||
805 | port_b = port_a + 1; | ||
806 | arr[num++] = 0x0; /* reserved */ | ||
807 | arr[num++] = 0x0; /* reserved */ | ||
808 | arr[num++] = 0x0; | ||
809 | arr[num++] = 0x1; /* relative port 1 (primary) */ | ||
810 | memset(arr + num, 0, 6); | ||
811 | num += 6; | ||
812 | arr[num++] = 0x0; | ||
813 | arr[num++] = 12; /* length tp descriptor */ | ||
814 | /* naa-5 target port identifier (A) */ | ||
815 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
816 | arr[num++] = 0x93; /* PIV=1, target port, NAA */ | ||
817 | arr[num++] = 0x0; /* reserved */ | ||
818 | arr[num++] = 0x8; /* length */ | ||
819 | arr[num++] = 0x52; /* NAA-5, company_id=0x222222 (fake) */ | ||
820 | arr[num++] = 0x22; | ||
821 | arr[num++] = 0x22; | ||
822 | arr[num++] = 0x20; | ||
823 | arr[num++] = (port_a >> 24); | ||
824 | arr[num++] = (port_a >> 16) & 0xff; | ||
825 | arr[num++] = (port_a >> 8) & 0xff; | ||
826 | arr[num++] = port_a & 0xff; | ||
827 | |||
828 | arr[num++] = 0x0; /* reserved */ | ||
829 | arr[num++] = 0x0; /* reserved */ | ||
830 | arr[num++] = 0x0; | ||
831 | arr[num++] = 0x2; /* relative port 2 (secondary) */ | ||
832 | memset(arr + num, 0, 6); | ||
833 | num += 6; | ||
834 | arr[num++] = 0x0; | ||
835 | arr[num++] = 12; /* length tp descriptor */ | ||
836 | /* naa-5 target port identifier (B) */ | ||
837 | arr[num++] = 0x61; /* proto=sas, binary */ | ||
838 | arr[num++] = 0x93; /* PIV=1, target port, NAA */ | ||
839 | arr[num++] = 0x0; /* reserved */ | ||
840 | arr[num++] = 0x8; /* length */ | ||
841 | arr[num++] = 0x52; /* NAA-5, company_id=0x222222 (fake) */ | ||
842 | arr[num++] = 0x22; | ||
843 | arr[num++] = 0x22; | ||
844 | arr[num++] = 0x20; | ||
845 | arr[num++] = (port_b >> 24); | ||
846 | arr[num++] = (port_b >> 16) & 0xff; | ||
847 | arr[num++] = (port_b >> 8) & 0xff; | ||
848 | arr[num++] = port_b & 0xff; | ||
849 | |||
850 | return num; | ||
851 | } | ||
852 | |||
853 | |||
854 | static unsigned char vpd89_data[] = { | ||
855 | /* from 4th byte */ 0,0,0,0, | ||
856 | 'l','i','n','u','x',' ',' ',' ', | ||
857 | 'S','A','T',' ','s','c','s','i','_','d','e','b','u','g',' ',' ', | ||
858 | '1','2','3','4', | ||
859 | 0x34,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, | ||
860 | 0xec,0,0,0, | ||
861 | 0x5a,0xc,0xff,0x3f,0x37,0xc8,0x10,0,0,0,0,0,0x3f,0,0,0, | ||
862 | 0,0,0,0,0x58,0x58,0x58,0x58,0x58,0x58,0x58,0x58,0x20,0x20,0x20,0x20, | ||
863 | 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0,0,0,0x40,0x4,0,0x2e,0x33, | ||
864 | 0x38,0x31,0x20,0x20,0x20,0x20,0x54,0x53,0x38,0x33,0x30,0x30,0x33,0x31, | ||
865 | 0x53,0x41, | ||
866 | 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
867 | 0x20,0x20, | ||
868 | 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
869 | 0x10,0x80, | ||
870 | 0,0,0,0x2f,0,0,0,0x2,0,0x2,0x7,0,0xff,0xff,0x1,0, | ||
871 | 0x3f,0,0xc1,0xff,0x3e,0,0x10,0x1,0xb0,0xf8,0x50,0x9,0,0,0x7,0, | ||
872 | 0x3,0,0x78,0,0x78,0,0xf0,0,0x78,0,0,0,0,0,0,0, | ||
873 | 0,0,0,0,0,0,0,0,0x2,0,0,0,0,0,0,0, | ||
874 | 0x7e,0,0x1b,0,0x6b,0x34,0x1,0x7d,0x3,0x40,0x69,0x34,0x1,0x3c,0x3,0x40, | ||
875 | 0x7f,0x40,0,0,0,0,0xfe,0xfe,0,0,0,0,0,0xfe,0,0, | ||
876 | 0,0,0,0,0,0,0,0,0xb0,0xf8,0x50,0x9,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 | 0x1,0,0xb0,0xf8,0x50,0x9,0xb0,0xf8,0x50,0x9,0x20,0x20,0x2,0,0xb6,0x42, | ||
881 | 0,0x80,0x8a,0,0x6,0x3c,0xa,0x3c,0xff,0xff,0xc6,0x7,0,0x1,0,0x8, | ||
882 | 0xf0,0xf,0,0x10,0x2,0,0x30,0,0,0,0,0,0,0,0x6,0xfe, | ||
883 | 0,0,0x2,0,0x50,0,0x8a,0,0x4f,0x95,0,0,0x21,0,0xb,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,0,0, | ||
887 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
888 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
889 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
890 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
891 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
892 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
893 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
894 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
895 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xa5,0x51, | ||
896 | }; | ||
897 | |||
898 | static int inquiry_evpd_89(unsigned char * arr) | ||
899 | { | ||
900 | memcpy(arr, vpd89_data, sizeof(vpd89_data)); | ||
901 | return sizeof(vpd89_data); | ||
902 | } | ||
903 | |||
904 | |||
905 | static unsigned char vpdb0_data[] = { | ||
906 | /* from 4th byte */ 0,0,0,4, | ||
907 | 0,0,0x4,0, | ||
908 | 0,0,0,64, | ||
909 | }; | ||
910 | |||
911 | static int inquiry_evpd_b0(unsigned char * arr) | ||
912 | { | ||
913 | memcpy(arr, vpdb0_data, sizeof(vpdb0_data)); | ||
914 | if (sdebug_store_sectors > 0x400) { | ||
915 | arr[4] = (sdebug_store_sectors >> 24) & 0xff; | ||
916 | arr[5] = (sdebug_store_sectors >> 16) & 0xff; | ||
917 | arr[6] = (sdebug_store_sectors >> 8) & 0xff; | ||
918 | arr[7] = sdebug_store_sectors & 0xff; | ||
919 | } | ||
920 | return sizeof(vpdb0_data); | ||
600 | } | 921 | } |
601 | 922 | ||
602 | 923 | ||
603 | #define SDEBUG_LONG_INQ_SZ 96 | 924 | #define SDEBUG_LONG_INQ_SZ 96 |
604 | #define SDEBUG_MAX_INQ_ARR_SZ 128 | 925 | #define SDEBUG_MAX_INQ_ARR_SZ 584 |
605 | 926 | ||
606 | static int resp_inquiry(struct scsi_cmnd * scp, int target, | 927 | static int resp_inquiry(struct scsi_cmnd * scp, int target, |
607 | struct sdebug_dev_info * devip) | 928 | struct sdebug_dev_info * devip) |
@@ -609,64 +930,115 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target, | |||
609 | unsigned char pq_pdt; | 930 | unsigned char pq_pdt; |
610 | unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ]; | 931 | unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ]; |
611 | unsigned char *cmd = (unsigned char *)scp->cmnd; | 932 | unsigned char *cmd = (unsigned char *)scp->cmnd; |
612 | int alloc_len; | 933 | int alloc_len, n; |
613 | 934 | ||
614 | alloc_len = (cmd[3] << 8) + cmd[4]; | 935 | alloc_len = (cmd[3] << 8) + cmd[4]; |
615 | memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ); | 936 | memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ); |
616 | pq_pdt = (scsi_debug_ptype & 0x1f); | 937 | if (devip->wlun) |
938 | pq_pdt = 0x1e; /* present, wlun */ | ||
939 | else if (scsi_debug_no_lun_0 && (0 == devip->lun)) | ||
940 | pq_pdt = 0x7f; /* not present, no device type */ | ||
941 | else | ||
942 | pq_pdt = (scsi_debug_ptype & 0x1f); | ||
617 | arr[0] = pq_pdt; | 943 | arr[0] = pq_pdt; |
618 | if (0x2 & cmd[1]) { /* CMDDT bit set */ | 944 | if (0x2 & cmd[1]) { /* CMDDT bit set */ |
619 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | 945 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, |
620 | 0); | 946 | 0); |
621 | return check_condition_result; | 947 | return check_condition_result; |
622 | } else if (0x1 & cmd[1]) { /* EVPD bit set */ | 948 | } else if (0x1 & cmd[1]) { /* EVPD bit set */ |
623 | int dev_id_num, len; | 949 | int lu_id_num, target_dev_id, len; |
624 | char dev_id_str[6]; | 950 | char lu_id_str[6]; |
951 | int host_no = devip->sdbg_host->shost->host_no; | ||
625 | 952 | ||
626 | dev_id_num = ((devip->sdbg_host->shost->host_no + 1) * 2000) + | 953 | if (0 == scsi_debug_vpd_use_hostno) |
627 | (devip->target * 1000) + devip->lun; | 954 | host_no = 0; |
628 | len = scnprintf(dev_id_str, 6, "%d", dev_id_num); | 955 | lu_id_num = devip->wlun ? -1 : (((host_no + 1) * 2000) + |
956 | (devip->target * 1000) + devip->lun); | ||
957 | target_dev_id = ((host_no + 1) * 2000) + | ||
958 | (devip->target * 1000) - 3; | ||
959 | len = scnprintf(lu_id_str, 6, "%d", lu_id_num); | ||
629 | if (0 == cmd[2]) { /* supported vital product data pages */ | 960 | if (0 == cmd[2]) { /* supported vital product data pages */ |
630 | arr[3] = 3; | 961 | arr[1] = cmd[2]; /*sanity */ |
631 | arr[4] = 0x0; /* this page */ | 962 | n = 4; |
632 | arr[5] = 0x80; /* unit serial number */ | 963 | arr[n++] = 0x0; /* this page */ |
633 | arr[6] = 0x83; /* device identification */ | 964 | arr[n++] = 0x80; /* unit serial number */ |
965 | arr[n++] = 0x83; /* device identification */ | ||
966 | arr[n++] = 0x84; /* software interface ident. */ | ||
967 | arr[n++] = 0x85; /* management network addresses */ | ||
968 | arr[n++] = 0x86; /* extended inquiry */ | ||
969 | arr[n++] = 0x87; /* mode page policy */ | ||
970 | arr[n++] = 0x88; /* SCSI ports */ | ||
971 | arr[n++] = 0x89; /* ATA information */ | ||
972 | arr[n++] = 0xb0; /* Block limits (SBC) */ | ||
973 | arr[3] = n - 4; /* number of supported VPD pages */ | ||
634 | } else if (0x80 == cmd[2]) { /* unit serial number */ | 974 | } else if (0x80 == cmd[2]) { /* unit serial number */ |
635 | arr[1] = 0x80; | 975 | arr[1] = cmd[2]; /*sanity */ |
636 | arr[3] = len; | 976 | arr[3] = len; |
637 | memcpy(&arr[4], dev_id_str, len); | 977 | memcpy(&arr[4], lu_id_str, len); |
638 | } else if (0x83 == cmd[2]) { /* device identification */ | 978 | } else if (0x83 == cmd[2]) { /* device identification */ |
639 | arr[1] = 0x83; | 979 | arr[1] = cmd[2]; /*sanity */ |
640 | arr[3] = inquiry_evpd_83(&arr[4], dev_id_num, | 980 | arr[3] = inquiry_evpd_83(&arr[4], target_dev_id, |
641 | dev_id_str, len); | 981 | lu_id_num, lu_id_str, len); |
982 | } else if (0x84 == cmd[2]) { /* Software interface ident. */ | ||
983 | arr[1] = cmd[2]; /*sanity */ | ||
984 | arr[3] = inquiry_evpd_84(&arr[4]); | ||
985 | } else if (0x85 == cmd[2]) { /* Management network addresses */ | ||
986 | arr[1] = cmd[2]; /*sanity */ | ||
987 | arr[3] = inquiry_evpd_85(&arr[4]); | ||
988 | } else if (0x86 == cmd[2]) { /* extended inquiry */ | ||
989 | arr[1] = cmd[2]; /*sanity */ | ||
990 | arr[3] = 0x3c; /* number of following entries */ | ||
991 | arr[4] = 0x0; /* no protection stuff */ | ||
992 | arr[5] = 0x7; /* head of q, ordered + simple q's */ | ||
993 | } else if (0x87 == cmd[2]) { /* mode page policy */ | ||
994 | arr[1] = cmd[2]; /*sanity */ | ||
995 | arr[3] = 0x8; /* number of following entries */ | ||
996 | arr[4] = 0x2; /* disconnect-reconnect mp */ | ||
997 | arr[6] = 0x80; /* mlus, shared */ | ||
998 | arr[8] = 0x18; /* protocol specific lu */ | ||
999 | arr[10] = 0x82; /* mlus, per initiator port */ | ||
1000 | } else if (0x88 == cmd[2]) { /* SCSI Ports */ | ||
1001 | arr[1] = cmd[2]; /*sanity */ | ||
1002 | arr[3] = inquiry_evpd_88(&arr[4], target_dev_id); | ||
1003 | } else if (0x89 == cmd[2]) { /* ATA information */ | ||
1004 | arr[1] = cmd[2]; /*sanity */ | ||
1005 | n = inquiry_evpd_89(&arr[4]); | ||
1006 | arr[2] = (n >> 8); | ||
1007 | arr[3] = (n & 0xff); | ||
1008 | } else if (0xb0 == cmd[2]) { /* Block limits (SBC) */ | ||
1009 | arr[1] = cmd[2]; /*sanity */ | ||
1010 | arr[3] = inquiry_evpd_b0(&arr[4]); | ||
642 | } else { | 1011 | } else { |
643 | /* Illegal request, invalid field in cdb */ | 1012 | /* Illegal request, invalid field in cdb */ |
644 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | 1013 | mk_sense_buffer(devip, ILLEGAL_REQUEST, |
645 | INVALID_FIELD_IN_CDB, 0); | 1014 | INVALID_FIELD_IN_CDB, 0); |
646 | return check_condition_result; | 1015 | return check_condition_result; |
647 | } | 1016 | } |
1017 | len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len); | ||
648 | return fill_from_dev_buffer(scp, arr, | 1018 | return fill_from_dev_buffer(scp, arr, |
649 | min(alloc_len, SDEBUG_MAX_INQ_ARR_SZ)); | 1019 | min(len, SDEBUG_MAX_INQ_ARR_SZ)); |
650 | } | 1020 | } |
651 | /* drops through here for a standard inquiry */ | 1021 | /* drops through here for a standard inquiry */ |
652 | arr[1] = DEV_REMOVEABLE(target) ? 0x80 : 0; /* Removable disk */ | 1022 | arr[1] = DEV_REMOVEABLE(target) ? 0x80 : 0; /* Removable disk */ |
653 | arr[2] = scsi_debug_scsi_level; | 1023 | arr[2] = scsi_debug_scsi_level; |
654 | arr[3] = 2; /* response_data_format==2 */ | 1024 | arr[3] = 2; /* response_data_format==2 */ |
655 | arr[4] = SDEBUG_LONG_INQ_SZ - 5; | 1025 | arr[4] = SDEBUG_LONG_INQ_SZ - 5; |
656 | arr[6] = 0x1; /* claim: ADDR16 */ | 1026 | arr[6] = 0x10; /* claim: MultiP */ |
657 | /* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */ | 1027 | /* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */ |
658 | arr[7] = 0x3a; /* claim: WBUS16, SYNC, LINKED + CMDQUE */ | 1028 | arr[7] = 0xa; /* claim: LINKED + CMDQUE */ |
659 | memcpy(&arr[8], inq_vendor_id, 8); | 1029 | memcpy(&arr[8], inq_vendor_id, 8); |
660 | memcpy(&arr[16], inq_product_id, 16); | 1030 | memcpy(&arr[16], inq_product_id, 16); |
661 | memcpy(&arr[32], inq_product_rev, 4); | 1031 | memcpy(&arr[32], inq_product_rev, 4); |
662 | /* version descriptors (2 bytes each) follow */ | 1032 | /* version descriptors (2 bytes each) follow */ |
663 | arr[58] = 0x0; arr[59] = 0x40; /* SAM-2 */ | 1033 | arr[58] = 0x0; arr[59] = 0x77; /* SAM-3 ANSI */ |
664 | arr[60] = 0x3; arr[61] = 0x0; /* SPC-3 */ | 1034 | arr[60] = 0x3; arr[61] = 0x14; /* SPC-3 ANSI */ |
1035 | n = 62; | ||
665 | if (scsi_debug_ptype == 0) { | 1036 | if (scsi_debug_ptype == 0) { |
666 | arr[62] = 0x1; arr[63] = 0x80; /* SBC */ | 1037 | arr[n++] = 0x3; arr[n++] = 0x3d; /* SBC-2 ANSI */ |
667 | } else if (scsi_debug_ptype == 1) { | 1038 | } else if (scsi_debug_ptype == 1) { |
668 | arr[62] = 0x2; arr[63] = 0x00; /* SSC */ | 1039 | arr[n++] = 0x3; arr[n++] = 0x60; /* SSC-2 no version */ |
669 | } | 1040 | } |
1041 | arr[n++] = 0xc; arr[n++] = 0xf; /* SAS-1.1 rev 10 */ | ||
670 | return fill_from_dev_buffer(scp, arr, | 1042 | return fill_from_dev_buffer(scp, arr, |
671 | min(alloc_len, SDEBUG_LONG_INQ_SZ)); | 1043 | min(alloc_len, SDEBUG_LONG_INQ_SZ)); |
672 | } | 1044 | } |
@@ -677,46 +1049,128 @@ static int resp_requests(struct scsi_cmnd * scp, | |||
677 | unsigned char * sbuff; | 1049 | unsigned char * sbuff; |
678 | unsigned char *cmd = (unsigned char *)scp->cmnd; | 1050 | unsigned char *cmd = (unsigned char *)scp->cmnd; |
679 | unsigned char arr[SDEBUG_SENSE_LEN]; | 1051 | unsigned char arr[SDEBUG_SENSE_LEN]; |
1052 | int want_dsense; | ||
680 | int len = 18; | 1053 | int len = 18; |
681 | 1054 | ||
682 | memset(arr, 0, SDEBUG_SENSE_LEN); | 1055 | memset(arr, 0, sizeof(arr)); |
683 | if (devip->reset == 1) | 1056 | if (devip->reset == 1) |
684 | mk_sense_buffer(devip, 0, NO_ADDED_SENSE, 0); | 1057 | mk_sense_buffer(devip, 0, NO_ADDITIONAL_SENSE, 0); |
1058 | want_dsense = !!(cmd[1] & 1) || scsi_debug_dsense; | ||
685 | sbuff = devip->sense_buff; | 1059 | sbuff = devip->sense_buff; |
686 | if ((cmd[1] & 1) && (! scsi_debug_dsense)) { | 1060 | if ((iec_m_pg[2] & 0x4) && (6 == (iec_m_pg[3] & 0xf))) { |
687 | /* DESC bit set and sense_buff in fixed format */ | 1061 | if (want_dsense) { |
688 | arr[0] = 0x72; | 1062 | arr[0] = 0x72; |
689 | arr[1] = sbuff[2]; /* sense key */ | 1063 | arr[1] = 0x0; /* NO_SENSE in sense_key */ |
690 | arr[2] = sbuff[12]; /* asc */ | 1064 | arr[2] = THRESHOLD_EXCEEDED; |
691 | arr[3] = sbuff[13]; /* ascq */ | 1065 | arr[3] = 0xff; /* TEST set and MRIE==6 */ |
692 | len = 8; | 1066 | } else { |
693 | } else | 1067 | arr[0] = 0x70; |
1068 | arr[2] = 0x0; /* NO_SENSE in sense_key */ | ||
1069 | arr[7] = 0xa; /* 18 byte sense buffer */ | ||
1070 | arr[12] = THRESHOLD_EXCEEDED; | ||
1071 | arr[13] = 0xff; /* TEST set and MRIE==6 */ | ||
1072 | } | ||
1073 | } else { | ||
694 | memcpy(arr, sbuff, SDEBUG_SENSE_LEN); | 1074 | memcpy(arr, sbuff, SDEBUG_SENSE_LEN); |
695 | mk_sense_buffer(devip, 0, NO_ADDED_SENSE, 0); | 1075 | if ((cmd[1] & 1) && (! scsi_debug_dsense)) { |
1076 | /* DESC bit set and sense_buff in fixed format */ | ||
1077 | memset(arr, 0, sizeof(arr)); | ||
1078 | arr[0] = 0x72; | ||
1079 | arr[1] = sbuff[2]; /* sense key */ | ||
1080 | arr[2] = sbuff[12]; /* asc */ | ||
1081 | arr[3] = sbuff[13]; /* ascq */ | ||
1082 | len = 8; | ||
1083 | } | ||
1084 | } | ||
1085 | mk_sense_buffer(devip, 0, NO_ADDITIONAL_SENSE, 0); | ||
696 | return fill_from_dev_buffer(scp, arr, len); | 1086 | return fill_from_dev_buffer(scp, arr, len); |
697 | } | 1087 | } |
698 | 1088 | ||
1089 | static int resp_start_stop(struct scsi_cmnd * scp, | ||
1090 | struct sdebug_dev_info * devip) | ||
1091 | { | ||
1092 | unsigned char *cmd = (unsigned char *)scp->cmnd; | ||
1093 | int power_cond, errsts, start; | ||
1094 | |||
1095 | if ((errsts = check_readiness(scp, 1, devip))) | ||
1096 | return errsts; | ||
1097 | power_cond = (cmd[4] & 0xf0) >> 4; | ||
1098 | if (power_cond) { | ||
1099 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | ||
1100 | 0); | ||
1101 | return check_condition_result; | ||
1102 | } | ||
1103 | start = cmd[4] & 1; | ||
1104 | if (start == devip->stopped) | ||
1105 | devip->stopped = !start; | ||
1106 | return 0; | ||
1107 | } | ||
1108 | |||
699 | #define SDEBUG_READCAP_ARR_SZ 8 | 1109 | #define SDEBUG_READCAP_ARR_SZ 8 |
700 | static int resp_readcap(struct scsi_cmnd * scp, | 1110 | static int resp_readcap(struct scsi_cmnd * scp, |
701 | struct sdebug_dev_info * devip) | 1111 | struct sdebug_dev_info * devip) |
702 | { | 1112 | { |
703 | unsigned char arr[SDEBUG_READCAP_ARR_SZ]; | 1113 | unsigned char arr[SDEBUG_READCAP_ARR_SZ]; |
704 | unsigned long capac; | 1114 | unsigned int capac; |
705 | int errsts; | 1115 | int errsts; |
706 | 1116 | ||
707 | if ((errsts = check_reset(scp, devip))) | 1117 | if ((errsts = check_readiness(scp, 1, devip))) |
708 | return errsts; | 1118 | return errsts; |
1119 | /* following just in case virtual_gb changed */ | ||
1120 | if (scsi_debug_virtual_gb > 0) { | ||
1121 | sdebug_capacity = 2048 * 1024; | ||
1122 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
1123 | } else | ||
1124 | sdebug_capacity = sdebug_store_sectors; | ||
709 | memset(arr, 0, SDEBUG_READCAP_ARR_SZ); | 1125 | memset(arr, 0, SDEBUG_READCAP_ARR_SZ); |
710 | capac = (unsigned long)sdebug_capacity - 1; | 1126 | if (sdebug_capacity < 0xffffffff) { |
711 | arr[0] = (capac >> 24); | 1127 | capac = (unsigned int)sdebug_capacity - 1; |
712 | arr[1] = (capac >> 16) & 0xff; | 1128 | arr[0] = (capac >> 24); |
713 | arr[2] = (capac >> 8) & 0xff; | 1129 | arr[1] = (capac >> 16) & 0xff; |
714 | arr[3] = capac & 0xff; | 1130 | arr[2] = (capac >> 8) & 0xff; |
1131 | arr[3] = capac & 0xff; | ||
1132 | } else { | ||
1133 | arr[0] = 0xff; | ||
1134 | arr[1] = 0xff; | ||
1135 | arr[2] = 0xff; | ||
1136 | arr[3] = 0xff; | ||
1137 | } | ||
715 | arr[6] = (SECT_SIZE_PER(target) >> 8) & 0xff; | 1138 | arr[6] = (SECT_SIZE_PER(target) >> 8) & 0xff; |
716 | arr[7] = SECT_SIZE_PER(target) & 0xff; | 1139 | arr[7] = SECT_SIZE_PER(target) & 0xff; |
717 | return fill_from_dev_buffer(scp, arr, SDEBUG_READCAP_ARR_SZ); | 1140 | return fill_from_dev_buffer(scp, arr, SDEBUG_READCAP_ARR_SZ); |
718 | } | 1141 | } |
719 | 1142 | ||
1143 | #define SDEBUG_READCAP16_ARR_SZ 32 | ||
1144 | static int resp_readcap16(struct scsi_cmnd * scp, | ||
1145 | struct sdebug_dev_info * devip) | ||
1146 | { | ||
1147 | unsigned char *cmd = (unsigned char *)scp->cmnd; | ||
1148 | unsigned char arr[SDEBUG_READCAP16_ARR_SZ]; | ||
1149 | unsigned long long capac; | ||
1150 | int errsts, k, alloc_len; | ||
1151 | |||
1152 | if ((errsts = check_readiness(scp, 1, devip))) | ||
1153 | return errsts; | ||
1154 | alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8) | ||
1155 | + cmd[13]); | ||
1156 | /* following just in case virtual_gb changed */ | ||
1157 | if (scsi_debug_virtual_gb > 0) { | ||
1158 | sdebug_capacity = 2048 * 1024; | ||
1159 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
1160 | } else | ||
1161 | sdebug_capacity = sdebug_store_sectors; | ||
1162 | memset(arr, 0, SDEBUG_READCAP16_ARR_SZ); | ||
1163 | capac = sdebug_capacity - 1; | ||
1164 | for (k = 0; k < 8; ++k, capac >>= 8) | ||
1165 | arr[7 - k] = capac & 0xff; | ||
1166 | arr[8] = (SECT_SIZE_PER(target) >> 24) & 0xff; | ||
1167 | arr[9] = (SECT_SIZE_PER(target) >> 16) & 0xff; | ||
1168 | arr[10] = (SECT_SIZE_PER(target) >> 8) & 0xff; | ||
1169 | arr[11] = SECT_SIZE_PER(target) & 0xff; | ||
1170 | return fill_from_dev_buffer(scp, arr, | ||
1171 | min(alloc_len, SDEBUG_READCAP16_ARR_SZ)); | ||
1172 | } | ||
1173 | |||
720 | /* <<Following mode page info copied from ST318451LW>> */ | 1174 | /* <<Following mode page info copied from ST318451LW>> */ |
721 | 1175 | ||
722 | static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target) | 1176 | static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target) |
@@ -772,47 +1226,123 @@ static int resp_caching_pg(unsigned char * p, int pcontrol, int target) | |||
772 | 1226 | ||
773 | static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target) | 1227 | static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target) |
774 | { /* Control mode page for mode_sense */ | 1228 | { /* Control mode page for mode_sense */ |
775 | unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | 1229 | unsigned char ch_ctrl_m_pg[] = {/* 0xa, 10, */ 0x6, 0, 0, 0, 0, 0, |
1230 | 0, 0, 0, 0}; | ||
1231 | unsigned char d_ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | ||
776 | 0, 0, 0x2, 0x4b}; | 1232 | 0, 0, 0x2, 0x4b}; |
777 | 1233 | ||
778 | if (scsi_debug_dsense) | 1234 | if (scsi_debug_dsense) |
779 | ctrl_m_pg[2] |= 0x4; | 1235 | ctrl_m_pg[2] |= 0x4; |
1236 | else | ||
1237 | ctrl_m_pg[2] &= ~0x4; | ||
780 | memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg)); | 1238 | memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg)); |
781 | if (1 == pcontrol) | 1239 | if (1 == pcontrol) |
782 | memset(p + 2, 0, sizeof(ctrl_m_pg) - 2); | 1240 | memcpy(p + 2, ch_ctrl_m_pg, sizeof(ch_ctrl_m_pg)); |
1241 | else if (2 == pcontrol) | ||
1242 | memcpy(p, d_ctrl_m_pg, sizeof(d_ctrl_m_pg)); | ||
783 | return sizeof(ctrl_m_pg); | 1243 | return sizeof(ctrl_m_pg); |
784 | } | 1244 | } |
785 | 1245 | ||
1246 | |||
786 | static int resp_iec_m_pg(unsigned char * p, int pcontrol, int target) | 1247 | static int resp_iec_m_pg(unsigned char * p, int pcontrol, int target) |
787 | { /* Informational Exceptions control mode page for mode_sense */ | 1248 | { /* Informational Exceptions control mode page for mode_sense */ |
788 | unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0, | 1249 | unsigned char ch_iec_m_pg[] = {/* 0x1c, 0xa, */ 0x4, 0xf, 0, 0, 0, 0, |
789 | 0, 0, 0x0, 0x0}; | 1250 | 0, 0, 0x0, 0x0}; |
1251 | unsigned char d_iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0, | ||
1252 | 0, 0, 0x0, 0x0}; | ||
1253 | |||
790 | memcpy(p, iec_m_pg, sizeof(iec_m_pg)); | 1254 | memcpy(p, iec_m_pg, sizeof(iec_m_pg)); |
791 | if (1 == pcontrol) | 1255 | if (1 == pcontrol) |
792 | memset(p + 2, 0, sizeof(iec_m_pg) - 2); | 1256 | memcpy(p + 2, ch_iec_m_pg, sizeof(ch_iec_m_pg)); |
1257 | else if (2 == pcontrol) | ||
1258 | memcpy(p, d_iec_m_pg, sizeof(d_iec_m_pg)); | ||
793 | return sizeof(iec_m_pg); | 1259 | return sizeof(iec_m_pg); |
794 | } | 1260 | } |
795 | 1261 | ||
1262 | static int resp_sas_sf_m_pg(unsigned char * p, int pcontrol, int target) | ||
1263 | { /* SAS SSP mode page - short format for mode_sense */ | ||
1264 | unsigned char sas_sf_m_pg[] = {0x19, 0x6, | ||
1265 | 0x6, 0x0, 0x7, 0xd0, 0x0, 0x0}; | ||
1266 | |||
1267 | memcpy(p, sas_sf_m_pg, sizeof(sas_sf_m_pg)); | ||
1268 | if (1 == pcontrol) | ||
1269 | memset(p + 2, 0, sizeof(sas_sf_m_pg) - 2); | ||
1270 | return sizeof(sas_sf_m_pg); | ||
1271 | } | ||
1272 | |||
1273 | |||
1274 | static int resp_sas_pcd_m_spg(unsigned char * p, int pcontrol, int target, | ||
1275 | int target_dev_id) | ||
1276 | { /* SAS phy control and discover mode page for mode_sense */ | ||
1277 | unsigned char sas_pcd_m_pg[] = {0x59, 0x1, 0, 0x64, 0, 0x6, 0, 2, | ||
1278 | 0, 0, 0, 0, 0x10, 0x9, 0x8, 0x0, | ||
1279 | 0x52, 0x22, 0x22, 0x20, 0x0, 0x0, 0x0, 0x0, | ||
1280 | 0x51, 0x11, 0x11, 0x10, 0x0, 0x0, 0x0, 0x1, | ||
1281 | 0x2, 0, 0, 0, 0, 0, 0, 0, | ||
1282 | 0x88, 0x99, 0, 0, 0, 0, 0, 0, | ||
1283 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
1284 | 0, 1, 0, 0, 0x10, 0x9, 0x8, 0x0, | ||
1285 | 0x52, 0x22, 0x22, 0x20, 0x0, 0x0, 0x0, 0x0, | ||
1286 | 0x51, 0x11, 0x11, 0x10, 0x0, 0x0, 0x0, 0x1, | ||
1287 | 0x3, 0, 0, 0, 0, 0, 0, 0, | ||
1288 | 0x88, 0x99, 0, 0, 0, 0, 0, 0, | ||
1289 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
1290 | }; | ||
1291 | int port_a, port_b; | ||
1292 | |||
1293 | port_a = target_dev_id + 1; | ||
1294 | port_b = port_a + 1; | ||
1295 | memcpy(p, sas_pcd_m_pg, sizeof(sas_pcd_m_pg)); | ||
1296 | p[20] = (port_a >> 24); | ||
1297 | p[21] = (port_a >> 16) & 0xff; | ||
1298 | p[22] = (port_a >> 8) & 0xff; | ||
1299 | p[23] = port_a & 0xff; | ||
1300 | p[48 + 20] = (port_b >> 24); | ||
1301 | p[48 + 21] = (port_b >> 16) & 0xff; | ||
1302 | p[48 + 22] = (port_b >> 8) & 0xff; | ||
1303 | p[48 + 23] = port_b & 0xff; | ||
1304 | if (1 == pcontrol) | ||
1305 | memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4); | ||
1306 | return sizeof(sas_pcd_m_pg); | ||
1307 | } | ||
1308 | |||
1309 | static int resp_sas_sha_m_spg(unsigned char * p, int pcontrol) | ||
1310 | { /* SAS SSP shared protocol specific port mode subpage */ | ||
1311 | unsigned char sas_sha_m_pg[] = {0x59, 0x2, 0, 0xc, 0, 0x6, 0x10, 0, | ||
1312 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
1313 | }; | ||
1314 | |||
1315 | memcpy(p, sas_sha_m_pg, sizeof(sas_sha_m_pg)); | ||
1316 | if (1 == pcontrol) | ||
1317 | memset(p + 4, 0, sizeof(sas_sha_m_pg) - 4); | ||
1318 | return sizeof(sas_sha_m_pg); | ||
1319 | } | ||
1320 | |||
796 | #define SDEBUG_MAX_MSENSE_SZ 256 | 1321 | #define SDEBUG_MAX_MSENSE_SZ 256 |
797 | 1322 | ||
798 | static int resp_mode_sense(struct scsi_cmnd * scp, int target, | 1323 | static int resp_mode_sense(struct scsi_cmnd * scp, int target, |
799 | struct sdebug_dev_info * devip) | 1324 | struct sdebug_dev_info * devip) |
800 | { | 1325 | { |
801 | unsigned char dbd; | 1326 | unsigned char dbd, llbaa; |
802 | int pcontrol, pcode, subpcode; | 1327 | int pcontrol, pcode, subpcode, bd_len; |
803 | unsigned char dev_spec; | 1328 | unsigned char dev_spec; |
804 | int alloc_len, msense_6, offset, len, errsts; | 1329 | int k, alloc_len, msense_6, offset, len, errsts, target_dev_id; |
805 | unsigned char * ap; | 1330 | unsigned char * ap; |
806 | unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; | 1331 | unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; |
807 | unsigned char *cmd = (unsigned char *)scp->cmnd; | 1332 | unsigned char *cmd = (unsigned char *)scp->cmnd; |
808 | 1333 | ||
809 | if ((errsts = check_reset(scp, devip))) | 1334 | if ((errsts = check_readiness(scp, 1, devip))) |
810 | return errsts; | 1335 | return errsts; |
811 | dbd = cmd[1] & 0x8; | 1336 | dbd = !!(cmd[1] & 0x8); |
812 | pcontrol = (cmd[2] & 0xc0) >> 6; | 1337 | pcontrol = (cmd[2] & 0xc0) >> 6; |
813 | pcode = cmd[2] & 0x3f; | 1338 | pcode = cmd[2] & 0x3f; |
814 | subpcode = cmd[3]; | 1339 | subpcode = cmd[3]; |
815 | msense_6 = (MODE_SENSE == cmd[0]); | 1340 | msense_6 = (MODE_SENSE == cmd[0]); |
1341 | llbaa = msense_6 ? 0 : !!(cmd[1] & 0x10); | ||
1342 | if ((0 == scsi_debug_ptype) && (0 == dbd)) | ||
1343 | bd_len = llbaa ? 16 : 8; | ||
1344 | else | ||
1345 | bd_len = 0; | ||
816 | alloc_len = msense_6 ? cmd[4] : ((cmd[7] << 8) | cmd[8]); | 1346 | alloc_len = msense_6 ? cmd[4] : ((cmd[7] << 8) | cmd[8]); |
817 | memset(arr, 0, SDEBUG_MAX_MSENSE_SZ); | 1347 | memset(arr, 0, SDEBUG_MAX_MSENSE_SZ); |
818 | if (0x3 == pcontrol) { /* Saving values not supported */ | 1348 | if (0x3 == pcontrol) { /* Saving values not supported */ |
@@ -820,17 +1350,63 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
820 | 0); | 1350 | 0); |
821 | return check_condition_result; | 1351 | return check_condition_result; |
822 | } | 1352 | } |
823 | dev_spec = DEV_READONLY(target) ? 0x80 : 0x0; | 1353 | target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) + |
1354 | (devip->target * 1000) - 3; | ||
1355 | /* set DPOFUA bit for disks */ | ||
1356 | if (0 == scsi_debug_ptype) | ||
1357 | dev_spec = (DEV_READONLY(target) ? 0x80 : 0x0) | 0x10; | ||
1358 | else | ||
1359 | dev_spec = 0x0; | ||
824 | if (msense_6) { | 1360 | if (msense_6) { |
825 | arr[2] = dev_spec; | 1361 | arr[2] = dev_spec; |
1362 | arr[3] = bd_len; | ||
826 | offset = 4; | 1363 | offset = 4; |
827 | } else { | 1364 | } else { |
828 | arr[3] = dev_spec; | 1365 | arr[3] = dev_spec; |
1366 | if (16 == bd_len) | ||
1367 | arr[4] = 0x1; /* set LONGLBA bit */ | ||
1368 | arr[7] = bd_len; /* assume 255 or less */ | ||
829 | offset = 8; | 1369 | offset = 8; |
830 | } | 1370 | } |
831 | ap = arr + offset; | 1371 | ap = arr + offset; |
1372 | if ((bd_len > 0) && (0 == sdebug_capacity)) { | ||
1373 | if (scsi_debug_virtual_gb > 0) { | ||
1374 | sdebug_capacity = 2048 * 1024; | ||
1375 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
1376 | } else | ||
1377 | sdebug_capacity = sdebug_store_sectors; | ||
1378 | } | ||
1379 | if (8 == bd_len) { | ||
1380 | if (sdebug_capacity > 0xfffffffe) { | ||
1381 | ap[0] = 0xff; | ||
1382 | ap[1] = 0xff; | ||
1383 | ap[2] = 0xff; | ||
1384 | ap[3] = 0xff; | ||
1385 | } else { | ||
1386 | ap[0] = (sdebug_capacity >> 24) & 0xff; | ||
1387 | ap[1] = (sdebug_capacity >> 16) & 0xff; | ||
1388 | ap[2] = (sdebug_capacity >> 8) & 0xff; | ||
1389 | ap[3] = sdebug_capacity & 0xff; | ||
1390 | } | ||
1391 | ap[6] = (SECT_SIZE_PER(target) >> 8) & 0xff; | ||
1392 | ap[7] = SECT_SIZE_PER(target) & 0xff; | ||
1393 | offset += bd_len; | ||
1394 | ap = arr + offset; | ||
1395 | } else if (16 == bd_len) { | ||
1396 | unsigned long long capac = sdebug_capacity; | ||
1397 | |||
1398 | for (k = 0; k < 8; ++k, capac >>= 8) | ||
1399 | ap[7 - k] = capac & 0xff; | ||
1400 | ap[12] = (SECT_SIZE_PER(target) >> 24) & 0xff; | ||
1401 | ap[13] = (SECT_SIZE_PER(target) >> 16) & 0xff; | ||
1402 | ap[14] = (SECT_SIZE_PER(target) >> 8) & 0xff; | ||
1403 | ap[15] = SECT_SIZE_PER(target) & 0xff; | ||
1404 | offset += bd_len; | ||
1405 | ap = arr + offset; | ||
1406 | } | ||
832 | 1407 | ||
833 | if (0 != subpcode) { /* TODO: Control Extension page */ | 1408 | if ((subpcode > 0x0) && (subpcode < 0xff) && (0x19 != pcode)) { |
1409 | /* TODO: Control Extension page */ | ||
834 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | 1410 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, |
835 | 0); | 1411 | 0); |
836 | return check_condition_result; | 1412 | return check_condition_result; |
@@ -856,17 +1432,45 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
856 | len = resp_ctrl_m_pg(ap, pcontrol, target); | 1432 | len = resp_ctrl_m_pg(ap, pcontrol, target); |
857 | offset += len; | 1433 | offset += len; |
858 | break; | 1434 | break; |
1435 | case 0x19: /* if spc==1 then sas phy, control+discover */ | ||
1436 | if ((subpcode > 0x2) && (subpcode < 0xff)) { | ||
1437 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1438 | INVALID_FIELD_IN_CDB, 0); | ||
1439 | return check_condition_result; | ||
1440 | } | ||
1441 | len = 0; | ||
1442 | if ((0x0 == subpcode) || (0xff == subpcode)) | ||
1443 | len += resp_sas_sf_m_pg(ap + len, pcontrol, target); | ||
1444 | if ((0x1 == subpcode) || (0xff == subpcode)) | ||
1445 | len += resp_sas_pcd_m_spg(ap + len, pcontrol, target, | ||
1446 | target_dev_id); | ||
1447 | if ((0x2 == subpcode) || (0xff == subpcode)) | ||
1448 | len += resp_sas_sha_m_spg(ap + len, pcontrol); | ||
1449 | offset += len; | ||
1450 | break; | ||
859 | case 0x1c: /* Informational Exceptions Mode page, all devices */ | 1451 | case 0x1c: /* Informational Exceptions Mode page, all devices */ |
860 | len = resp_iec_m_pg(ap, pcontrol, target); | 1452 | len = resp_iec_m_pg(ap, pcontrol, target); |
861 | offset += len; | 1453 | offset += len; |
862 | break; | 1454 | break; |
863 | case 0x3f: /* Read all Mode pages */ | 1455 | case 0x3f: /* Read all Mode pages */ |
864 | len = resp_err_recov_pg(ap, pcontrol, target); | 1456 | if ((0 == subpcode) || (0xff == subpcode)) { |
865 | len += resp_disconnect_pg(ap + len, pcontrol, target); | 1457 | len = resp_err_recov_pg(ap, pcontrol, target); |
866 | len += resp_format_pg(ap + len, pcontrol, target); | 1458 | len += resp_disconnect_pg(ap + len, pcontrol, target); |
867 | len += resp_caching_pg(ap + len, pcontrol, target); | 1459 | len += resp_format_pg(ap + len, pcontrol, target); |
868 | len += resp_ctrl_m_pg(ap + len, pcontrol, target); | 1460 | len += resp_caching_pg(ap + len, pcontrol, target); |
869 | len += resp_iec_m_pg(ap + len, pcontrol, target); | 1461 | len += resp_ctrl_m_pg(ap + len, pcontrol, target); |
1462 | len += resp_sas_sf_m_pg(ap + len, pcontrol, target); | ||
1463 | if (0xff == subpcode) { | ||
1464 | len += resp_sas_pcd_m_spg(ap + len, pcontrol, | ||
1465 | target, target_dev_id); | ||
1466 | len += resp_sas_sha_m_spg(ap + len, pcontrol); | ||
1467 | } | ||
1468 | len += resp_iec_m_pg(ap + len, pcontrol, target); | ||
1469 | } else { | ||
1470 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1471 | INVALID_FIELD_IN_CDB, 0); | ||
1472 | return check_condition_result; | ||
1473 | } | ||
870 | offset += len; | 1474 | offset += len; |
871 | break; | 1475 | break; |
872 | default: | 1476 | default: |
@@ -883,71 +1487,314 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
883 | return fill_from_dev_buffer(scp, arr, min(alloc_len, offset)); | 1487 | return fill_from_dev_buffer(scp, arr, min(alloc_len, offset)); |
884 | } | 1488 | } |
885 | 1489 | ||
886 | static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, | 1490 | #define SDEBUG_MAX_MSELECT_SZ 512 |
887 | int num, struct sdebug_dev_info * devip) | 1491 | |
1492 | static int resp_mode_select(struct scsi_cmnd * scp, int mselect6, | ||
1493 | struct sdebug_dev_info * devip) | ||
1494 | { | ||
1495 | int pf, sp, ps, md_len, bd_len, off, spf, pg_len; | ||
1496 | int param_len, res, errsts, mpage; | ||
1497 | unsigned char arr[SDEBUG_MAX_MSELECT_SZ]; | ||
1498 | unsigned char *cmd = (unsigned char *)scp->cmnd; | ||
1499 | |||
1500 | if ((errsts = check_readiness(scp, 1, devip))) | ||
1501 | return errsts; | ||
1502 | memset(arr, 0, sizeof(arr)); | ||
1503 | pf = cmd[1] & 0x10; | ||
1504 | sp = cmd[1] & 0x1; | ||
1505 | param_len = mselect6 ? cmd[4] : ((cmd[7] << 8) + cmd[8]); | ||
1506 | if ((0 == pf) || sp || (param_len > SDEBUG_MAX_MSELECT_SZ)) { | ||
1507 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1508 | INVALID_FIELD_IN_CDB, 0); | ||
1509 | return check_condition_result; | ||
1510 | } | ||
1511 | res = fetch_to_dev_buffer(scp, arr, param_len); | ||
1512 | if (-1 == res) | ||
1513 | return (DID_ERROR << 16); | ||
1514 | else if ((res < param_len) && | ||
1515 | (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) | ||
1516 | printk(KERN_INFO "scsi_debug: mode_select: cdb indicated=%d, " | ||
1517 | " IO sent=%d bytes\n", param_len, res); | ||
1518 | md_len = mselect6 ? (arr[0] + 1) : ((arr[0] << 8) + arr[1] + 2); | ||
1519 | bd_len = mselect6 ? arr[3] : ((arr[6] << 8) + arr[7]); | ||
1520 | if (md_len > 2) { | ||
1521 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1522 | INVALID_FIELD_IN_PARAM_LIST, 0); | ||
1523 | return check_condition_result; | ||
1524 | } | ||
1525 | off = bd_len + (mselect6 ? 4 : 8); | ||
1526 | mpage = arr[off] & 0x3f; | ||
1527 | ps = !!(arr[off] & 0x80); | ||
1528 | if (ps) { | ||
1529 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1530 | INVALID_FIELD_IN_PARAM_LIST, 0); | ||
1531 | return check_condition_result; | ||
1532 | } | ||
1533 | spf = !!(arr[off] & 0x40); | ||
1534 | pg_len = spf ? ((arr[off + 2] << 8) + arr[off + 3] + 4) : | ||
1535 | (arr[off + 1] + 2); | ||
1536 | if ((pg_len + off) > param_len) { | ||
1537 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1538 | PARAMETER_LIST_LENGTH_ERR, 0); | ||
1539 | return check_condition_result; | ||
1540 | } | ||
1541 | switch (mpage) { | ||
1542 | case 0xa: /* Control Mode page */ | ||
1543 | if (ctrl_m_pg[1] == arr[off + 1]) { | ||
1544 | memcpy(ctrl_m_pg + 2, arr + off + 2, | ||
1545 | sizeof(ctrl_m_pg) - 2); | ||
1546 | scsi_debug_dsense = !!(ctrl_m_pg[2] & 0x4); | ||
1547 | return 0; | ||
1548 | } | ||
1549 | break; | ||
1550 | case 0x1c: /* Informational Exceptions Mode page */ | ||
1551 | if (iec_m_pg[1] == arr[off + 1]) { | ||
1552 | memcpy(iec_m_pg + 2, arr + off + 2, | ||
1553 | sizeof(iec_m_pg) - 2); | ||
1554 | return 0; | ||
1555 | } | ||
1556 | break; | ||
1557 | default: | ||
1558 | break; | ||
1559 | } | ||
1560 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1561 | INVALID_FIELD_IN_PARAM_LIST, 0); | ||
1562 | return check_condition_result; | ||
1563 | } | ||
1564 | |||
1565 | static int resp_temp_l_pg(unsigned char * arr) | ||
1566 | { | ||
1567 | unsigned char temp_l_pg[] = {0x0, 0x0, 0x3, 0x2, 0x0, 38, | ||
1568 | 0x0, 0x1, 0x3, 0x2, 0x0, 65, | ||
1569 | }; | ||
1570 | |||
1571 | memcpy(arr, temp_l_pg, sizeof(temp_l_pg)); | ||
1572 | return sizeof(temp_l_pg); | ||
1573 | } | ||
1574 | |||
1575 | static int resp_ie_l_pg(unsigned char * arr) | ||
1576 | { | ||
1577 | unsigned char ie_l_pg[] = {0x0, 0x0, 0x3, 0x3, 0x0, 0x0, 38, | ||
1578 | }; | ||
1579 | |||
1580 | memcpy(arr, ie_l_pg, sizeof(ie_l_pg)); | ||
1581 | if (iec_m_pg[2] & 0x4) { /* TEST bit set */ | ||
1582 | arr[4] = THRESHOLD_EXCEEDED; | ||
1583 | arr[5] = 0xff; | ||
1584 | } | ||
1585 | return sizeof(ie_l_pg); | ||
1586 | } | ||
1587 | |||
1588 | #define SDEBUG_MAX_LSENSE_SZ 512 | ||
1589 | |||
1590 | static int resp_log_sense(struct scsi_cmnd * scp, | ||
1591 | struct sdebug_dev_info * devip) | ||
1592 | { | ||
1593 | int ppc, sp, pcontrol, pcode, subpcode, alloc_len, errsts, len, n; | ||
1594 | unsigned char arr[SDEBUG_MAX_LSENSE_SZ]; | ||
1595 | unsigned char *cmd = (unsigned char *)scp->cmnd; | ||
1596 | |||
1597 | if ((errsts = check_readiness(scp, 1, devip))) | ||
1598 | return errsts; | ||
1599 | memset(arr, 0, sizeof(arr)); | ||
1600 | ppc = cmd[1] & 0x2; | ||
1601 | sp = cmd[1] & 0x1; | ||
1602 | if (ppc || sp) { | ||
1603 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1604 | INVALID_FIELD_IN_CDB, 0); | ||
1605 | return check_condition_result; | ||
1606 | } | ||
1607 | pcontrol = (cmd[2] & 0xc0) >> 6; | ||
1608 | pcode = cmd[2] & 0x3f; | ||
1609 | subpcode = cmd[3] & 0xff; | ||
1610 | alloc_len = (cmd[7] << 8) + cmd[8]; | ||
1611 | arr[0] = pcode; | ||
1612 | if (0 == subpcode) { | ||
1613 | switch (pcode) { | ||
1614 | case 0x0: /* Supported log pages log page */ | ||
1615 | n = 4; | ||
1616 | arr[n++] = 0x0; /* this page */ | ||
1617 | arr[n++] = 0xd; /* Temperature */ | ||
1618 | arr[n++] = 0x2f; /* Informational exceptions */ | ||
1619 | arr[3] = n - 4; | ||
1620 | break; | ||
1621 | case 0xd: /* Temperature log page */ | ||
1622 | arr[3] = resp_temp_l_pg(arr + 4); | ||
1623 | break; | ||
1624 | case 0x2f: /* Informational exceptions log page */ | ||
1625 | arr[3] = resp_ie_l_pg(arr + 4); | ||
1626 | break; | ||
1627 | default: | ||
1628 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1629 | INVALID_FIELD_IN_CDB, 0); | ||
1630 | return check_condition_result; | ||
1631 | } | ||
1632 | } else if (0xff == subpcode) { | ||
1633 | arr[0] |= 0x40; | ||
1634 | arr[1] = subpcode; | ||
1635 | switch (pcode) { | ||
1636 | case 0x0: /* Supported log pages and subpages log page */ | ||
1637 | n = 4; | ||
1638 | arr[n++] = 0x0; | ||
1639 | arr[n++] = 0x0; /* 0,0 page */ | ||
1640 | arr[n++] = 0x0; | ||
1641 | arr[n++] = 0xff; /* this page */ | ||
1642 | arr[n++] = 0xd; | ||
1643 | arr[n++] = 0x0; /* Temperature */ | ||
1644 | arr[n++] = 0x2f; | ||
1645 | arr[n++] = 0x0; /* Informational exceptions */ | ||
1646 | arr[3] = n - 4; | ||
1647 | break; | ||
1648 | case 0xd: /* Temperature subpages */ | ||
1649 | n = 4; | ||
1650 | arr[n++] = 0xd; | ||
1651 | arr[n++] = 0x0; /* Temperature */ | ||
1652 | arr[3] = n - 4; | ||
1653 | break; | ||
1654 | case 0x2f: /* Informational exceptions subpages */ | ||
1655 | n = 4; | ||
1656 | arr[n++] = 0x2f; | ||
1657 | arr[n++] = 0x0; /* Informational exceptions */ | ||
1658 | arr[3] = n - 4; | ||
1659 | break; | ||
1660 | default: | ||
1661 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1662 | INVALID_FIELD_IN_CDB, 0); | ||
1663 | return check_condition_result; | ||
1664 | } | ||
1665 | } else { | ||
1666 | mk_sense_buffer(devip, ILLEGAL_REQUEST, | ||
1667 | INVALID_FIELD_IN_CDB, 0); | ||
1668 | return check_condition_result; | ||
1669 | } | ||
1670 | len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len); | ||
1671 | return fill_from_dev_buffer(scp, arr, | ||
1672 | min(len, SDEBUG_MAX_INQ_ARR_SZ)); | ||
1673 | } | ||
1674 | |||
1675 | static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba, | ||
1676 | unsigned int num, struct sdebug_dev_info * devip) | ||
888 | { | 1677 | { |
889 | unsigned long iflags; | 1678 | unsigned long iflags; |
1679 | unsigned int block, from_bottom; | ||
1680 | unsigned long long u; | ||
890 | int ret; | 1681 | int ret; |
891 | 1682 | ||
892 | if (upper_blk || (block + num > sdebug_capacity)) { | 1683 | if (lba + num > sdebug_capacity) { |
893 | mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, | 1684 | mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, |
894 | 0); | 1685 | 0); |
895 | return check_condition_result; | 1686 | return check_condition_result; |
896 | } | 1687 | } |
1688 | /* transfer length excessive (tie in to block limits VPD page) */ | ||
1689 | if (num > sdebug_store_sectors) { | ||
1690 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | ||
1691 | 0); | ||
1692 | return check_condition_result; | ||
1693 | } | ||
897 | if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && | 1694 | if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && |
898 | (block <= OPT_MEDIUM_ERR_ADDR) && | 1695 | (lba <= OPT_MEDIUM_ERR_ADDR) && |
899 | ((block + num) > OPT_MEDIUM_ERR_ADDR)) { | 1696 | ((lba + num) > OPT_MEDIUM_ERR_ADDR)) { |
1697 | /* claim unrecoverable read error */ | ||
900 | mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR, | 1698 | mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR, |
901 | 0); | 1699 | 0); |
902 | /* claim unrecoverable read error */ | 1700 | /* set info field and valid bit for fixed descriptor */ |
1701 | if (0x70 == (devip->sense_buff[0] & 0x7f)) { | ||
1702 | devip->sense_buff[0] |= 0x80; /* Valid bit */ | ||
1703 | ret = OPT_MEDIUM_ERR_ADDR; | ||
1704 | devip->sense_buff[3] = (ret >> 24) & 0xff; | ||
1705 | devip->sense_buff[4] = (ret >> 16) & 0xff; | ||
1706 | devip->sense_buff[5] = (ret >> 8) & 0xff; | ||
1707 | devip->sense_buff[6] = ret & 0xff; | ||
1708 | } | ||
903 | return check_condition_result; | 1709 | return check_condition_result; |
904 | } | 1710 | } |
905 | read_lock_irqsave(&atomic_rw, iflags); | 1711 | read_lock_irqsave(&atomic_rw, iflags); |
906 | ret = fill_from_dev_buffer(SCpnt, fake_storep + (block * SECT_SIZE), | 1712 | if ((lba + num) <= sdebug_store_sectors) |
907 | num * SECT_SIZE); | 1713 | ret = fill_from_dev_buffer(SCpnt, |
1714 | fake_storep + (lba * SECT_SIZE), | ||
1715 | num * SECT_SIZE); | ||
1716 | else { | ||
1717 | /* modulo when one arg is 64 bits needs do_div() */ | ||
1718 | u = lba; | ||
1719 | block = do_div(u, sdebug_store_sectors); | ||
1720 | from_bottom = 0; | ||
1721 | if ((block + num) > sdebug_store_sectors) | ||
1722 | from_bottom = (block + num) - sdebug_store_sectors; | ||
1723 | ret = fill_from_dev_buffer(SCpnt, | ||
1724 | fake_storep + (block * SECT_SIZE), | ||
1725 | (num - from_bottom) * SECT_SIZE); | ||
1726 | if ((0 == ret) && (from_bottom > 0)) | ||
1727 | ret = fill_from_dev_buffer(SCpnt, fake_storep, | ||
1728 | from_bottom * SECT_SIZE); | ||
1729 | } | ||
908 | read_unlock_irqrestore(&atomic_rw, iflags); | 1730 | read_unlock_irqrestore(&atomic_rw, iflags); |
909 | return ret; | 1731 | return ret; |
910 | } | 1732 | } |
911 | 1733 | ||
912 | static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, | 1734 | static int resp_write(struct scsi_cmnd * SCpnt, unsigned long long lba, |
913 | int num, struct sdebug_dev_info * devip) | 1735 | unsigned int num, struct sdebug_dev_info * devip) |
914 | { | 1736 | { |
915 | unsigned long iflags; | 1737 | unsigned long iflags; |
1738 | unsigned int block, to_bottom; | ||
1739 | unsigned long long u; | ||
916 | int res; | 1740 | int res; |
917 | 1741 | ||
918 | if (upper_blk || (block + num > sdebug_capacity)) { | 1742 | if (lba + num > sdebug_capacity) { |
919 | mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, | 1743 | mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, |
920 | 0); | 1744 | 0); |
921 | return check_condition_result; | 1745 | return check_condition_result; |
922 | } | 1746 | } |
1747 | /* transfer length excessive (tie in to block limits VPD page) */ | ||
1748 | if (num > sdebug_store_sectors) { | ||
1749 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | ||
1750 | 0); | ||
1751 | return check_condition_result; | ||
1752 | } | ||
923 | 1753 | ||
924 | write_lock_irqsave(&atomic_rw, iflags); | 1754 | write_lock_irqsave(&atomic_rw, iflags); |
925 | res = fetch_to_dev_buffer(SCpnt, fake_storep + (block * SECT_SIZE), | 1755 | if ((lba + num) <= sdebug_store_sectors) |
926 | num * SECT_SIZE); | 1756 | res = fetch_to_dev_buffer(SCpnt, |
1757 | fake_storep + (lba * SECT_SIZE), | ||
1758 | num * SECT_SIZE); | ||
1759 | else { | ||
1760 | /* modulo when one arg is 64 bits needs do_div() */ | ||
1761 | u = lba; | ||
1762 | block = do_div(u, sdebug_store_sectors); | ||
1763 | to_bottom = 0; | ||
1764 | if ((block + num) > sdebug_store_sectors) | ||
1765 | to_bottom = (block + num) - sdebug_store_sectors; | ||
1766 | res = fetch_to_dev_buffer(SCpnt, | ||
1767 | fake_storep + (block * SECT_SIZE), | ||
1768 | (num - to_bottom) * SECT_SIZE); | ||
1769 | if ((0 == res) && (to_bottom > 0)) | ||
1770 | res = fetch_to_dev_buffer(SCpnt, fake_storep, | ||
1771 | to_bottom * SECT_SIZE); | ||
1772 | } | ||
927 | write_unlock_irqrestore(&atomic_rw, iflags); | 1773 | write_unlock_irqrestore(&atomic_rw, iflags); |
928 | if (-1 == res) | 1774 | if (-1 == res) |
929 | return (DID_ERROR << 16); | 1775 | return (DID_ERROR << 16); |
930 | else if ((res < (num * SECT_SIZE)) && | 1776 | else if ((res < (num * SECT_SIZE)) && |
931 | (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) | 1777 | (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) |
932 | printk(KERN_INFO "scsi_debug: write: cdb indicated=%d, " | 1778 | printk(KERN_INFO "scsi_debug: write: cdb indicated=%u, " |
933 | " IO sent=%d bytes\n", num * SECT_SIZE, res); | 1779 | " IO sent=%d bytes\n", num * SECT_SIZE, res); |
934 | return 0; | 1780 | return 0; |
935 | } | 1781 | } |
936 | 1782 | ||
937 | #define SDEBUG_RLUN_ARR_SZ 128 | 1783 | #define SDEBUG_RLUN_ARR_SZ 256 |
938 | 1784 | ||
939 | static int resp_report_luns(struct scsi_cmnd * scp, | 1785 | static int resp_report_luns(struct scsi_cmnd * scp, |
940 | struct sdebug_dev_info * devip) | 1786 | struct sdebug_dev_info * devip) |
941 | { | 1787 | { |
942 | unsigned int alloc_len; | 1788 | unsigned int alloc_len; |
943 | int lun_cnt, i, upper; | 1789 | int lun_cnt, i, upper, num, n, wlun, lun; |
944 | unsigned char *cmd = (unsigned char *)scp->cmnd; | 1790 | unsigned char *cmd = (unsigned char *)scp->cmnd; |
945 | int select_report = (int)cmd[2]; | 1791 | int select_report = (int)cmd[2]; |
946 | struct scsi_lun *one_lun; | 1792 | struct scsi_lun *one_lun; |
947 | unsigned char arr[SDEBUG_RLUN_ARR_SZ]; | 1793 | unsigned char arr[SDEBUG_RLUN_ARR_SZ]; |
1794 | unsigned char * max_addr; | ||
948 | 1795 | ||
949 | alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24); | 1796 | alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24); |
950 | if ((alloc_len < 16) || (select_report > 2)) { | 1797 | if ((alloc_len < 4) || (select_report > 2)) { |
951 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, | 1798 | mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, |
952 | 0); | 1799 | 0); |
953 | return check_condition_result; | 1800 | return check_condition_result; |
@@ -955,18 +1802,37 @@ static int resp_report_luns(struct scsi_cmnd * scp, | |||
955 | /* can produce response with up to 16k luns (lun 0 to lun 16383) */ | 1802 | /* can produce response with up to 16k luns (lun 0 to lun 16383) */ |
956 | memset(arr, 0, SDEBUG_RLUN_ARR_SZ); | 1803 | memset(arr, 0, SDEBUG_RLUN_ARR_SZ); |
957 | lun_cnt = scsi_debug_max_luns; | 1804 | lun_cnt = scsi_debug_max_luns; |
958 | arr[2] = ((sizeof(struct scsi_lun) * lun_cnt) >> 8) & 0xff; | 1805 | if (1 == select_report) |
959 | arr[3] = (sizeof(struct scsi_lun) * lun_cnt) & 0xff; | 1806 | lun_cnt = 0; |
960 | lun_cnt = min((int)((SDEBUG_RLUN_ARR_SZ - 8) / | 1807 | else if (scsi_debug_no_lun_0 && (lun_cnt > 0)) |
961 | sizeof(struct scsi_lun)), lun_cnt); | 1808 | --lun_cnt; |
1809 | wlun = (select_report > 0) ? 1 : 0; | ||
1810 | num = lun_cnt + wlun; | ||
1811 | arr[2] = ((sizeof(struct scsi_lun) * num) >> 8) & 0xff; | ||
1812 | arr[3] = (sizeof(struct scsi_lun) * num) & 0xff; | ||
1813 | n = min((int)((SDEBUG_RLUN_ARR_SZ - 8) / | ||
1814 | sizeof(struct scsi_lun)), num); | ||
1815 | if (n < num) { | ||
1816 | wlun = 0; | ||
1817 | lun_cnt = n; | ||
1818 | } | ||
962 | one_lun = (struct scsi_lun *) &arr[8]; | 1819 | one_lun = (struct scsi_lun *) &arr[8]; |
963 | for (i = 0; i < lun_cnt; i++) { | 1820 | max_addr = arr + SDEBUG_RLUN_ARR_SZ; |
964 | upper = (i >> 8) & 0x3f; | 1821 | for (i = 0, lun = (scsi_debug_no_lun_0 ? 1 : 0); |
1822 | ((i < lun_cnt) && ((unsigned char *)(one_lun + i) < max_addr)); | ||
1823 | i++, lun++) { | ||
1824 | upper = (lun >> 8) & 0x3f; | ||
965 | if (upper) | 1825 | if (upper) |
966 | one_lun[i].scsi_lun[0] = | 1826 | one_lun[i].scsi_lun[0] = |
967 | (upper | (SAM2_LUN_ADDRESS_METHOD << 6)); | 1827 | (upper | (SAM2_LUN_ADDRESS_METHOD << 6)); |
968 | one_lun[i].scsi_lun[1] = i & 0xff; | 1828 | one_lun[i].scsi_lun[1] = lun & 0xff; |
969 | } | 1829 | } |
1830 | if (wlun) { | ||
1831 | one_lun[i].scsi_lun[0] = (SAM2_WLUN_REPORT_LUNS >> 8) & 0xff; | ||
1832 | one_lun[i].scsi_lun[1] = SAM2_WLUN_REPORT_LUNS & 0xff; | ||
1833 | i++; | ||
1834 | } | ||
1835 | alloc_len = (unsigned char *)(one_lun + i) - arr; | ||
970 | return fill_from_dev_buffer(scp, arr, | 1836 | return fill_from_dev_buffer(scp, arr, |
971 | min((int)alloc_len, SDEBUG_RLUN_ARR_SZ)); | 1837 | min((int)alloc_len, SDEBUG_RLUN_ARR_SZ)); |
972 | } | 1838 | } |
@@ -1002,7 +1868,8 @@ static void timer_intr_handler(unsigned long indx) | |||
1002 | static int scsi_debug_slave_alloc(struct scsi_device * sdp) | 1868 | static int scsi_debug_slave_alloc(struct scsi_device * sdp) |
1003 | { | 1869 | { |
1004 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 1870 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
1005 | sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_alloc\n"); | 1871 | printk(KERN_INFO "scsi_debug: slave_alloc <%u %u %u %u>\n", |
1872 | sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); | ||
1006 | return 0; | 1873 | return 0; |
1007 | } | 1874 | } |
1008 | 1875 | ||
@@ -1011,7 +1878,8 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp) | |||
1011 | struct sdebug_dev_info * devip; | 1878 | struct sdebug_dev_info * devip; |
1012 | 1879 | ||
1013 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 1880 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
1014 | sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_configure\n"); | 1881 | printk(KERN_INFO "scsi_debug: slave_configure <%u %u %u %u>\n", |
1882 | sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); | ||
1015 | if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) | 1883 | if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) |
1016 | sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN; | 1884 | sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN; |
1017 | devip = devInfoReg(sdp); | 1885 | devip = devInfoReg(sdp); |
@@ -1019,6 +1887,7 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp) | |||
1019 | if (sdp->host->cmd_per_lun) | 1887 | if (sdp->host->cmd_per_lun) |
1020 | scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING, | 1888 | scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING, |
1021 | sdp->host->cmd_per_lun); | 1889 | sdp->host->cmd_per_lun); |
1890 | blk_queue_max_segment_size(sdp->request_queue, 256 * 1024); | ||
1022 | return 0; | 1891 | return 0; |
1023 | } | 1892 | } |
1024 | 1893 | ||
@@ -1028,7 +1897,8 @@ static void scsi_debug_slave_destroy(struct scsi_device * sdp) | |||
1028 | (struct sdebug_dev_info *)sdp->hostdata; | 1897 | (struct sdebug_dev_info *)sdp->hostdata; |
1029 | 1898 | ||
1030 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) | 1899 | if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) |
1031 | sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_destroy\n"); | 1900 | printk(KERN_INFO "scsi_debug: slave_destroy <%u %u %u %u>\n", |
1901 | sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); | ||
1032 | if (devip) { | 1902 | if (devip) { |
1033 | /* make this slot avaliable for re-use */ | 1903 | /* make this slot avaliable for re-use */ |
1034 | devip->used = 0; | 1904 | devip->used = 0; |
@@ -1085,6 +1955,8 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev) | |||
1085 | open_devip->sense_buff[0] = 0x70; | 1955 | open_devip->sense_buff[0] = 0x70; |
1086 | open_devip->sense_buff[7] = 0xa; | 1956 | open_devip->sense_buff[7] = 0xa; |
1087 | } | 1957 | } |
1958 | if (sdev->lun == SAM2_WLUN_REPORT_LUNS) | ||
1959 | open_devip->wlun = SAM2_WLUN_REPORT_LUNS & 0xff; | ||
1088 | return open_devip; | 1960 | return open_devip; |
1089 | } | 1961 | } |
1090 | return NULL; | 1962 | return NULL; |
@@ -1273,7 +2145,7 @@ static void __init sdebug_build_parts(unsigned char * ramp) | |||
1273 | printk(KERN_WARNING "scsi_debug:build_parts: reducing " | 2145 | printk(KERN_WARNING "scsi_debug:build_parts: reducing " |
1274 | "partitions to %d\n", SDEBUG_MAX_PARTS); | 2146 | "partitions to %d\n", SDEBUG_MAX_PARTS); |
1275 | } | 2147 | } |
1276 | num_sectors = (int)(sdebug_store_size / SECT_SIZE); | 2148 | num_sectors = (int)sdebug_store_sectors; |
1277 | sectors_per_part = (num_sectors - sdebug_sectors_per) | 2149 | sectors_per_part = (num_sectors - sdebug_sectors_per) |
1278 | / scsi_debug_num_parts; | 2150 | / scsi_debug_num_parts; |
1279 | heads_by_sects = sdebug_heads * sdebug_sectors_per; | 2151 | heads_by_sects = sdebug_heads * sdebug_sectors_per; |
@@ -1316,9 +2188,9 @@ static int schedule_resp(struct scsi_cmnd * cmnd, | |||
1316 | if (scsi_result) { | 2188 | if (scsi_result) { |
1317 | struct scsi_device * sdp = cmnd->device; | 2189 | struct scsi_device * sdp = cmnd->device; |
1318 | 2190 | ||
1319 | sdev_printk(KERN_INFO, sdp, | 2191 | printk(KERN_INFO "scsi_debug: <%u %u %u %u> " |
1320 | "non-zero result=0x%x\n", | 2192 | "non-zero result=0x%x\n", sdp->host->host_no, |
1321 | scsi_result); | 2193 | sdp->channel, sdp->id, sdp->lun, scsi_result); |
1322 | } | 2194 | } |
1323 | } | 2195 | } |
1324 | if (cmnd && devip) { | 2196 | if (cmnd && devip) { |
@@ -1365,21 +2237,28 @@ static int schedule_resp(struct scsi_cmnd * cmnd, | |||
1365 | } | 2237 | } |
1366 | } | 2238 | } |
1367 | 2239 | ||
1368 | /* Set 'perm' (4th argument) to 0 to disable module_param's definition | 2240 | /* Note: The following macros create attribute files in the |
1369 | * of sysfs parameters (which module_param doesn't yet support). | 2241 | /sys/module/scsi_debug/parameters directory. Unfortunately this |
1370 | * Sysfs parameters defined explicitly below. | 2242 | driver is unaware of a change and cannot trigger auxiliary actions |
2243 | as it can when the corresponding attribute in the | ||
2244 | /sys/bus/pseudo/drivers/scsi_debug directory is changed. | ||
1371 | */ | 2245 | */ |
1372 | module_param_named(add_host, scsi_debug_add_host, int, 0); /* perm=0644 */ | 2246 | module_param_named(add_host, scsi_debug_add_host, int, S_IRUGO | S_IWUSR); |
1373 | module_param_named(delay, scsi_debug_delay, int, 0); /* perm=0644 */ | 2247 | module_param_named(delay, scsi_debug_delay, int, S_IRUGO | S_IWUSR); |
1374 | module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, 0); | 2248 | module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, S_IRUGO); |
1375 | module_param_named(dsense, scsi_debug_dsense, int, 0); | 2249 | module_param_named(dsense, scsi_debug_dsense, int, S_IRUGO | S_IWUSR); |
1376 | module_param_named(every_nth, scsi_debug_every_nth, int, 0); | 2250 | module_param_named(every_nth, scsi_debug_every_nth, int, S_IRUGO | S_IWUSR); |
1377 | module_param_named(max_luns, scsi_debug_max_luns, int, 0); | 2251 | module_param_named(fake_rw, scsi_debug_fake_rw, int, S_IRUGO | S_IWUSR); |
1378 | module_param_named(num_parts, scsi_debug_num_parts, int, 0); | 2252 | module_param_named(max_luns, scsi_debug_max_luns, int, S_IRUGO | S_IWUSR); |
1379 | module_param_named(num_tgts, scsi_debug_num_tgts, int, 0); | 2253 | module_param_named(no_lun_0, scsi_debug_no_lun_0, int, S_IRUGO | S_IWUSR); |
1380 | module_param_named(opts, scsi_debug_opts, int, 0); /* perm=0644 */ | 2254 | module_param_named(num_parts, scsi_debug_num_parts, int, S_IRUGO); |
1381 | module_param_named(ptype, scsi_debug_ptype, int, 0); | 2255 | module_param_named(num_tgts, scsi_debug_num_tgts, int, S_IRUGO | S_IWUSR); |
1382 | module_param_named(scsi_level, scsi_debug_scsi_level, int, 0); | 2256 | module_param_named(opts, scsi_debug_opts, int, S_IRUGO | S_IWUSR); |
2257 | module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR); | ||
2258 | module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO); | ||
2259 | module_param_named(virtual_gb, scsi_debug_virtual_gb, int, S_IRUGO | S_IWUSR); | ||
2260 | module_param_named(vpd_use_hostno, scsi_debug_vpd_use_hostno, int, | ||
2261 | S_IRUGO | S_IWUSR); | ||
1383 | 2262 | ||
1384 | MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); | 2263 | MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); |
1385 | MODULE_DESCRIPTION("SCSI debug adapter driver"); | 2264 | MODULE_DESCRIPTION("SCSI debug adapter driver"); |
@@ -1388,15 +2267,19 @@ MODULE_VERSION(SCSI_DEBUG_VERSION); | |||
1388 | 2267 | ||
1389 | MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)"); | 2268 | MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)"); |
1390 | MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)"); | 2269 | MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)"); |
1391 | MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs"); | 2270 | MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs(def=8)"); |
1392 | MODULE_PARM_DESC(dsense, "use descriptor sense format(def: fixed)"); | 2271 | MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)"); |
1393 | MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)"); | 2272 | MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)"); |
1394 | MODULE_PARM_DESC(max_luns, "number of SCSI LUNs per target to simulate"); | 2273 | MODULE_PARM_DESC(fake_rw, "fake reads/writes instead of copying (def=0)"); |
2274 | MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)"); | ||
2275 | MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)"); | ||
1395 | MODULE_PARM_DESC(num_parts, "number of partitions(def=0)"); | 2276 | MODULE_PARM_DESC(num_parts, "number of partitions(def=0)"); |
1396 | MODULE_PARM_DESC(num_tgts, "number of SCSI targets per host to simulate"); | 2277 | MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)"); |
1397 | MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->..."); | 2278 | MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->... (def=0)"); |
1398 | MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); | 2279 | MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); |
1399 | MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); | 2280 | MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); |
2281 | MODULE_PARM_DESC(virtual_gb, "virtual gigabyte size (def=0 -> use dev_size_mb)"); | ||
2282 | MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)"); | ||
1400 | 2283 | ||
1401 | 2284 | ||
1402 | static char sdebug_info[256]; | 2285 | static char sdebug_info[256]; |
@@ -1548,6 +2431,42 @@ static ssize_t sdebug_dsense_store(struct device_driver * ddp, | |||
1548 | DRIVER_ATTR(dsense, S_IRUGO | S_IWUSR, sdebug_dsense_show, | 2431 | DRIVER_ATTR(dsense, S_IRUGO | S_IWUSR, sdebug_dsense_show, |
1549 | sdebug_dsense_store); | 2432 | sdebug_dsense_store); |
1550 | 2433 | ||
2434 | static ssize_t sdebug_fake_rw_show(struct device_driver * ddp, char * buf) | ||
2435 | { | ||
2436 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_fake_rw); | ||
2437 | } | ||
2438 | static ssize_t sdebug_fake_rw_store(struct device_driver * ddp, | ||
2439 | const char * buf, size_t count) | ||
2440 | { | ||
2441 | int n; | ||
2442 | |||
2443 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { | ||
2444 | scsi_debug_fake_rw = n; | ||
2445 | return count; | ||
2446 | } | ||
2447 | return -EINVAL; | ||
2448 | } | ||
2449 | DRIVER_ATTR(fake_rw, S_IRUGO | S_IWUSR, sdebug_fake_rw_show, | ||
2450 | sdebug_fake_rw_store); | ||
2451 | |||
2452 | static ssize_t sdebug_no_lun_0_show(struct device_driver * ddp, char * buf) | ||
2453 | { | ||
2454 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_lun_0); | ||
2455 | } | ||
2456 | static ssize_t sdebug_no_lun_0_store(struct device_driver * ddp, | ||
2457 | const char * buf, size_t count) | ||
2458 | { | ||
2459 | int n; | ||
2460 | |||
2461 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { | ||
2462 | scsi_debug_no_lun_0 = n; | ||
2463 | return count; | ||
2464 | } | ||
2465 | return -EINVAL; | ||
2466 | } | ||
2467 | DRIVER_ATTR(no_lun_0, S_IRUGO | S_IWUSR, sdebug_no_lun_0_show, | ||
2468 | sdebug_no_lun_0_store); | ||
2469 | |||
1551 | static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf) | 2470 | static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf) |
1552 | { | 2471 | { |
1553 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); | 2472 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); |
@@ -1623,6 +2542,29 @@ static ssize_t sdebug_scsi_level_show(struct device_driver * ddp, char * buf) | |||
1623 | } | 2542 | } |
1624 | DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL); | 2543 | DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL); |
1625 | 2544 | ||
2545 | static ssize_t sdebug_virtual_gb_show(struct device_driver * ddp, char * buf) | ||
2546 | { | ||
2547 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_virtual_gb); | ||
2548 | } | ||
2549 | static ssize_t sdebug_virtual_gb_store(struct device_driver * ddp, | ||
2550 | const char * buf, size_t count) | ||
2551 | { | ||
2552 | int n; | ||
2553 | |||
2554 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { | ||
2555 | scsi_debug_virtual_gb = n; | ||
2556 | if (scsi_debug_virtual_gb > 0) { | ||
2557 | sdebug_capacity = 2048 * 1024; | ||
2558 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
2559 | } else | ||
2560 | sdebug_capacity = sdebug_store_sectors; | ||
2561 | return count; | ||
2562 | } | ||
2563 | return -EINVAL; | ||
2564 | } | ||
2565 | DRIVER_ATTR(virtual_gb, S_IRUGO | S_IWUSR, sdebug_virtual_gb_show, | ||
2566 | sdebug_virtual_gb_store); | ||
2567 | |||
1626 | static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf) | 2568 | static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf) |
1627 | { | 2569 | { |
1628 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); | 2570 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); |
@@ -1660,29 +2602,65 @@ static ssize_t sdebug_add_host_store(struct device_driver * ddp, | |||
1660 | DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show, | 2602 | DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show, |
1661 | sdebug_add_host_store); | 2603 | sdebug_add_host_store); |
1662 | 2604 | ||
1663 | static void do_create_driverfs_files(void) | 2605 | static ssize_t sdebug_vpd_use_hostno_show(struct device_driver * ddp, |
2606 | char * buf) | ||
1664 | { | 2607 | { |
1665 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_add_host); | 2608 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_vpd_use_hostno); |
1666 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_delay); | 2609 | } |
1667 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); | 2610 | static ssize_t sdebug_vpd_use_hostno_store(struct device_driver * ddp, |
1668 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_dsense); | 2611 | const char * buf, size_t count) |
1669 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_every_nth); | 2612 | { |
1670 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_max_luns); | 2613 | int n; |
1671 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); | 2614 | |
1672 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_parts); | 2615 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { |
1673 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_ptype); | 2616 | scsi_debug_vpd_use_hostno = n; |
1674 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts); | 2617 | return count; |
1675 | driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); | 2618 | } |
2619 | return -EINVAL; | ||
2620 | } | ||
2621 | DRIVER_ATTR(vpd_use_hostno, S_IRUGO | S_IWUSR, sdebug_vpd_use_hostno_show, | ||
2622 | sdebug_vpd_use_hostno_store); | ||
2623 | |||
2624 | /* Note: The following function creates attribute files in the | ||
2625 | /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these | ||
2626 | files (over those found in the /sys/module/scsi_debug/parameters | ||
2627 | directory) is that auxiliary actions can be triggered when an attribute | ||
2628 | is changed. For example see: sdebug_add_host_store() above. | ||
2629 | */ | ||
2630 | static int do_create_driverfs_files(void) | ||
2631 | { | ||
2632 | int ret; | ||
2633 | |||
2634 | ret = driver_create_file(&sdebug_driverfs_driver, &driver_attr_add_host); | ||
2635 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_delay); | ||
2636 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); | ||
2637 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dsense); | ||
2638 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_every_nth); | ||
2639 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_fake_rw); | ||
2640 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_max_luns); | ||
2641 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_no_lun_0); | ||
2642 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_parts); | ||
2643 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); | ||
2644 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_ptype); | ||
2645 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts); | ||
2646 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); | ||
2647 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_virtual_gb); | ||
2648 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_vpd_use_hostno); | ||
2649 | return ret; | ||
1676 | } | 2650 | } |
1677 | 2651 | ||
1678 | static void do_remove_driverfs_files(void) | 2652 | static void do_remove_driverfs_files(void) |
1679 | { | 2653 | { |
2654 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_vpd_use_hostno); | ||
2655 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_virtual_gb); | ||
1680 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); | 2656 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); |
1681 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_opts); | 2657 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_opts); |
1682 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_ptype); | 2658 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_ptype); |
1683 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_parts); | ||
1684 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); | 2659 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); |
2660 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_parts); | ||
2661 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_no_lun_0); | ||
1685 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_max_luns); | 2662 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_max_luns); |
2663 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_fake_rw); | ||
1686 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_every_nth); | 2664 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_every_nth); |
1687 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dsense); | 2665 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dsense); |
1688 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); | 2666 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); |
@@ -1692,14 +2670,20 @@ static void do_remove_driverfs_files(void) | |||
1692 | 2670 | ||
1693 | static int __init scsi_debug_init(void) | 2671 | static int __init scsi_debug_init(void) |
1694 | { | 2672 | { |
1695 | unsigned long sz; | 2673 | unsigned int sz; |
1696 | int host_to_add; | 2674 | int host_to_add; |
1697 | int k; | 2675 | int k; |
2676 | int ret; | ||
1698 | 2677 | ||
1699 | if (scsi_debug_dev_size_mb < 1) | 2678 | if (scsi_debug_dev_size_mb < 1) |
1700 | scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */ | 2679 | scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */ |
1701 | sdebug_store_size = (unsigned long)scsi_debug_dev_size_mb * 1048576; | 2680 | sdebug_store_size = (unsigned int)scsi_debug_dev_size_mb * 1048576; |
1702 | sdebug_capacity = sdebug_store_size / SECT_SIZE; | 2681 | sdebug_store_sectors = sdebug_store_size / SECT_SIZE; |
2682 | if (scsi_debug_virtual_gb > 0) { | ||
2683 | sdebug_capacity = 2048 * 1024; | ||
2684 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
2685 | } else | ||
2686 | sdebug_capacity = sdebug_store_sectors; | ||
1703 | 2687 | ||
1704 | /* play around with geometry, don't waste too much on track 0 */ | 2688 | /* play around with geometry, don't waste too much on track 0 */ |
1705 | sdebug_heads = 8; | 2689 | sdebug_heads = 8; |
@@ -1728,12 +2712,32 @@ static int __init scsi_debug_init(void) | |||
1728 | if (scsi_debug_num_parts > 0) | 2712 | if (scsi_debug_num_parts > 0) |
1729 | sdebug_build_parts(fake_storep); | 2713 | sdebug_build_parts(fake_storep); |
1730 | 2714 | ||
1731 | init_all_queued(); | 2715 | ret = device_register(&pseudo_primary); |
2716 | if (ret < 0) { | ||
2717 | printk(KERN_WARNING "scsi_debug: device_register error: %d\n", | ||
2718 | ret); | ||
2719 | goto free_vm; | ||
2720 | } | ||
2721 | ret = bus_register(&pseudo_lld_bus); | ||
2722 | if (ret < 0) { | ||
2723 | printk(KERN_WARNING "scsi_debug: bus_register error: %d\n", | ||
2724 | ret); | ||
2725 | goto dev_unreg; | ||
2726 | } | ||
2727 | ret = driver_register(&sdebug_driverfs_driver); | ||
2728 | if (ret < 0) { | ||
2729 | printk(KERN_WARNING "scsi_debug: driver_register error: %d\n", | ||
2730 | ret); | ||
2731 | goto bus_unreg; | ||
2732 | } | ||
2733 | ret = do_create_driverfs_files(); | ||
2734 | if (ret < 0) { | ||
2735 | printk(KERN_WARNING "scsi_debug: driver_create_file error: %d\n", | ||
2736 | ret); | ||
2737 | goto del_files; | ||
2738 | } | ||
1732 | 2739 | ||
1733 | device_register(&pseudo_primary); | 2740 | init_all_queued(); |
1734 | bus_register(&pseudo_lld_bus); | ||
1735 | driver_register(&sdebug_driverfs_driver); | ||
1736 | do_create_driverfs_files(); | ||
1737 | 2741 | ||
1738 | sdebug_driver_template.proc_name = (char *)sdebug_proc_name; | 2742 | sdebug_driver_template.proc_name = (char *)sdebug_proc_name; |
1739 | 2743 | ||
@@ -1753,6 +2757,18 @@ static int __init scsi_debug_init(void) | |||
1753 | scsi_debug_add_host); | 2757 | scsi_debug_add_host); |
1754 | } | 2758 | } |
1755 | return 0; | 2759 | return 0; |
2760 | |||
2761 | del_files: | ||
2762 | do_remove_driverfs_files(); | ||
2763 | driver_unregister(&sdebug_driverfs_driver); | ||
2764 | bus_unreg: | ||
2765 | bus_unregister(&pseudo_lld_bus); | ||
2766 | dev_unreg: | ||
2767 | device_unregister(&pseudo_primary); | ||
2768 | free_vm: | ||
2769 | vfree(fake_storep); | ||
2770 | |||
2771 | return ret; | ||
1756 | } | 2772 | } |
1757 | 2773 | ||
1758 | static void __exit scsi_debug_exit(void) | 2774 | static void __exit scsi_debug_exit(void) |
@@ -1813,7 +2829,7 @@ static int sdebug_add_adapter(void) | |||
1813 | struct sdebug_dev_info *sdbg_devinfo; | 2829 | struct sdebug_dev_info *sdbg_devinfo; |
1814 | struct list_head *lh, *lh_sf; | 2830 | struct list_head *lh, *lh_sf; |
1815 | 2831 | ||
1816 | sdbg_host = kzalloc(sizeof(*sdbg_host), GFP_KERNEL); | 2832 | sdbg_host = kzalloc(sizeof(*sdbg_host),GFP_KERNEL); |
1817 | 2833 | ||
1818 | if (NULL == sdbg_host) { | 2834 | if (NULL == sdbg_host) { |
1819 | printk(KERN_ERR "%s: out of memory at line %d\n", | 2835 | printk(KERN_ERR "%s: out of memory at line %d\n", |
@@ -1825,7 +2841,7 @@ static int sdebug_add_adapter(void) | |||
1825 | 2841 | ||
1826 | devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns; | 2842 | devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns; |
1827 | for (k = 0; k < devs_per_host; k++) { | 2843 | for (k = 0; k < devs_per_host; k++) { |
1828 | sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo), GFP_KERNEL); | 2844 | sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo),GFP_KERNEL); |
1829 | if (NULL == sdbg_devinfo) { | 2845 | if (NULL == sdbg_devinfo) { |
1830 | printk(KERN_ERR "%s: out of memory at line %d\n", | 2846 | printk(KERN_ERR "%s: out of memory at line %d\n", |
1831 | __FUNCTION__, __LINE__); | 2847 | __FUNCTION__, __LINE__); |
@@ -1906,7 +2922,7 @@ static int sdebug_driver_probe(struct device * dev) | |||
1906 | hpnt->max_id = scsi_debug_num_tgts + 1; | 2922 | hpnt->max_id = scsi_debug_num_tgts + 1; |
1907 | else | 2923 | else |
1908 | hpnt->max_id = scsi_debug_num_tgts; | 2924 | hpnt->max_id = scsi_debug_num_tgts; |
1909 | hpnt->max_lun = scsi_debug_max_luns; | 2925 | hpnt->max_lun = SAM2_WLUN_REPORT_LUNS; /* = scsi_debug_max_luns; */ |
1910 | 2926 | ||
1911 | error = scsi_add_host(hpnt, &sdbg_host->dev); | 2927 | error = scsi_add_host(hpnt, &sdbg_host->dev); |
1912 | if (error) { | 2928 | if (error) { |
@@ -1960,7 +2976,7 @@ static void sdebug_max_tgts_luns(void) | |||
1960 | hpnt->max_id = scsi_debug_num_tgts + 1; | 2976 | hpnt->max_id = scsi_debug_num_tgts + 1; |
1961 | else | 2977 | else |
1962 | hpnt->max_id = scsi_debug_num_tgts; | 2978 | hpnt->max_id = scsi_debug_num_tgts; |
1963 | hpnt->max_lun = scsi_debug_max_luns; | 2979 | hpnt->max_lun = SAM2_WLUN_REPORT_LUNS; /* scsi_debug_max_luns; */ |
1964 | } | 2980 | } |
1965 | spin_unlock(&sdebug_host_list_lock); | 2981 | spin_unlock(&sdebug_host_list_lock); |
1966 | } | 2982 | } |