Commit c560c423 authored by James Bottomley's avatar James Bottomley

scsi_debug: num_parts, ptype and (re-)scans

From: 	Douglas Gilbert <dougg@torque.net>

Changes in version 1.73:
  - 'num_parts' parameter to specify 0 to 4 partitions
  - 'ptype' to specify (or change via sysfs) SCSI
    peripheral device type
  - support ability to increase the number of targets
    and/or luns then re-scan a scsi_debug host
  - remove redundant trailing spaces

The new facilties are described at:
http://www.torque.net/sg/sdebug26.html
A tarball of driver (version 1.73) is also there.
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
(conflict resolution)
parent c71a48f9
/* /*
* linux/kernel/scsi_debug.c * linux/kernel/scsi_debug.c
* vvvvvvvvvvvvvvvvvvvvvvv Original vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv * vvvvvvvvvvvvvvvvvvvvvvv Original vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
* Copyright (C) 1992 Eric Youngdale * Copyright (C) 1992 Eric Youngdale
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
* anything out of the ordinary is seen. * anything out of the ordinary is seen.
* ^^^^^^^^^^^^^^^^^^^^^^^ Original ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * ^^^^^^^^^^^^^^^^^^^^^^^ Original ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* *
* This version is more generic, simulating a variable number of disk * This version is more generic, simulating a variable number of disk
* (or disk like devices) sharing a common amount of RAM * (or disk like devices) sharing a common amount of RAM
* *
* *
* For documentation see http://www.torque.net/sg/sdebug25.html * For documentation see http://www.torque.net/sg/sdebug25.html
* *
...@@ -55,7 +55,8 @@ ...@@ -55,7 +55,8 @@
#include "scsi_logging.h" #include "scsi_logging.h"
#include "scsi_debug.h" #include "scsi_debug.h"
static const char * scsi_debug_version_str = "Version: 1.71 (20031007)"; #define SCSI_DEBUG_VERSION "1.73"
static const char * scsi_debug_version_date = "20040518";
/* Additional Sense Code (ASC) used */ /* Additional Sense Code (ASC) used */
#define NO_ADDED_SENSE 0x0 #define NO_ADDED_SENSE 0x0
...@@ -76,11 +77,13 @@ static const char * scsi_debug_version_str = "Version: 1.71 (20031007)"; ...@@ -76,11 +77,13 @@ static const char * scsi_debug_version_str = "Version: 1.71 (20031007)";
/* With these defaults, this driver will make 1 host with 1 target /* With these defaults, this driver will make 1 host with 1 target
* (id 0) containing 1 logical unit (lun 0). That is 1 device. * (id 0) containing 1 logical unit (lun 0). That is 1 device.
*/ */
#define DEF_DELAY 1
#define DEF_DEV_SIZE_MB 8 #define DEF_DEV_SIZE_MB 8
#define DEF_EVERY_NTH 0 #define DEF_EVERY_NTH 0
#define DEF_DELAY 1 #define DEF_NUM_PARTS 0
#define DEF_SCSI_LEVEL 3
#define DEF_OPTS 0 #define DEF_OPTS 0
#define DEF_SCSI_LEVEL 3
#define DEF_PTYPE 0
/* bit mask values for scsi_debug_opts */ /* bit mask values for scsi_debug_opts */
#define SCSI_DEBUG_OPT_NOISE 1 #define SCSI_DEBUG_OPT_NOISE 1
...@@ -101,19 +104,21 @@ static const char * scsi_debug_version_str = "Version: 1.71 (20031007)"; ...@@ -101,19 +104,21 @@ static const char * scsi_debug_version_str = "Version: 1.71 (20031007)";
* or "peripheral device" addressing (value 0) */ * or "peripheral device" addressing (value 0) */
#define SAM2_LUN_ADDRESS_METHOD 0 #define SAM2_LUN_ADDRESS_METHOD 0
static int scsi_debug_add_host = DEF_NUM_HOST;
static int scsi_debug_delay = DEF_DELAY;
static int scsi_debug_dev_size_mb = DEF_DEV_SIZE_MB; static int scsi_debug_dev_size_mb = DEF_DEV_SIZE_MB;
static int scsi_debug_num_tgts = DEF_NUM_TGTS; /* targets per host */
static int scsi_debug_opts = DEF_OPTS;
static int scsi_debug_every_nth = DEF_EVERY_NTH; static int scsi_debug_every_nth = DEF_EVERY_NTH;
static int scsi_debug_cmnd_count = 0;
static int scsi_debug_delay = DEF_DELAY;
static int scsi_debug_max_luns = DEF_MAX_LUNS; static int scsi_debug_max_luns = DEF_MAX_LUNS;
static int scsi_debug_num_parts = DEF_NUM_PARTS;
static int scsi_debug_num_tgts = DEF_NUM_TGTS; /* targets per host */
static int scsi_debug_opts = DEF_OPTS;
static int scsi_debug_scsi_level = DEF_SCSI_LEVEL; static int scsi_debug_scsi_level = DEF_SCSI_LEVEL;
static int scsi_debug_add_host = DEF_NUM_HOST; static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */
static int scsi_debug_cmnd_count = 0;
#define DEV_READONLY(TGT) (0) #define DEV_READONLY(TGT) (0)
#define DEV_REMOVEABLE(TGT) (0) #define DEV_REMOVEABLE(TGT) (0)
#define PERIPH_DEVICE_TYPE(TGT) (TYPE_DISK);
static unsigned long sdebug_store_size; /* in bytes */ static unsigned long sdebug_store_size; /* in bytes */
static sector_t sdebug_capacity; /* in sectors */ static sector_t sdebug_capacity; /* in sectors */
...@@ -129,6 +134,8 @@ static int sdebug_sectors_per; /* sectors per cylinder */ ...@@ -129,6 +134,8 @@ static int sdebug_sectors_per; /* sectors per cylinder */
#define SECT_SIZE (1 << POW2_SECT_SIZE) #define SECT_SIZE (1 << POW2_SECT_SIZE)
#define SECT_SIZE_PER(TGT) SECT_SIZE #define SECT_SIZE_PER(TGT) SECT_SIZE
#define SDEBUG_MAX_PARTS 4
#define SDEBUG_SENSE_LEN 32 #define SDEBUG_SENSE_LEN 32
struct sdebug_dev_info { struct sdebug_dev_info {
...@@ -215,7 +222,7 @@ static struct device_driver sdebug_driverfs_driver = { ...@@ -215,7 +222,7 @@ static struct device_driver sdebug_driverfs_driver = {
.remove = sdebug_driver_remove, .remove = sdebug_driver_remove,
}; };
static const int check_condition_result = static const int check_condition_result =
(DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
/* function declarations */ /* function declarations */
...@@ -224,7 +231,7 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff, ...@@ -224,7 +231,7 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff,
static int resp_mode_sense(unsigned char * cmd, int target, static int resp_mode_sense(unsigned char * cmd, int target,
unsigned char * buff, int bufflen, unsigned char * buff, int bufflen,
struct sdebug_dev_info * devip); struct sdebug_dev_info * devip);
static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block,
int num, struct sdebug_dev_info * devip); int num, struct sdebug_dev_info * devip);
static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block,
int num, struct sdebug_dev_info * devip); int num, struct sdebug_dev_info * devip);
...@@ -232,14 +239,15 @@ static int resp_report_luns(unsigned char * cmd, unsigned char * buff, ...@@ -232,14 +239,15 @@ static int resp_report_luns(unsigned char * cmd, unsigned char * buff,
int bufflen, struct sdebug_dev_info * devip); int bufflen, struct sdebug_dev_info * devip);
static void timer_intr_handler(unsigned long); static void timer_intr_handler(unsigned long);
static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev); static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev);
static void mk_sense_buffer(struct sdebug_dev_info * devip, int key, static void mk_sense_buffer(struct sdebug_dev_info * devip, int key,
int asc, int asq, int inbandLen); int asc, int asq, int inbandLen);
static int check_reset(struct scsi_cmnd * SCpnt, static int check_reset(struct scsi_cmnd * SCpnt,
struct sdebug_dev_info * devip); struct sdebug_dev_info * devip);
static int schedule_resp(struct scsi_cmnd * cmnd, static int schedule_resp(struct scsi_cmnd * cmnd,
struct sdebug_dev_info * devip, struct sdebug_dev_info * devip,
done_funct_t done, int scsi_result, int delta_jiff); done_funct_t done, int scsi_result, int delta_jiff);
static void init_all_queued(void); static void __init sdebug_build_parts(unsigned char * ramp);
static void __init init_all_queued(void);
static void stop_all_queued(void); static void stop_all_queued(void);
static int stop_queued_cmnd(struct scsi_cmnd * cmnd); static int stop_queued_cmnd(struct scsi_cmnd * cmnd);
static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, static int inquiry_evpd_83(unsigned char * arr, int dev_id_num,
...@@ -249,6 +257,8 @@ static void do_remove_driverfs_files(void); ...@@ -249,6 +257,8 @@ static void do_remove_driverfs_files(void);
static int sdebug_add_adapter(void); static int sdebug_add_adapter(void);
static void sdebug_remove_adapter(void); static void sdebug_remove_adapter(void);
static void sdebug_max_tgts_luns(void);
static struct device pseudo_primary; static struct device pseudo_primary;
static struct bus_type pseudo_lld_bus; static struct bus_type pseudo_lld_bus;
...@@ -257,7 +267,7 @@ static unsigned char * scatg2virt(const struct scatterlist * sclp) ...@@ -257,7 +267,7 @@ static unsigned char * scatg2virt(const struct scatterlist * sclp)
if (NULL == sclp) if (NULL == sclp)
return NULL; return NULL;
else if (sclp->page) else if (sclp->page)
return (unsigned char *)page_address(sclp->page) + return (unsigned char *)page_address(sclp->page) +
sclp->offset; sclp->offset;
else else
return NULL; return NULL;
...@@ -288,7 +298,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -288,7 +298,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
bufflen = sgpnt[0].length; bufflen = sgpnt[0].length;
/* READ and WRITE process scatterlist themselves */ /* READ and WRITE process scatterlist themselves */
} }
else else
buff = (unsigned char *) SCpnt->request_buffer; buff = (unsigned char *) SCpnt->request_buffer;
if (NULL == buff) { if (NULL == buff) {
buff = spare_buff; /* assume cmd moves no data */ buff = spare_buff; /* assume cmd moves no data */
...@@ -304,11 +314,11 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -304,11 +314,11 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
} }
if (SCpnt->device->lun >= scsi_debug_max_luns) if (SCpnt->device->lun >= scsi_debug_max_luns)
return schedule_resp(SCpnt, NULL, done, return schedule_resp(SCpnt, NULL, done,
DID_NO_CONNECT << 16, 0); DID_NO_CONNECT << 16, 0);
devip = devInfoReg(SCpnt->device); devip = devInfoReg(SCpnt->device);
if (NULL == devip) if (NULL == devip)
return schedule_resp(SCpnt, NULL, done, return schedule_resp(SCpnt, NULL, done,
DID_NO_CONNECT << 16, 0); DID_NO_CONNECT << 16, 0);
if ((scsi_debug_every_nth > 0) && if ((scsi_debug_every_nth > 0) &&
...@@ -331,7 +341,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -331,7 +341,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
* shouldn't need to call REQUEST_SENSE */ * shouldn't need to call REQUEST_SENSE */
if (devip) { if (devip) {
sbuff = devip->sense_buff; sbuff = devip->sense_buff;
memcpy(buff, sbuff, (bufflen < SDEBUG_SENSE_LEN) ? memcpy(buff, sbuff, (bufflen < SDEBUG_SENSE_LEN) ?
bufflen : SDEBUG_SENSE_LEN); bufflen : SDEBUG_SENSE_LEN);
mk_sense_buffer(devip, 0, NO_ADDED_SENSE, 0, 7); mk_sense_buffer(devip, 0, NO_ADDED_SENSE, 0, 7);
} else { } else {
...@@ -392,29 +402,29 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -392,29 +402,29 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
break; break;
upper_blk = 0; upper_blk = 0;
if ((*cmd) == READ_16) { if ((*cmd) == READ_16) {
upper_blk = cmd[5] + (cmd[4] << 8) + upper_blk = cmd[5] + (cmd[4] << 8) +
(cmd[3] << 16) + (cmd[2] << 24); (cmd[3] << 16) + (cmd[2] << 24);
block = cmd[9] + (cmd[8] << 8) + block = cmd[9] + (cmd[8] << 8) +
(cmd[7] << 16) + (cmd[6] << 24); (cmd[7] << 16) + (cmd[6] << 24);
num = cmd[13] + (cmd[12] << 8) + num = cmd[13] + (cmd[12] << 8) +
(cmd[11] << 16) + (cmd[10] << 24); (cmd[11] << 16) + (cmd[10] << 24);
} else if ((*cmd) == READ_12) { } else if ((*cmd) == READ_12) {
block = cmd[5] + (cmd[4] << 8) + block = cmd[5] + (cmd[4] << 8) +
(cmd[3] << 16) + (cmd[2] << 24); (cmd[3] << 16) + (cmd[2] << 24);
num = cmd[9] + (cmd[8] << 8) + num = cmd[9] + (cmd[8] << 8) +
(cmd[7] << 16) + (cmd[6] << 24); (cmd[7] << 16) + (cmd[6] << 24);
} else if ((*cmd) == READ_10) { } else if ((*cmd) == READ_10) {
block = cmd[5] + (cmd[4] << 8) + block = cmd[5] + (cmd[4] << 8) +
(cmd[3] << 16) + (cmd[2] << 24); (cmd[3] << 16) + (cmd[2] << 24);
num = cmd[8] + (cmd[7] << 8); num = cmd[8] + (cmd[7] << 8);
} else { } else {
block = cmd[3] + (cmd[2] << 8) + block = cmd[3] + (cmd[2] << 8) +
((cmd[1] & 0x1f) << 16); ((cmd[1] & 0x1f) << 16);
num = cmd[4]; num = cmd[4];
} }
errsts = resp_read(SCpnt, upper_blk, block, num, devip); errsts = resp_read(SCpnt, upper_blk, block, num, devip);
if (inj_recovered && (0 == errsts)) { if (inj_recovered && (0 == errsts)) {
mk_sense_buffer(devip, RECOVERED_ERROR, mk_sense_buffer(devip, RECOVERED_ERROR,
THRESHHOLD_EXCEEDED, 0, 18); THRESHHOLD_EXCEEDED, 0, 18);
errsts = check_condition_result; errsts = check_condition_result;
} }
...@@ -430,29 +440,29 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -430,29 +440,29 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
break; break;
upper_blk = 0; upper_blk = 0;
if ((*cmd) == WRITE_16) { if ((*cmd) == WRITE_16) {
upper_blk = cmd[5] + (cmd[4] << 8) + upper_blk = cmd[5] + (cmd[4] << 8) +
(cmd[3] << 16) + (cmd[2] << 24); (cmd[3] << 16) + (cmd[2] << 24);
block = cmd[9] + (cmd[8] << 8) + block = cmd[9] + (cmd[8] << 8) +
(cmd[7] << 16) + (cmd[6] << 24); (cmd[7] << 16) + (cmd[6] << 24);
num = cmd[13] + (cmd[12] << 8) + num = cmd[13] + (cmd[12] << 8) +
(cmd[11] << 16) + (cmd[10] << 24); (cmd[11] << 16) + (cmd[10] << 24);
} else if ((*cmd) == WRITE_12) { } else if ((*cmd) == WRITE_12) {
block = cmd[5] + (cmd[4] << 8) + block = cmd[5] + (cmd[4] << 8) +
(cmd[3] << 16) + (cmd[2] << 24); (cmd[3] << 16) + (cmd[2] << 24);
num = cmd[9] + (cmd[8] << 8) + num = cmd[9] + (cmd[8] << 8) +
(cmd[7] << 16) + (cmd[6] << 24); (cmd[7] << 16) + (cmd[6] << 24);
} else if ((*cmd) == WRITE_10) { } else if ((*cmd) == WRITE_10) {
block = cmd[5] + (cmd[4] << 8) + block = cmd[5] + (cmd[4] << 8) +
(cmd[3] << 16) + (cmd[2] << 24); (cmd[3] << 16) + (cmd[2] << 24);
num = cmd[8] + (cmd[7] << 8); num = cmd[8] + (cmd[7] << 8);
} else { } else {
block = cmd[3] + (cmd[2] << 8) + block = cmd[3] + (cmd[2] << 8) +
((cmd[1] & 0x1f) << 16); ((cmd[1] & 0x1f) << 16);
num = cmd[4]; num = cmd[4];
} }
errsts = resp_write(SCpnt, upper_blk, block, num, devip); errsts = resp_write(SCpnt, upper_blk, block, num, devip);
if (inj_recovered && (0 == errsts)) { if (inj_recovered && (0 == errsts)) {
mk_sense_buffer(devip, RECOVERED_ERROR, mk_sense_buffer(devip, RECOVERED_ERROR,
THRESHHOLD_EXCEEDED, 0, 18); THRESHHOLD_EXCEEDED, 0, 18);
errsts = check_condition_result; errsts = check_condition_result;
} }
...@@ -500,7 +510,7 @@ static const char * vendor_id = "Linux "; ...@@ -500,7 +510,7 @@ static const char * vendor_id = "Linux ";
static const char * product_id = "scsi_debug "; static const char * product_id = "scsi_debug ";
static const char * product_rev = "0004"; static const char * product_rev = "0004";
static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, static int inquiry_evpd_83(unsigned char * arr, int dev_id_num,
const char * dev_id_str, int dev_id_str_len) const char * dev_id_str, int dev_id_str_len)
{ {
int num; int num;
...@@ -537,7 +547,7 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff, ...@@ -537,7 +547,7 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff,
{ {
unsigned char pq_pdt; unsigned char pq_pdt;
unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ]; unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ];
int min_len = bufflen > SDEBUG_MAX_INQ_ARR_SZ ? int min_len = bufflen > SDEBUG_MAX_INQ_ARR_SZ ?
SDEBUG_MAX_INQ_ARR_SZ : bufflen; SDEBUG_MAX_INQ_ARR_SZ : bufflen;
if (bufflen < cmd[4]) if (bufflen < cmd[4])
...@@ -545,7 +555,7 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff, ...@@ -545,7 +555,7 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff,
"< alloc_length=%d\n", bufflen, (int)cmd[4]); "< alloc_length=%d\n", bufflen, (int)cmd[4]);
memset(buff, 0, bufflen); memset(buff, 0, bufflen);
memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ); memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ);
pq_pdt = PERIPH_DEVICE_TYPE(target); pq_pdt = (scsi_debug_ptype & 0x1f);
arr[0] = pq_pdt; arr[0] = pq_pdt;
if (0x2 & cmd[1]) { /* CMDDT bit set */ if (0x2 & cmd[1]) { /* CMDDT bit set */
mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
...@@ -573,11 +583,11 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff, ...@@ -573,11 +583,11 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff,
dev_id_str, len); dev_id_str, len);
} else { } else {
/* Illegal request, invalid field in cdb */ /* Illegal request, invalid field in cdb */
mk_sense_buffer(devip, ILLEGAL_REQUEST, mk_sense_buffer(devip, ILLEGAL_REQUEST,
INVALID_FIELD_IN_CDB, 0, 18); INVALID_FIELD_IN_CDB, 0, 18);
return check_condition_result; return check_condition_result;
} }
memcpy(buff, arr, min_len); memcpy(buff, arr, min_len);
return 0; return 0;
} }
/* drops through here for a standard inquiry */ /* drops through here for a standard inquiry */
...@@ -592,11 +602,11 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff, ...@@ -592,11 +602,11 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff,
return 0; return 0;
} }
/* <<Following mode page info copied from ST318451LW>> */ /* <<Following mode page info copied from ST318451LW>> */
static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target) static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target)
{ /* Read-Write Error Recovery page for mode_sense */ { /* Read-Write Error Recovery page for mode_sense */
unsigned char err_recov_pg[] = {0x1, 0xa, 0xc0, 11, 240, 0, 0, 0, unsigned char err_recov_pg[] = {0x1, 0xa, 0xc0, 11, 240, 0, 0, 0,
5, 0, 0xff, 0xff}; 5, 0, 0xff, 0xff};
memcpy(p, err_recov_pg, sizeof(err_recov_pg)); memcpy(p, err_recov_pg, sizeof(err_recov_pg));
...@@ -607,7 +617,7 @@ static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target) ...@@ -607,7 +617,7 @@ static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target)
static int resp_disconnect_pg(unsigned char * p, int pcontrol, int target) static int resp_disconnect_pg(unsigned char * p, int pcontrol, int target)
{ /* Disconnect-Reconnect page for mode_sense */ { /* Disconnect-Reconnect page for mode_sense */
unsigned char disconnect_pg[] = {0x2, 0xe, 128, 128, 0, 10, 0, 0, unsigned char disconnect_pg[] = {0x2, 0xe, 128, 128, 0, 10, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0}; 0, 0, 0, 0, 0, 0, 0, 0};
memcpy(p, disconnect_pg, sizeof(disconnect_pg)); memcpy(p, disconnect_pg, sizeof(disconnect_pg));
...@@ -636,7 +646,7 @@ static int resp_format_pg(unsigned char * p, int pcontrol, int target) ...@@ -636,7 +646,7 @@ static int resp_format_pg(unsigned char * p, int pcontrol, int target)
static int resp_caching_pg(unsigned char * p, int pcontrol, int target) static int resp_caching_pg(unsigned char * p, int pcontrol, int target)
{ /* Caching page for mode_sense */ { /* Caching page for mode_sense */
unsigned char caching_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0, unsigned char caching_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0,
0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0}; 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0};
memcpy(p, caching_pg, sizeof(caching_pg)); memcpy(p, caching_pg, sizeof(caching_pg));
...@@ -678,7 +688,7 @@ static int resp_mode_sense(unsigned char * cmd, int target, ...@@ -678,7 +688,7 @@ static int resp_mode_sense(unsigned char * cmd, int target,
int alloc_len, msense_6, offset, len; int alloc_len, msense_6, offset, len;
unsigned char * ap; unsigned char * ap;
unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; unsigned char arr[SDEBUG_MAX_MSENSE_SZ];
int min_len = bufflen > SDEBUG_MAX_MSENSE_SZ ? int min_len = bufflen > SDEBUG_MAX_MSENSE_SZ ?
SDEBUG_MAX_MSENSE_SZ : bufflen; SDEBUG_MAX_MSENSE_SZ : bufflen;
SCSI_LOG_LLQUEUE(3, printk("Mode sense ...(%p %d)\n", buff, bufflen)); SCSI_LOG_LLQUEUE(3, printk("Mode sense ...(%p %d)\n", buff, bufflen));
...@@ -753,14 +763,14 @@ static int resp_mode_sense(unsigned char * cmd, int target, ...@@ -753,14 +763,14 @@ static int resp_mode_sense(unsigned char * cmd, int target,
arr[0] = offset - 1; arr[0] = offset - 1;
else { else {
offset -= 2; offset -= 2;
arr[0] = (offset >> 8) & 0xff; arr[0] = (offset >> 8) & 0xff;
arr[1] = offset & 0xff; arr[1] = offset & 0xff;
} }
memcpy(buff, arr, min_len); memcpy(buff, arr, min_len);
return 0; return 0;
} }
static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block,
int num, struct sdebug_dev_info * devip) int num, struct sdebug_dev_info * devip)
{ {
unsigned char *buff = (unsigned char *) SCpnt->request_buffer; unsigned char *buff = (unsigned char *) SCpnt->request_buffer;
...@@ -770,14 +780,14 @@ static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, ...@@ -770,14 +780,14 @@ static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block,
unsigned long iflags; unsigned long iflags;
if (upper_blk || (block + num > sdebug_capacity)) { if (upper_blk || (block + num > sdebug_capacity)) {
mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE,
0, 18); 0, 18);
return check_condition_result; return check_condition_result;
} }
if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) &&
(block <= OPT_MEDIUM_ERR_ADDR) && (block <= OPT_MEDIUM_ERR_ADDR) &&
((block + num) > OPT_MEDIUM_ERR_ADDR)) { ((block + num) > OPT_MEDIUM_ERR_ADDR)) {
mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR, mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR,
0, 18); 0, 18);
/* claim unrecoverable read error */ /* claim unrecoverable read error */
return check_condition_result; return check_condition_result;
...@@ -785,7 +795,7 @@ static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, ...@@ -785,7 +795,7 @@ static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block,
read_lock_irqsave(&atomic_rw, iflags); read_lock_irqsave(&atomic_rw, iflags);
sgcount = 0; sgcount = 0;
nbytes = bufflen; nbytes = bufflen;
/* printk(KERN_INFO "scsi_debug_read: block=%d, tot_bufflen=%d\n", /* printk(KERN_INFO "scsi_debug_read: block=%d, tot_bufflen=%d\n",
block, bufflen); */ block, bufflen); */
if (SCpnt->use_sg) { if (SCpnt->use_sg) {
sgcount = 0; sgcount = 0;
...@@ -857,7 +867,7 @@ static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, ...@@ -857,7 +867,7 @@ static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block,
static int resp_report_luns(unsigned char * cmd, unsigned char * buff, static int resp_report_luns(unsigned char * cmd, unsigned char * buff,
int bufflen, struct sdebug_dev_info * devip) int bufflen, struct sdebug_dev_info * devip)
{ {
unsigned int alloc_len; unsigned int alloc_len;
int lun_cnt, i, upper; int lun_cnt, i, upper;
int select_report = (int)cmd[2]; int select_report = (int)cmd[2];
struct scsi_lun *one_lun; struct scsi_lun *one_lun;
...@@ -868,19 +878,19 @@ static int resp_report_luns(unsigned char * cmd, unsigned char * buff, ...@@ -868,19 +878,19 @@ static int resp_report_luns(unsigned char * cmd, unsigned char * buff,
0, 18); 0, 18);
return check_condition_result; return check_condition_result;
} }
if (bufflen > 8) { /* can produce response with up to 16k luns if (bufflen > 8) { /* can produce response with up to 16k luns
(lun 0 to lun 16383) */ (lun 0 to lun 16383) */
memset(buff, 0, bufflen); memset(buff, 0, bufflen);
lun_cnt = scsi_debug_max_luns; lun_cnt = scsi_debug_max_luns;
buff[2] = ((sizeof(struct scsi_lun) * lun_cnt) >> 8) & 0xff; buff[2] = ((sizeof(struct scsi_lun) * lun_cnt) >> 8) & 0xff;
buff[3] = (sizeof(struct scsi_lun) * lun_cnt) & 0xff; buff[3] = (sizeof(struct scsi_lun) * lun_cnt) & 0xff;
lun_cnt = min((int)((bufflen - 8) / sizeof(struct scsi_lun)), lun_cnt = min((int)((bufflen - 8) / sizeof(struct scsi_lun)),
lun_cnt); lun_cnt);
one_lun = (struct scsi_lun *) &buff[8]; one_lun = (struct scsi_lun *) &buff[8];
for (i = 0; i < lun_cnt; i++) { for (i = 0; i < lun_cnt; i++) {
upper = (i >> 8) & 0x3f; upper = (i >> 8) & 0x3f;
if (upper) if (upper)
one_lun[i].scsi_lun[0] = one_lun[i].scsi_lun[0] =
(upper | (SAM2_LUN_ADDRESS_METHOD << 6)); (upper | (SAM2_LUN_ADDRESS_METHOD << 6));
one_lun[i].scsi_lun[1] = i & 0xff; one_lun[i].scsi_lun[1] = i & 0xff;
} }
...@@ -926,7 +936,7 @@ static int scsi_debug_slave_alloc(struct scsi_device * sdp) ...@@ -926,7 +936,7 @@ static int scsi_debug_slave_alloc(struct scsi_device * sdp)
static int scsi_debug_slave_configure(struct scsi_device * sdp) static int scsi_debug_slave_configure(struct scsi_device * sdp)
{ {
struct sdebug_dev_info * devip; struct sdebug_dev_info * devip;
if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
printk(KERN_INFO "scsi_debug: slave_configure <%u %u %u %u>\n", printk(KERN_INFO "scsi_debug: slave_configure <%u %u %u %u>\n",
...@@ -936,14 +946,14 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp) ...@@ -936,14 +946,14 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp)
devip = devInfoReg(sdp); devip = devInfoReg(sdp);
sdp->hostdata = devip; sdp->hostdata = devip;
if (sdp->host->cmd_per_lun) if (sdp->host->cmd_per_lun)
scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING, scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING,
sdp->host->cmd_per_lun); sdp->host->cmd_per_lun);
return 0; return 0;
} }
static void scsi_debug_slave_destroy(struct scsi_device * sdp) static void scsi_debug_slave_destroy(struct scsi_device * sdp)
{ {
struct sdebug_dev_info * devip = struct sdebug_dev_info * devip =
(struct sdebug_dev_info *)sdp->hostdata; (struct sdebug_dev_info *)sdp->hostdata;
if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
...@@ -980,6 +990,18 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev) ...@@ -980,6 +990,18 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
open_devip = devip; open_devip = devip;
} }
} }
if (NULL == open_devip) { /* try and make a new one */
open_devip = kmalloc(sizeof(*open_devip),GFP_KERNEL);
if (NULL == open_devip) {
printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__);
return NULL;
}
memset(open_devip, 0, sizeof(*open_devip));
open_devip->sdbg_host = sdbg_host;
list_add_tail(&open_devip->dev_list,
&sdbg_host->dev_info_list);
}
if (open_devip) { if (open_devip) {
open_devip->channel = sdev->channel; open_devip->channel = sdev->channel;
open_devip->target = sdev->id; open_devip->target = sdev->id;
...@@ -994,7 +1016,7 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev) ...@@ -994,7 +1016,7 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
return NULL; return NULL;
} }
static void mk_sense_buffer(struct sdebug_dev_info * devip, int key, static void mk_sense_buffer(struct sdebug_dev_info * devip, int key,
int asc, int asq, int inbandLen) int asc, int asq, int inbandLen)
{ {
unsigned char * sbuff; unsigned char * sbuff;
...@@ -1029,7 +1051,7 @@ static int scsi_debug_biosparam(struct scsi_device *sdev, ...@@ -1029,7 +1051,7 @@ static int scsi_debug_biosparam(struct scsi_device *sdev,
printk(KERN_INFO "scsi_debug: biosparam\n"); printk(KERN_INFO "scsi_debug: biosparam\n");
buf = scsi_bios_ptable(bdev); buf = scsi_bios_ptable(bdev);
if (buf) { if (buf) {
res = scsi_partsize(buf, capacity, res = scsi_partsize(buf, capacity,
&info[2], &info[0], &info[1]); &info[2], &info[0], &info[1]);
kfree(buf); kfree(buf);
if (! res) if (! res)
...@@ -1138,7 +1160,7 @@ static void stop_all_queued(void) ...@@ -1138,7 +1160,7 @@ static void stop_all_queued(void)
} }
/* Initializes timers in queued array */ /* Initializes timers in queued array */
static void init_all_queued(void) static void __init init_all_queued(void)
{ {
unsigned long iflags; unsigned long iflags;
int k; int k;
...@@ -1154,11 +1176,61 @@ static void init_all_queued(void) ...@@ -1154,11 +1176,61 @@ static void init_all_queued(void)
spin_unlock_irqrestore(&queued_arr_lock, iflags); spin_unlock_irqrestore(&queued_arr_lock, iflags);
} }
static int schedule_resp(struct scsi_cmnd * cmnd, static void __init sdebug_build_parts(unsigned char * ramp)
{
struct partition * pp;
int starts[SDEBUG_MAX_PARTS + 2];
int sectors_per_part, num_sectors, k;
int heads_by_sects, start_sec, end_sec;
/* assume partition table already zeroed */
if ((scsi_debug_num_parts < 1) || (sdebug_store_size < 1048576))
return;
if (scsi_debug_num_parts > SDEBUG_MAX_PARTS) {
scsi_debug_num_parts = SDEBUG_MAX_PARTS;
printk(KERN_WARNING "scsi_debug:build_parts: reducing "
"partitions to %d\n", SDEBUG_MAX_PARTS);
}
num_sectors = (int)(sdebug_store_size / SECT_SIZE);
sectors_per_part = (num_sectors - sdebug_sectors_per)
/ scsi_debug_num_parts;
heads_by_sects = sdebug_heads * sdebug_sectors_per;
starts[0] = sdebug_sectors_per;
for (k = 1; k < scsi_debug_num_parts; ++k)
starts[k] = ((k * sectors_per_part) / heads_by_sects)
* heads_by_sects;
starts[scsi_debug_num_parts] = num_sectors;
starts[scsi_debug_num_parts + 1] = 0;
ramp[510] = 0x55; /* magic partition markings */
ramp[511] = 0xAA;
pp = (struct partition *)(ramp + 0x1be);
for (k = 0; starts[k + 1]; ++k, ++pp) {
start_sec = starts[k];
end_sec = starts[k + 1] - 1;
pp->boot_ind = 0;
pp->cyl = start_sec / heads_by_sects;
pp->head = (start_sec - (pp->cyl * heads_by_sects))
/ sdebug_sectors_per;
pp->sector = (start_sec % sdebug_sectors_per) + 1;
pp->end_cyl = end_sec / heads_by_sects;
pp->end_head = (end_sec - (pp->end_cyl * heads_by_sects))
/ sdebug_sectors_per;
pp->end_sector = (end_sec % sdebug_sectors_per) + 1;
pp->start_sect = start_sec;
pp->nr_sects = end_sec - start_sec + 1;
pp->sys_ind = 0x83; /* plain Linux partition */
}
}
static int schedule_resp(struct scsi_cmnd * cmnd,
struct sdebug_dev_info * devip, struct sdebug_dev_info * devip,
done_funct_t done, int scsi_result, int delta_jiff) done_funct_t done, int scsi_result, int delta_jiff)
{ {
int k, num; int k, num;
if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmnd) { if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmnd) {
printk(KERN_INFO "scsi_debug: cmd "); printk(KERN_INFO "scsi_debug: cmd ");
...@@ -1176,7 +1248,7 @@ static int schedule_resp(struct scsi_cmnd * cmnd, ...@@ -1176,7 +1248,7 @@ static int schedule_resp(struct scsi_cmnd * cmnd,
if (cmnd && devip) { if (cmnd && devip) {
/* simulate autosense by this driver */ /* simulate autosense by this driver */
if (SAM_STAT_CHECK_CONDITION == (scsi_result & 0xff)) if (SAM_STAT_CHECK_CONDITION == (scsi_result & 0xff))
memcpy(cmnd->sense_buffer, devip->sense_buff, memcpy(cmnd->sense_buffer, devip->sense_buff,
(SCSI_SENSE_BUFFERSIZE > SDEBUG_SENSE_LEN) ? (SCSI_SENSE_BUFFERSIZE > SDEBUG_SENSE_LEN) ?
SDEBUG_SENSE_LEN : SCSI_SENSE_BUFFERSIZE); SDEBUG_SENSE_LEN : SCSI_SENSE_BUFFERSIZE);
} }
...@@ -1219,38 +1291,43 @@ static int schedule_resp(struct scsi_cmnd * cmnd, ...@@ -1219,38 +1291,43 @@ static int schedule_resp(struct scsi_cmnd * cmnd,
/* Set 'perm' (4th argument) to 0 to disable module_param's definition /* Set 'perm' (4th argument) to 0 to disable module_param's definition
* of sysfs parameters (which module_param doesn't yet support). * of sysfs parameters (which module_param doesn't yet support).
* Sysfs parameters defined explicitly below. * Sysfs parameters defined explicitly below.
*/ */
module_param_named(num_tgts, scsi_debug_num_tgts, int, 0); module_param_named(add_host, scsi_debug_add_host, int, 0); /* perm=0644 */
module_param_named(max_luns, scsi_debug_max_luns, int, 0); module_param_named(delay, scsi_debug_delay, int, 0); /* perm=0644 */
module_param_named(scsi_level, scsi_debug_scsi_level, int, 0);
module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, 0); module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, 0);
module_param_named(opts, scsi_debug_opts, int, 0); /* perm=0644 */
module_param_named(every_nth, scsi_debug_every_nth, int, 0); module_param_named(every_nth, scsi_debug_every_nth, int, 0);
module_param_named(delay, scsi_debug_delay, int, 0); /* perm=0644 */ module_param_named(max_luns, scsi_debug_max_luns, int, 0);
module_param_named(add_host, scsi_debug_add_host, int, 0); /* perm=0644 */ module_param_named(num_parts, scsi_debug_num_parts, int, 0);
module_param_named(num_tgts, scsi_debug_num_tgts, int, 0);
module_param_named(opts, scsi_debug_opts, int, 0); /* perm=0644 */
module_param_named(ptype, scsi_debug_ptype, int, 0);
module_param_named(scsi_level, scsi_debug_scsi_level, int, 0);
MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert");
MODULE_DESCRIPTION("SCSI debug adapter driver"); MODULE_DESCRIPTION("SCSI debug adapter driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_VERSION(SCSI_DEBUG_VERSION);
MODULE_PARM_DESC(num_tgts, "number of SCSI targets per host to simulate"); MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)");
MODULE_PARM_DESC(max_luns, "number of SCSI LUNs per target to simulate"); MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)");
MODULE_PARM_DESC(scsi_level, "SCSI level to simulate");
MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs"); MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs");
MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->...");
MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)"); MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)");
MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)"); MODULE_PARM_DESC(max_luns, "number of SCSI LUNs per target to simulate");
MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)"); MODULE_PARM_DESC(num_parts, "number of partitions(def=0)");
MODULE_PARM_DESC(num_tgts, "number of SCSI targets per host to simulate");
MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->...");
MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
MODULE_PARM_DESC(scsi_level, "SCSI level to simulate");
static char sdebug_info[256]; static char sdebug_info[256];
static const char * scsi_debug_info(struct Scsi_Host * shp) static const char * scsi_debug_info(struct Scsi_Host * shp)
{ {
sprintf(sdebug_info, "scsi_debug, %s, num_tgts=%d, " sprintf(sdebug_info, "scsi_debug, version %s [%s], "
"dev_size_mb=%d, opts=0x%x", scsi_debug_version_str, "dev_size_mb=%d, opts=0x%x", SCSI_DEBUG_VERSION,
scsi_debug_num_tgts, scsi_debug_dev_size_mb, scsi_debug_version_date, scsi_debug_dev_size_mb,
scsi_debug_opts); scsi_debug_opts);
return sdebug_info; return sdebug_info;
} }
...@@ -1282,14 +1359,15 @@ static int scsi_debug_proc_info(struct Scsi_Host *host, char *buffer, char **sta ...@@ -1282,14 +1359,15 @@ static int scsi_debug_proc_info(struct Scsi_Host *host, char *buffer, char **sta
return length; return length;
} }
begin = 0; begin = 0;
pos = len = sprintf(buffer, "scsi_debug adapter driver, %s\n" pos = len = sprintf(buffer, "scsi_debug adapter driver, version "
"%s [%s]\n"
"num_tgts=%d, shared (ram) size=%d MB, opts=0x%x, " "num_tgts=%d, shared (ram) size=%d MB, opts=0x%x, "
"every_nth=%d(curr:%d)\n" "every_nth=%d(curr:%d)\n"
"delay=%d, max_luns=%d, scsi_level=%d\n" "delay=%d, max_luns=%d, scsi_level=%d\n"
"sector_size=%d bytes, cylinders=%d, heads=%d, sectors=%d\n" "sector_size=%d bytes, cylinders=%d, heads=%d, sectors=%d\n"
"number of aborts=%d, device_reset=%d, bus_resets=%d, " "number of aborts=%d, device_reset=%d, bus_resets=%d, "
"host_resets=%d\n", "host_resets=%d\n",
scsi_debug_version_str, scsi_debug_num_tgts, SCSI_DEBUG_VERSION, scsi_debug_version_date, scsi_debug_num_tgts,
scsi_debug_dev_size_mb, scsi_debug_opts, scsi_debug_every_nth, scsi_debug_dev_size_mb, scsi_debug_opts, scsi_debug_every_nth,
scsi_debug_cmnd_count, scsi_debug_delay, scsi_debug_cmnd_count, scsi_debug_delay,
scsi_debug_max_luns, scsi_debug_scsi_level, scsi_debug_max_luns, scsi_debug_scsi_level,
...@@ -1306,12 +1384,12 @@ static int scsi_debug_proc_info(struct Scsi_Host *host, char *buffer, char **sta ...@@ -1306,12 +1384,12 @@ static int scsi_debug_proc_info(struct Scsi_Host *host, char *buffer, char **sta
return len; return len;
} }
static ssize_t sdebug_delay_show(struct device_driver * ddp, char * buf) static ssize_t sdebug_delay_show(struct device_driver * ddp, char * buf)
{ {
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_delay); return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_delay);
} }
static ssize_t sdebug_delay_store(struct device_driver * ddp, static ssize_t sdebug_delay_store(struct device_driver * ddp,
const char * buf, size_t count) const char * buf, size_t count)
{ {
int delay; int delay;
...@@ -1325,15 +1403,15 @@ static ssize_t sdebug_delay_store(struct device_driver * ddp, ...@@ -1325,15 +1403,15 @@ static ssize_t sdebug_delay_store(struct device_driver * ddp,
} }
return -EINVAL; return -EINVAL;
} }
DRIVER_ATTR(delay, S_IRUGO | S_IWUSR, sdebug_delay_show, DRIVER_ATTR(delay, S_IRUGO | S_IWUSR, sdebug_delay_show,
sdebug_delay_store) sdebug_delay_store)
static ssize_t sdebug_opts_show(struct device_driver * ddp, char * buf) static ssize_t sdebug_opts_show(struct device_driver * ddp, char * buf)
{ {
return scnprintf(buf, PAGE_SIZE, "0x%x\n", scsi_debug_opts); return scnprintf(buf, PAGE_SIZE, "0x%x\n", scsi_debug_opts);
} }
static ssize_t sdebug_opts_store(struct device_driver * ddp, static ssize_t sdebug_opts_store(struct device_driver * ddp,
const char * buf, size_t count) const char * buf, size_t count)
{ {
int opts; int opts;
...@@ -1354,38 +1432,62 @@ static ssize_t sdebug_opts_store(struct device_driver * ddp, ...@@ -1354,38 +1432,62 @@ static ssize_t sdebug_opts_store(struct device_driver * ddp,
scsi_debug_cmnd_count = 0; scsi_debug_cmnd_count = 0;
return count; return count;
} }
DRIVER_ATTR(opts, S_IRUGO | S_IWUSR, sdebug_opts_show, DRIVER_ATTR(opts, S_IRUGO | S_IWUSR, sdebug_opts_show,
sdebug_opts_store) sdebug_opts_store)
static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf) static ssize_t sdebug_ptype_show(struct device_driver * ddp, char * buf)
{
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_ptype);
}
static ssize_t sdebug_ptype_store(struct device_driver * ddp,
const char * buf, size_t count)
{
int n;
if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
scsi_debug_ptype = n;
return count;
}
return -EINVAL;
}
DRIVER_ATTR(ptype, S_IRUGO | S_IWUSR, sdebug_ptype_show, sdebug_ptype_store)
static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf)
{ {
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts);
} }
static ssize_t sdebug_num_tgts_store(struct device_driver * ddp, static ssize_t sdebug_num_tgts_store(struct device_driver * ddp,
const char * buf, size_t count) const char * buf, size_t count)
{ {
int n; int n;
if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
scsi_debug_num_tgts = n; scsi_debug_num_tgts = n;
sdebug_max_tgts_luns();
return count; return count;
} }
return -EINVAL; return -EINVAL;
} }
DRIVER_ATTR(num_tgts, S_IRUGO | S_IWUSR, sdebug_num_tgts_show, DRIVER_ATTR(num_tgts, S_IRUGO | S_IWUSR, sdebug_num_tgts_show,
sdebug_num_tgts_store) sdebug_num_tgts_store)
static ssize_t sdebug_dev_size_mb_show(struct device_driver * ddp, char * buf) static ssize_t sdebug_dev_size_mb_show(struct device_driver * ddp, char * buf)
{ {
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dev_size_mb); return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dev_size_mb);
} }
DRIVER_ATTR(dev_size_mb, S_IRUGO, sdebug_dev_size_mb_show, NULL) DRIVER_ATTR(dev_size_mb, S_IRUGO, sdebug_dev_size_mb_show, NULL)
static ssize_t sdebug_num_parts_show(struct device_driver * ddp, char * buf)
{
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_parts);
}
DRIVER_ATTR(num_parts, S_IRUGO, sdebug_num_parts_show, NULL)
static ssize_t sdebug_every_nth_show(struct device_driver * ddp, char * buf) static ssize_t sdebug_every_nth_show(struct device_driver * ddp, char * buf)
{ {
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_every_nth); return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_every_nth);
} }
static ssize_t sdebug_every_nth_store(struct device_driver * ddp, static ssize_t sdebug_every_nth_store(struct device_driver * ddp,
const char * buf, size_t count) const char * buf, size_t count)
{ {
int nth; int nth;
...@@ -1398,38 +1500,39 @@ static ssize_t sdebug_every_nth_store(struct device_driver * ddp, ...@@ -1398,38 +1500,39 @@ static ssize_t sdebug_every_nth_store(struct device_driver * ddp,
return -EINVAL; return -EINVAL;
} }
DRIVER_ATTR(every_nth, S_IRUGO | S_IWUSR, sdebug_every_nth_show, DRIVER_ATTR(every_nth, S_IRUGO | S_IWUSR, sdebug_every_nth_show,
sdebug_every_nth_store) sdebug_every_nth_store)
static ssize_t sdebug_max_luns_show(struct device_driver * ddp, char * buf) static ssize_t sdebug_max_luns_show(struct device_driver * ddp, char * buf)
{ {
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_luns); return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_luns);
} }
static ssize_t sdebug_max_luns_store(struct device_driver * ddp, static ssize_t sdebug_max_luns_store(struct device_driver * ddp,
const char * buf, size_t count) const char * buf, size_t count)
{ {
int n; int n;
if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
scsi_debug_max_luns = n; scsi_debug_max_luns = n;
sdebug_max_tgts_luns();
return count; return count;
} }
return -EINVAL; return -EINVAL;
} }
DRIVER_ATTR(max_luns, S_IRUGO | S_IWUSR, sdebug_max_luns_show, DRIVER_ATTR(max_luns, S_IRUGO | S_IWUSR, sdebug_max_luns_show,
sdebug_max_luns_store) sdebug_max_luns_store)
static ssize_t sdebug_scsi_level_show(struct device_driver * ddp, char * buf) static ssize_t sdebug_scsi_level_show(struct device_driver * ddp, char * buf)
{ {
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_scsi_level); return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_scsi_level);
} }
DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL) DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL)
static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf) static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf)
{ {
return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host);
} }
static ssize_t sdebug_add_host_store(struct device_driver * ddp, static ssize_t sdebug_add_host_store(struct device_driver * ddp,
const char * buf, size_t count) const char * buf, size_t count)
{ {
int delta_hosts; int delta_hosts;
...@@ -1463,26 +1566,30 @@ DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show, ...@@ -1463,26 +1566,30 @@ DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show,
static void do_create_driverfs_files(void) static void do_create_driverfs_files(void)
{ {
driver_create_file(&sdebug_driverfs_driver, &driver_attr_add_host);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_delay); driver_create_file(&sdebug_driverfs_driver, &driver_attr_delay);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); driver_create_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_every_nth); driver_create_file(&sdebug_driverfs_driver, &driver_attr_every_nth);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_max_luns); driver_create_file(&sdebug_driverfs_driver, &driver_attr_max_luns);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_parts);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_ptype);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level);
driver_create_file(&sdebug_driverfs_driver, &driver_attr_add_host);
} }
static void do_remove_driverfs_files(void) static void do_remove_driverfs_files(void)
{ {
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_add_host);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_scsi_level);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_opts);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_ptype);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_parts);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_tgts);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_max_luns); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_max_luns);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_every_nth); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_every_nth);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_tgts);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_opts);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_delay); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_delay);
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_add_host);
} }
static int __init scsi_debug_init(void) static int __init scsi_debug_init(void)
...@@ -1491,23 +1598,25 @@ static int __init scsi_debug_init(void) ...@@ -1491,23 +1598,25 @@ static int __init scsi_debug_init(void)
int host_to_add; int host_to_add;
int k; int k;
if (scsi_debug_dev_size_mb < 1)
scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
sdebug_store_size = (unsigned long)scsi_debug_dev_size_mb * 1048576; sdebug_store_size = (unsigned long)scsi_debug_dev_size_mb * 1048576;
sdebug_capacity = sdebug_store_size / SECT_SIZE; sdebug_capacity = sdebug_store_size / SECT_SIZE;
/* play around with geometry, don't waste too much on track 0 */ /* play around with geometry, don't waste too much on track 0 */
sdebug_heads = 8; sdebug_heads = 8;
sdebug_sectors_per = 32; sdebug_sectors_per = 32;
if (scsi_debug_dev_size_mb >= 16) if (scsi_debug_dev_size_mb >= 16)
sdebug_heads = 32; sdebug_heads = 32;
else if (scsi_debug_dev_size_mb >= 256) else if (scsi_debug_dev_size_mb >= 256)
sdebug_heads = 64; sdebug_heads = 64;
sdebug_cylinders_per = (unsigned long)sdebug_capacity / sdebug_cylinders_per = (unsigned long)sdebug_capacity /
(sdebug_sectors_per * sdebug_heads); (sdebug_sectors_per * sdebug_heads);
if (sdebug_cylinders_per >= 1024) { if (sdebug_cylinders_per >= 1024) {
/* other LLDs do this; implies >= 1GB ram disk ... */ /* other LLDs do this; implies >= 1GB ram disk ... */
sdebug_heads = 255; sdebug_heads = 255;
sdebug_sectors_per = 63; sdebug_sectors_per = 63;
sdebug_cylinders_per = (unsigned long)sdebug_capacity / sdebug_cylinders_per = (unsigned long)sdebug_capacity /
(sdebug_sectors_per * sdebug_heads); (sdebug_sectors_per * sdebug_heads);
} }
...@@ -1518,6 +1627,8 @@ static int __init scsi_debug_init(void) ...@@ -1518,6 +1627,8 @@ static int __init scsi_debug_init(void)
return -ENOMEM; return -ENOMEM;
} }
memset(fake_storep, 0, sz); memset(fake_storep, 0, sz);
if (scsi_debug_num_parts > 0)
sdebug_build_parts(fake_storep);
init_all_queued(); init_all_queued();
...@@ -1575,7 +1686,7 @@ static struct device pseudo_primary = { ...@@ -1575,7 +1686,7 @@ static struct device pseudo_primary = {
.release = pseudo_0_release, .release = pseudo_0_release,
}; };
static int pseudo_lld_bus_match(struct device *dev, static int pseudo_lld_bus_match(struct device *dev,
struct device_driver *dev_driver) struct device_driver *dev_driver)
{ {
return 1; return 1;
...@@ -1737,3 +1848,21 @@ static int sdebug_driver_remove(struct device * dev) ...@@ -1737,3 +1848,21 @@ static int sdebug_driver_remove(struct device * dev)
scsi_host_put(sdbg_host->shost); scsi_host_put(sdbg_host->shost);
return 0; return 0;
} }
static void sdebug_max_tgts_luns(void)
{
struct sdebug_host_info * sdbg_host;
struct Scsi_Host *hpnt;
spin_lock(&sdebug_host_list_lock);
list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
hpnt = sdbg_host->shost;
if ((hpnt->this_id >= 0) &&
(scsi_debug_num_tgts > hpnt->this_id))
hpnt->max_id = scsi_debug_num_tgts + 1;
else
hpnt->max_id = scsi_debug_num_tgts;
hpnt->max_lun = scsi_debug_max_luns;
}
spin_unlock(&sdebug_host_list_lock);
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
static int scsi_debug_slave_alloc(struct scsi_device *); static int scsi_debug_slave_alloc(struct scsi_device *);
static int scsi_debug_slave_configure(struct scsi_device *); static int scsi_debug_slave_configure(struct scsi_device *);
static void scsi_debug_slave_destroy(struct scsi_device *); static void scsi_debug_slave_destroy(struct scsi_device *);
static int scsi_debug_queuecommand(struct scsi_cmnd *, static int scsi_debug_queuecommand(struct scsi_cmnd *,
void (*done) (struct scsi_cmnd *)); void (*done) (struct scsi_cmnd *));
static int scsi_debug_ioctl(struct scsi_device *, int, void *); static int scsi_debug_ioctl(struct scsi_device *, int, void *);
static int scsi_debug_biosparam(struct scsi_device *, struct block_device *, static int scsi_debug_biosparam(struct scsi_device *, struct block_device *,
...@@ -17,9 +17,6 @@ static int scsi_debug_host_reset(struct scsi_cmnd *); ...@@ -17,9 +17,6 @@ static int scsi_debug_host_reset(struct scsi_cmnd *);
static int scsi_debug_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int); static int scsi_debug_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
static const char * scsi_debug_info(struct Scsi_Host *); static const char * scsi_debug_info(struct Scsi_Host *);
/*
* This driver is written for the lk 2.5 series
*/
#define SCSI_DEBUG_CANQUEUE 255 /* needs to be >= 1 */ #define SCSI_DEBUG_CANQUEUE 255 /* needs to be >= 1 */
#define SCSI_DEBUG_MAX_CMD_LEN 16 #define SCSI_DEBUG_MAX_CMD_LEN 16
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment