Commit 384cce6d authored by James Bottomley's avatar James Bottomley

Merge raven.il.steeleye.com:/home/jejb/BK/scsi-misc-2.5

into raven.il.steeleye.com:/home/jejb/BK/scsi-for-linus-2.5
parents bda2dabe 39beef0b
...@@ -679,27 +679,26 @@ static int aac_cfg_ioctl(struct inode * inode, struct file * file, unsigned int ...@@ -679,27 +679,26 @@ static int aac_cfg_ioctl(struct inode * inode, struct file * file, unsigned int
*/ */
static Scsi_Host_Template driver_template = { static Scsi_Host_Template driver_template = {
module: THIS_MODULE, .module = THIS_MODULE,
name: "AAC", .name = "AAC",
proc_info: aac_procinfo, .proc_info = aac_procinfo,
detect: aac_detect, .detect = aac_detect,
release: aac_release, .release = aac_release,
info: aac_driverinfo, .info = aac_driverinfo,
ioctl: aac_ioctl, .ioctl = aac_ioctl,
queuecommand: aac_queuecommand, .queuecommand = aac_queuecommand,
bios_param: aac_biosparm, .bios_param = aac_biosparm,
slave_configure: aac_slave_configure, .slave_configure = aac_slave_configure,
can_queue: AAC_NUM_IO_FIB, .can_queue = AAC_NUM_IO_FIB,
this_id: 16, .this_id = 16,
sg_tablesize: 16, .sg_tablesize = 16,
max_sectors: 128, .max_sectors = 128,
cmd_per_lun: AAC_NUM_IO_FIB, .cmd_per_lun = 1,
eh_abort_handler: aac_eh_abort, .eh_abort_handler = aac_eh_abort,
eh_device_reset_handler:aac_eh_device_reset, .eh_device_reset_handler = aac_eh_device_reset,
eh_bus_reset_handler: aac_eh_bus_reset, .eh_bus_reset_handler = aac_eh_bus_reset,
eh_host_reset_handler: aac_eh_reset, .eh_host_reset_handler = aac_eh_reset,
.use_clustering = ENABLE_CLUSTERING,
use_clustering: ENABLE_CLUSTERING,
}; };
#include "scsi_module.c" #include "scsi_module.c"
......
...@@ -549,6 +549,7 @@ struct Scsi_Device_Template ...@@ -549,6 +549,7 @@ struct Scsi_Device_Template
void (*detach)(Scsi_Device *); void (*detach)(Scsi_Device *);
int (*init_command)(Scsi_Cmnd *); /* Used by new queueing code. int (*init_command)(Scsi_Cmnd *); /* Used by new queueing code.
Selects command for blkdevs */ Selects command for blkdevs */
void (*rescan)(Scsi_Device *);
struct device_driver scsi_driverfs_driver; struct device_driver scsi_driverfs_driver;
}; };
......
...@@ -606,7 +606,7 @@ static int osst_wait_ready(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsigned ...@@ -606,7 +606,7 @@ static int osst_wait_ready(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsigned
{ {
unsigned char cmd[MAX_COMMAND_SIZE]; unsigned char cmd[MAX_COMMAND_SIZE];
Scsi_Request * SRpnt; Scsi_Request * SRpnt;
long startwait = jiffies; unsigned long startwait = jiffies;
#if DEBUG #if DEBUG
int dbg = debugging; int dbg = debugging;
char * name = tape_name(STp); char * name = tape_name(STp);
...@@ -673,7 +673,7 @@ static int osst_wait_for_medium(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsi ...@@ -673,7 +673,7 @@ static int osst_wait_for_medium(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsi
{ {
unsigned char cmd[MAX_COMMAND_SIZE]; unsigned char cmd[MAX_COMMAND_SIZE];
Scsi_Request * SRpnt; Scsi_Request * SRpnt;
long startwait = jiffies; unsigned long startwait = jiffies;
#if DEBUG #if DEBUG
int dbg = debugging; int dbg = debugging;
char * name = tape_name(STp); char * name = tape_name(STp);
...@@ -777,7 +777,7 @@ static int osst_flush_drive_buffer(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) ...@@ -777,7 +777,7 @@ static int osst_flush_drive_buffer(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
#define OSST_POLL_PER_SEC 10 #define OSST_POLL_PER_SEC 10
static int osst_wait_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int curr, int minlast, int to) static int osst_wait_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int curr, int minlast, int to)
{ {
long startwait = jiffies; unsigned long startwait = jiffies;
char * name = tape_name(STp); char * name = tape_name(STp);
#if DEBUG #if DEBUG
char notyetprinted = 1; char notyetprinted = 1;
...@@ -1288,7 +1288,7 @@ static int osst_read_back_buffer_and_rewrite(OS_Scsi_Tape * STp, Scsi_Request ** ...@@ -1288,7 +1288,7 @@ static int osst_read_back_buffer_and_rewrite(OS_Scsi_Tape * STp, Scsi_Request **
int logical_blk_num = ntohl(STp->buffer->aux->logical_blk_num) int logical_blk_num = ntohl(STp->buffer->aux->logical_blk_num)
- (nframes + pending - 1) * blks_per_frame; - (nframes + pending - 1) * blks_per_frame;
char * name = tape_name(STp); char * name = tape_name(STp);
long startwait = jiffies; unsigned long startwait = jiffies;
#if DEBUG #if DEBUG
int dbg = debugging; int dbg = debugging;
#endif #endif
...@@ -1477,7 +1477,7 @@ static int osst_reposition_and_retry(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, ...@@ -1477,7 +1477,7 @@ static int osst_reposition_and_retry(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt,
int expected = 0; int expected = 0;
int attempts = 1000 / skip; int attempts = 1000 / skip;
int flag = 1; int flag = 1;
long startwait = jiffies; unsigned long startwait = jiffies;
#if DEBUG #if DEBUG
int dbg = debugging; int dbg = debugging;
#endif #endif
......
...@@ -836,14 +836,22 @@ static int isp2x00_make_portdb(struct Scsi_Host *host) ...@@ -836,14 +836,22 @@ static int isp2x00_make_portdb(struct Scsi_Host *host)
short param[8]; short param[8];
int i, j; int i, j;
struct id_name_map temp[QLOGICFC_MAX_ID + 1]; struct id_name_map *map; /* base of array [QLOGICFC_MAX_ID + 1] */
struct id_name_map *mapx; /* array entry pointer */
struct isp2x00_hostdata *hostdata; struct isp2x00_hostdata *hostdata;
isp2x00_disable_irqs(host);
memset(temp, 0, sizeof(temp));
hostdata = (struct isp2x00_hostdata *) host->hostdata; hostdata = (struct isp2x00_hostdata *) host->hostdata;
map = kmalloc((QLOGICFC_MAX_ID + 1) * sizeof(struct id_name_map), GFP_ATOMIC);
if (!map) {
printk("qlogicfc%d : error getting memory -- cannot make port database.\n",
hostdata->host_id);
goto fini;
}
memset(map, 0, (QLOGICFC_MAX_ID + 1) * sizeof(struct id_name_map));
isp2x00_disable_irqs(host);
#if ISP2x00_FABRIC #if ISP2x00_FABRIC
for (i = 0x81; i < QLOGICFC_MAX_ID; i++) { for (i = 0x81; i < QLOGICFC_MAX_ID; i++) {
param[0] = MBOX_PORT_LOGOUT; param[0] = MBOX_PORT_LOGOUT;
...@@ -868,72 +876,74 @@ static int isp2x00_make_portdb(struct Scsi_Host *host) ...@@ -868,72 +876,74 @@ static int isp2x00_make_portdb(struct Scsi_Host *host)
if (param[0] == MBOX_COMMAND_COMPLETE) { if (param[0] == MBOX_COMMAND_COMPLETE) {
hostdata->port_id = ((u_int) param[3]) << 16; hostdata->port_id = ((u_int) param[3]) << 16;
hostdata->port_id |= param[2]; hostdata->port_id |= param[2];
temp[0].loop_id = param[1]; map->loop_id = param[1];
temp[0].wwn = hostdata->wwn; map->wwn = hostdata->wwn;
} }
else { else {
printk("qlogicfc%d : error getting scsi id.\n", hostdata->host_id); printk("qlogicfc%d : error getting scsi id.\n", hostdata->host_id);
} }
for (i = 0; i <=QLOGICFC_MAX_ID; i++) for (i = 0, mapx = map; i <= QLOGICFC_MAX_ID; i++, mapx++)
temp[i].loop_id = temp[0].loop_id; mapx->loop_id = map->loop_id;
for (i = 0, j = 1; i <= QLOGICFC_MAX_LOOP_ID; i++) { for (i = 0, j = 1, mapx = map + 1; i <= QLOGICFC_MAX_LOOP_ID; i++) {
param[0] = MBOX_GET_PORT_NAME; param[0] = MBOX_GET_PORT_NAME;
param[1] = (i << 8) & 0xff00; param[1] = (i << 8) & 0xff00;
isp2x00_mbox_command(host, param); isp2x00_mbox_command(host, param);
if (param[0] == MBOX_COMMAND_COMPLETE) { if (param[0] == MBOX_COMMAND_COMPLETE) {
temp[j].loop_id = i; mapx->loop_id = i;
temp[j].wwn = ((u64) (param[2] & 0xff)) << 56; mapx->wwn = ((u64) (param[2] & 0xff)) << 56;
temp[j].wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48; mapx->wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48;
temp[j].wwn |= ((u64) (param[3] & 0xff)) << 40; mapx->wwn |= ((u64) (param[3] & 0xff)) << 40;
temp[j].wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32; mapx->wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32;
temp[j].wwn |= ((u64) (param[6] & 0xff)) << 24; mapx->wwn |= ((u64) (param[6] & 0xff)) << 24;
temp[j].wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16; mapx->wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16;
temp[j].wwn |= ((u64) (param[7] & 0xff)) << 8; mapx->wwn |= ((u64) (param[7] & 0xff)) << 8;
temp[j].wwn |= ((u64) ((param[7] >> 8) & 0xff)); mapx->wwn |= ((u64) ((param[7] >> 8) & 0xff));
j++; j++;
mapx++;
} }
} }
#if ISP2x00_FABRIC #if ISP2x00_FABRIC
isp2x00_init_fabric(host, temp, j); isp2x00_init_fabric(host, map, j);
#endif #endif
for (i = 0; i <= QLOGICFC_MAX_ID; i++) { for (i = 0, mapx = map; i <= QLOGICFC_MAX_ID; i++, mapx++) {
if (temp[i].wwn != hostdata->port_db[i].wwn) { struct id_name_map *tmap; /* second array entry pointer */
for (j = 0; j <= QLOGICFC_MAX_ID; j++) { if (mapx->wwn != hostdata->port_db[i].wwn) {
if (temp[j].wwn == hostdata->port_db[i].wwn) { for (j = 0, tmap = map; j <= QLOGICFC_MAX_ID; j++, tmap++) {
hostdata->port_db[i].loop_id = temp[j].loop_id; if (tmap->wwn == hostdata->port_db[i].wwn) {
hostdata->port_db[i].loop_id = tmap->loop_id;
break; break;
} }
} }
if (j == QLOGICFC_MAX_ID + 1) if (j == QLOGICFC_MAX_ID + 1)
hostdata->port_db[i].loop_id = temp[0].loop_id; hostdata->port_db[i].loop_id = map->loop_id;
for (j = 0; j <= QLOGICFC_MAX_ID; j++) { for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
if (hostdata->port_db[j].wwn == temp[i].wwn || !hostdata->port_db[j].wwn) { if (hostdata->port_db[j].wwn == mapx->wwn || !hostdata->port_db[j].wwn) {
break; break;
} }
} }
if (j == QLOGICFC_MAX_ID + 1) if (j == QLOGICFC_MAX_ID + 1)
printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata->host_id); printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata->host_id);
if (!hostdata->port_db[j].wwn) { if (!hostdata->port_db[j].wwn) {
hostdata->port_db[j].loop_id = temp[i].loop_id; hostdata->port_db[j].loop_id = mapx->loop_id;
hostdata->port_db[j].wwn = temp[i].wwn; hostdata->port_db[j].wwn = mapx->wwn;
} }
} else } else
hostdata->port_db[i].loop_id = temp[i].loop_id; hostdata->port_db[i].loop_id = mapx->loop_id;
} }
isp2x00_enable_irqs(host); isp2x00_enable_irqs(host);
kfree(map);
fini:
return 0; return 0;
} }
......
...@@ -96,12 +96,7 @@ unsigned long scsi_pid; ...@@ -96,12 +96,7 @@ unsigned long scsi_pid;
Scsi_Cmnd *last_cmnd; Scsi_Cmnd *last_cmnd;
static unsigned long serial_number; static unsigned long serial_number;
struct softscsi_data { static struct list_head done_q[NR_CPUS] __cacheline_aligned;
Scsi_Cmnd *head;
Scsi_Cmnd *tail;
};
static struct softscsi_data softscsi_data[NR_CPUS] __cacheline_aligned;
/* /*
* List of all highlevel drivers. * List of all highlevel drivers.
...@@ -637,79 +632,60 @@ void scsi_init_cmd_from_req(Scsi_Cmnd * SCpnt, Scsi_Request * SRpnt) ...@@ -637,79 +632,60 @@ void scsi_init_cmd_from_req(Scsi_Cmnd * SCpnt, Scsi_Request * SRpnt)
} }
/** /**
* scsi_done - Mark this command as done * scsi_done - Enqueue the finished SCSI command into the done queue.
* @SCpnt: The SCSI Command which we think we've completed. * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives
* * ownership back to SCSI Core -- i.e. the LLDD has finished with it.
* This function is the mid-level interrupt routine, which decides how
* to handle error conditions. Each invocation of this function must
* do one and *only* one of the following:
* *
* 1) Insert command in BH queue. * This function is the mid-level's (SCSI Core) interrupt routine, which
* 2) Activate error handler for host. * regains ownership of the SCSI command (de facto) from a LLDD, and enqueues
* the command to the done queue for further processing.
* *
* There is no longer a problem with stack overflow. Interrupts queue * This is the producer of the done queue who enqueues at the tail.
* Scsi_Cmnd on a per-CPU queue and the softirq handler removes them
* from the queue one at a time.
* *
* This function is sometimes called from interrupt context, but sometimes * This function is interrupt context safe.
* from task context.
*/ */
void scsi_done(Scsi_Cmnd * SCpnt) void scsi_done(struct scsi_cmnd *cmd)
{ {
int cpu;
unsigned long flags; unsigned long flags;
int cpu, tstatus; struct list_head *pdone_q;
struct softscsi_data *queue;
/* /*
* We don't have to worry about this one timing out any more. * We don't have to worry about this one timing out any more.
*/ * If we are unable to remove the timer, then the command
tstatus = scsi_delete_timer(SCpnt); * has already timed out. In which case, we have no choice but to
/*
* If we are unable to remove the timer, it means that the command
* has already timed out. In this case, we have no choice but to
* let the timeout function run, as we have no idea where in fact * let the timeout function run, as we have no idea where in fact
* that function could really be. It might be on another processor, * that function could really be. It might be on another processor,
* etc, etc. * etc, etc.
*/ */
if (!tstatus) { if (!scsi_delete_timer(cmd))
return; return;
}
/* Set the serial numbers back to zero */ /* Set the serial numbers back to zero */
SCpnt->serial_number = 0; cmd->serial_number = 0;
SCpnt->serial_number_at_timeout = 0; cmd->serial_number_at_timeout = 0;
SCpnt->state = SCSI_STATE_BHQUEUE; cmd->state = SCSI_STATE_BHQUEUE;
SCpnt->owner = SCSI_OWNER_BH_HANDLER; cmd->owner = SCSI_OWNER_BH_HANDLER;
SCpnt->bh_next = NULL;
/* /*
* Next, put this command in the softirq queue. * Next, enqueue the command into the done queue.
* * It is a per-CPU queue, so we just disable local interrupts
* This is a per-CPU queue, so we just disable local interrupts
* and need no spinlock. * and need no spinlock.
*/ */
local_irq_save(flags); local_irq_save(flags);
cpu = smp_processor_id(); cpu = smp_processor_id();
queue = &softscsi_data[cpu]; pdone_q = &done_q[cpu];
list_add_tail(&cmd->eh_entry, pdone_q);
if (!queue->head) {
queue->head = SCpnt;
queue->tail = SCpnt;
} else {
queue->tail->bh_next = SCpnt;
queue->tail = SCpnt;
}
cpu_raise_softirq(cpu, SCSI_SOFTIRQ); cpu_raise_softirq(cpu, SCSI_SOFTIRQ);
local_irq_restore(flags); local_irq_restore(flags);
} }
/** /**
* scsi_softirq - Perform post-interrupt handling for completed commands * scsi_softirq - Perform post-interrupt processing of finished SCSI commands.
*
* This is the consumer of the done queue.
* *
* This is called with all interrupts enabled. This should reduce * This is called with all interrupts enabled. This should reduce
* interrupt latency, stack depth, and reentrancy of the low-level * interrupt latency, stack depth, and reentrancy of the low-level
...@@ -717,30 +693,30 @@ void scsi_done(Scsi_Cmnd * SCpnt) ...@@ -717,30 +693,30 @@ void scsi_done(Scsi_Cmnd * SCpnt)
*/ */
static void scsi_softirq(struct softirq_action *h) static void scsi_softirq(struct softirq_action *h)
{ {
int cpu = smp_processor_id(); LIST_HEAD(local_q);
struct softscsi_data *queue = &softscsi_data[cpu];
while (queue->head) {
Scsi_Cmnd *SCpnt, *SCnext;
local_irq_disable(); local_irq_disable();
SCpnt = queue->head; list_splice_init(&done_q[smp_processor_id()], &local_q);
queue->head = NULL;
local_irq_enable(); local_irq_enable();
for (; SCpnt; SCpnt = SCnext) { while (!list_empty(&local_q)) {
SCnext = SCpnt->bh_next; struct scsi_cmnd *cmd = list_entry(local_q.next,
struct scsi_cmnd, eh_entry);
list_del_init(&cmd->eh_entry);
switch (scsi_decide_disposition(SCpnt)) { switch (scsi_decide_disposition(cmd)) {
case SUCCESS: case SUCCESS:
/* /*
* Add to BH queue. * Add to BH queue.
*/ */
SCSI_LOG_MLCOMPLETE(3, printk("Command finished %d %d 0x%x\n", SCpnt->device->host->host_busy, SCSI_LOG_MLCOMPLETE(3,
SCpnt->device->host->host_failed, printk("Command finished %d %d "
SCpnt->result)); "0x%x\n",
cmd->device->host->host_busy,
cmd->device->host->host_failed,
cmd->result));
scsi_finish_command(SCpnt); scsi_finish_command(cmd);
break; break;
case NEEDS_RETRY: case NEEDS_RETRY:
/* /*
...@@ -750,10 +726,13 @@ static void scsi_softirq(struct softirq_action *h) ...@@ -750,10 +726,13 @@ static void scsi_softirq(struct softirq_action *h)
* track of the number of tries, so we don't * track of the number of tries, so we don't
* end up looping, of course. * end up looping, of course.
*/ */
SCSI_LOG_MLCOMPLETE(3, printk("Command needs retry %d %d 0x%x\n", SCpnt->device->host->host_busy, SCSI_LOG_MLCOMPLETE(3, printk("Command needs retry "
SCpnt->device->host->host_failed, SCpnt->result)); "%d %d 0x%x\n",
cmd->device->host->host_busy,
cmd->device->host->host_failed,
cmd->result));
scsi_retry_command(SCpnt); scsi_retry_command(cmd);
break; break;
case ADD_TO_MLQUEUE: case ADD_TO_MLQUEUE:
/* /*
...@@ -766,9 +745,11 @@ static void scsi_softirq(struct softirq_action *h) ...@@ -766,9 +745,11 @@ static void scsi_softirq(struct softirq_action *h)
* shouldn't end up with tons of things being * shouldn't end up with tons of things being
* sent down that shouldn't be. * sent down that shouldn't be.
*/ */
SCSI_LOG_MLCOMPLETE(3, printk("Command rejected as device queue full, put on ml queue %p\n", SCSI_LOG_MLCOMPLETE(3, printk("Command rejected as "
SCpnt)); "device queue full, "
scsi_queue_insert(SCpnt, SCSI_MLQUEUE_DEVICE_BUSY); "put on ml queue %p\n",
cmd));
scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
break; break;
default: default:
/* /*
...@@ -776,29 +757,28 @@ static void scsi_softirq(struct softirq_action *h) ...@@ -776,29 +757,28 @@ static void scsi_softirq(struct softirq_action *h)
* Turn it over to the error handler. * Turn it over to the error handler.
*/ */
SCSI_LOG_MLCOMPLETE(3, SCSI_LOG_MLCOMPLETE(3,
printk("Command failed %p %x busy=%d failed=%d\n", printk("Command failed %p %x "
SCpnt, SCpnt->result, "busy=%d failed=%d\n",
SCpnt->device->host->host_busy, cmd, cmd->result,
SCpnt->device->host->host_failed)); cmd->device->host->host_busy,
cmd->device->host->host_failed));
/* /*
* Dump the sense information too. * Dump the sense information too.
*/ */
if ((status_byte(SCpnt->result) & CHECK_CONDITION) != 0) { if ((status_byte(cmd->result)&CHECK_CONDITION) != 0) {
SCSI_LOG_MLCOMPLETE(3, print_sense("bh", SCpnt)); SCSI_LOG_MLCOMPLETE(3, print_sense("bh", cmd));
} }
if (!scsi_eh_scmd_add(SCpnt, 0)) if (!scsi_eh_scmd_add(cmd, 0)) {
{
/* /*
* We only get here if the error * We only get here if the error
* recovery thread has died. * recovery thread has died.
*/ */
scsi_finish_command(SCpnt); scsi_finish_command(cmd);
}
}
} }
} /* switch */
} /* for(; SCpnt...) */
} /* while(queue->head) */
} }
/* /*
...@@ -1284,6 +1264,21 @@ void scsi_detach_device(struct scsi_device *sdev) ...@@ -1284,6 +1264,21 @@ void scsi_detach_device(struct scsi_device *sdev)
up_read(&scsi_devicelist_mutex); up_read(&scsi_devicelist_mutex);
} }
void scsi_rescan_device(struct scsi_device *sdev)
{
struct Scsi_Device_Template *sdt;
down_read(&scsi_devicelist_mutex);
list_for_each_entry(sdt, &scsi_devicelist, list) {
if (!try_module_get(sdt->module))
continue;
if (*sdt->rescan)
(*sdt->rescan)(sdev);
module_put(sdt->module);
}
up_read(&scsi_devicelist_mutex);
}
int scsi_device_get(struct scsi_device *sdev) int scsi_device_get(struct scsi_device *sdev)
{ {
if (!try_module_get(sdev->host->hostt->module)) if (!try_module_get(sdev->host->hostt->module))
...@@ -1481,7 +1476,7 @@ __setup("scsi_default_dev_flags=", setup_scsi_default_dev_flags); ...@@ -1481,7 +1476,7 @@ __setup("scsi_default_dev_flags=", setup_scsi_default_dev_flags);
static int __init init_scsi(void) static int __init init_scsi(void)
{ {
int error; int error, i;
error = scsi_init_queue(); error = scsi_init_queue();
if (error) if (error)
...@@ -1496,6 +1491,9 @@ static int __init init_scsi(void) ...@@ -1496,6 +1491,9 @@ static int __init init_scsi(void)
if (error) if (error)
goto cleanup_devlist; goto cleanup_devlist;
for (i = 0; i < NR_CPUS; i++)
INIT_LIST_HEAD(&done_q[i]);
scsi_host_init(); scsi_host_init();
devfs_mk_dir(NULL, "scsi", NULL); devfs_mk_dir(NULL, "scsi", NULL);
open_softirq(SCSI_SOFTIRQ, scsi_softirq, NULL); open_softirq(SCSI_SOFTIRQ, scsi_softirq, NULL);
......
...@@ -741,8 +741,7 @@ struct scsi_cmnd { ...@@ -741,8 +741,7 @@ struct scsi_cmnd {
* abort, etc are in process. * abort, etc are in process.
*/ */
unsigned volatile char internal_timeout; unsigned volatile char internal_timeout;
struct scsi_cmnd *bh_next; /* To enumerate the commands waiting
to be processed. */
unsigned char cmd_len; unsigned char cmd_len;
unsigned char old_cmd_len; unsigned char old_cmd_len;
unsigned char sc_data_direction; unsigned char sc_data_direction;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* (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/sdebug.html * For documentation see http://www.torque.net/sg/sdebug25.html
* *
* D. Gilbert (dpg) work for Magneto-Optical device test [20010421] * D. Gilbert (dpg) work for Magneto-Optical device test [20010421]
* dpg: work for devfs large number of disks [20010809] * dpg: work for devfs large number of disks [20010809]
...@@ -54,38 +54,37 @@ ...@@ -54,38 +54,37 @@
#include "scsi_debug.h" #include "scsi_debug.h"
static const char * scsi_debug_version_str = "Version: 1.67 (20021221)"; static const char * scsi_debug_version_str = "Version: 1.68 (20030314)";
#ifndef SCSI_CMD_READ_16
#define SCSI_CMD_READ_16 0x88
#endif
#ifndef SCSI_CMD_WRITE_16
#define SCSI_CMD_WRITE_16 0x8a
#endif
#define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */ #define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */
/* Default values for driver parameters */ /* Default values for driver parameters */
#define DEF_NUM_DEVS 1 #define DEF_NUM_DEVS 1
#define DEF_DEV_SIZE_MB 8 #define DEF_DEV_SIZE_MB 8
#define DEF_EVERY_NTH 100 #define DEF_EVERY_NTH 0
#define DEF_DELAY 1 #define DEF_DELAY 1
#define DEF_MAX_LUNS 2 #define DEF_MAX_LUNS 2
#define DEF_SCSI_LEVEL 3 #define DEF_SCSI_LEVEL 3
#define DEF_NUM_HOST 1 #define DEF_NUM_HOST 1
#define DEF_OPTS 0 #define DEF_OPTS 0
#define MAX_NUM_HOSTS 128
/* 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
#define SCSI_DEBUG_OPT_MEDIUM_ERR 2 #define SCSI_DEBUG_OPT_MEDIUM_ERR 2
#define SCSI_DEBUG_OPT_EVERY_NTH 4 #define SCSI_DEBUG_OPT_TIMEOUT 4
#define SCSI_DEBUG_OPT_RECOVERED_ERR 8
/* When "every_nth" > 0 then modulo "every_nth" commands:
* - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set
* - a RECOVERED_ERROR is simulated on successful read and write
* commands if SCSI_DEBUG_OPT_RECOVERED_ERR is set.
*/
#define OPT_MEDIUM_ERR_ADDR 0x1234 /* when 1==SCSI_DEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this
* sector on read commands: */
#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */
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_devs = DEF_NUM_DEVS; static int scsi_debug_num_devs = DEF_NUM_DEVS; /* max devs per host */
static int scsi_debug_opts = DEF_OPTS; 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_cmnd_count = 0;
...@@ -112,25 +111,28 @@ static int sdebug_sectors_per; /* sectors per cylinder */ ...@@ -112,25 +111,28 @@ 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
struct sdebug_host_info {
struct Scsi_Host *shost;
struct device *dev;
};
struct sdebug_host_info * scsi_debug_hosts;
#define SDEBUG_SENSE_LEN 32 #define SDEBUG_SENSE_LEN 32
struct sdebug_dev_info { struct sdebug_dev_info {
struct list_head dev_list;
unsigned char sense_buff[SDEBUG_SENSE_LEN]; /* weak nexus */ unsigned char sense_buff[SDEBUG_SENSE_LEN]; /* weak nexus */
unsigned int channel; unsigned int channel;
unsigned int target; unsigned int target;
unsigned int lun; unsigned int lun;
struct Scsi_Host *host; struct sdebug_host_info *sdbg_host;
char reset; char reset;
char used; char used;
}; };
static struct sdebug_dev_info * devInfop;
struct sdebug_host_info {
struct list_head host_list;
struct Scsi_Host *shost;
struct device *dev;
struct list_head dev_info_list;
};
static LIST_HEAD(sdebug_host_list);
static spinlock_t sdebug_host_list_lock = SPIN_LOCK_UNLOCKED;
typedef void (* done_funct_t) (struct scsi_cmnd *); typedef void (* done_funct_t) (struct scsi_cmnd *);
...@@ -156,11 +158,20 @@ static spinlock_t queued_arr_lock = SPIN_LOCK_UNLOCKED; ...@@ -156,11 +158,20 @@ static spinlock_t queued_arr_lock = SPIN_LOCK_UNLOCKED;
static rwlock_t atomic_rw = RW_LOCK_UNLOCKED; static rwlock_t atomic_rw = RW_LOCK_UNLOCKED;
static char sdebug_proc_name[] = "scsi_debug"; static char sdebug_proc_name[] = "scsi_debug";
static int sdebug_driver_probe(struct device *);
static int sdebug_driver_remove(struct device *);
static struct device_driver sdebug_driverfs_driver = { static struct device_driver sdebug_driverfs_driver = {
.name = sdebug_proc_name, .name = sdebug_proc_name,
.probe = sdebug_driver_probe,
.remove = sdebug_driver_remove,
.devclass = &shost_devclass, .devclass = &shost_devclass,
}; };
static const int check_condition_result =
(DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
/* function declarations */ /* function declarations */
static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff, static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff,
int bufflen, struct sdebug_dev_info * devip); int bufflen, struct sdebug_dev_info * devip);
...@@ -174,7 +185,7 @@ static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, ...@@ -174,7 +185,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);
static void timer_intr_handler(unsigned long); static void timer_intr_handler(unsigned long);
static struct sdebug_dev_info * devInfoReg(struct scsi_cmnd *scmd); 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,
...@@ -189,15 +200,29 @@ static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, ...@@ -189,15 +200,29 @@ 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);
static void do_create_driverfs_files(void); static void do_create_driverfs_files(void);
static void do_remove_driverfs_files(void); static void do_remove_driverfs_files(void);
static void sdebug_add_shost(int num);
static void sdebug_remove_shost(int num);
static int sdebug_add_adapter(int num); static int sdebug_add_adapter(void);
static void sdebug_remove_adapter(int num); static void sdebug_remove_adapter(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;
int scsi_debug_register_driver(struct device_driver *); static int scsi_debug_register_driver(struct device_driver *);
int scsi_debug_unregister_driver(struct device_driver *); static int scsi_debug_unregister_driver(struct device_driver *);
static struct sdebug_host_info *
sdebug_shost_to_host_info(struct Scsi_Host *shost)
{
struct sdebug_host_info * sdbg_host, * found = NULL;
spin_lock(&sdebug_host_list_lock);
list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
if (sdbg_host->shost == shost) {
found = sdbg_host;
break;
}
}
spin_unlock(&sdebug_host_list_lock);
return found;
}
static unsigned char * scatg2virt(const struct scatterlist * sclp) static unsigned char * scatg2virt(const struct scatterlist * sclp)
{ {
...@@ -222,6 +247,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -222,6 +247,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
unsigned long capac; unsigned long capac;
struct sdebug_dev_info * devip = NULL; struct sdebug_dev_info * devip = NULL;
unsigned char * sbuff; unsigned char * sbuff;
int inj_recovered = 0;
if (done == NULL) if (done == NULL)
return 0; /* assume mid level reprocessing command */ return 0; /* assume mid level reprocessing command */
...@@ -250,16 +276,18 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -250,16 +276,18 @@ 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); 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_OPT_EVERY_NTH & scsi_debug_opts) && if ((scsi_debug_every_nth > 0) &&
(scsi_debug_every_nth > 0) &&
(++scsi_debug_cmnd_count >= scsi_debug_every_nth)) { (++scsi_debug_cmnd_count >= scsi_debug_every_nth)) {
scsi_debug_cmnd_count =0; scsi_debug_cmnd_count =0;
if (SCSI_DEBUG_OPT_TIMEOUT & scsi_debug_opts)
return 0; /* ignore command causing timeout */ return 0; /* ignore command causing timeout */
else if (SCSI_DEBUG_OPT_RECOVERED_ERR & scsi_debug_opts)
inj_recovered = 1; /* to reads and writes below */
} }
switch (*cmd) { switch (*cmd) {
...@@ -269,8 +297,8 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -269,8 +297,8 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
case REQUEST_SENSE: /* mandatory */ case REQUEST_SENSE: /* mandatory */
/* Since this driver indicates autosense by placing the /* Since this driver indicates autosense by placing the
* sense buffer in the scsi_cmnd structure in the response * sense buffer in the scsi_cmnd structure in the response
* (when CHECK_CONDITION is set), the mid level shouldn't * (when SAM_STAT_CHECK_CONDITION is set), the mid level
* 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) ?
...@@ -326,14 +354,14 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -326,14 +354,14 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
buff[7] = SECT_SIZE_PER(target) & 0xff; buff[7] = SECT_SIZE_PER(target) & 0xff;
} }
break; break;
case SCSI_CMD_READ_16: /* SBC-2 */ case READ_16:
case READ_12: case READ_12:
case READ_10: case READ_10:
case READ_6: case READ_6:
if ((errsts = check_reset(SCpnt, devip))) if ((errsts = check_reset(SCpnt, devip)))
break; break;
upper_blk = 0; upper_blk = 0;
if ((*cmd) == SCSI_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) +
...@@ -355,18 +383,22 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -355,18 +383,22 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
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)) {
mk_sense_buffer(devip, RECOVERED_ERROR, 0x5d, 0, 14);
errsts = check_condition_result;
}
break; break;
case REPORT_LUNS: case REPORT_LUNS:
errsts = resp_report_luns(cmd, buff, bufflen, devip); errsts = resp_report_luns(cmd, buff, bufflen, devip);
break; break;
case SCSI_CMD_WRITE_16: /* SBC-2 */ case WRITE_16:
case WRITE_12: case WRITE_12:
case WRITE_10: case WRITE_10:
case WRITE_6: case WRITE_6:
if ((errsts = check_reset(SCpnt, devip))) if ((errsts = check_reset(SCpnt, devip)))
break; break;
upper_blk = 0; upper_blk = 0;
if ((*cmd) == SCSI_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) +
...@@ -388,6 +420,10 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -388,6 +420,10 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
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)) {
mk_sense_buffer(devip, RECOVERED_ERROR, 0x5d, 0, 14);
errsts = check_condition_result;
}
break; break;
case MODE_SENSE: case MODE_SENSE:
case MODE_SENSE_10: case MODE_SENSE_10:
...@@ -400,7 +436,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) ...@@ -400,7 +436,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
if ((errsts = check_reset(SCpnt, devip))) if ((errsts = check_reset(SCpnt, devip)))
break; break;
mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x20, 0, 14); mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x20, 0, 14);
errsts = (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); errsts = check_condition_result;
break; break;
} }
return schedule_resp(SCpnt, devip, done, errsts, scsi_debug_delay); return schedule_resp(SCpnt, devip, done, errsts, scsi_debug_delay);
...@@ -420,7 +456,7 @@ static int check_reset(struct scsi_cmnd * SCpnt, struct sdebug_dev_info * devip) ...@@ -420,7 +456,7 @@ static int check_reset(struct scsi_cmnd * SCpnt, struct sdebug_dev_info * devip)
if (devip->reset) { if (devip->reset) {
devip->reset = 0; devip->reset = 0;
mk_sense_buffer(devip, UNIT_ATTENTION, 0x29, 0, 14); mk_sense_buffer(devip, UNIT_ATTENTION, 0x29, 0, 14);
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); return check_condition_result;
} }
return 0; return 0;
} }
...@@ -481,12 +517,12 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff, ...@@ -481,12 +517,12 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff,
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, 0x24, 0, 14); mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x24, 0, 14);
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); return check_condition_result;
} else if (0x1 & cmd[1]) { /* EVPD bit set */ } else if (0x1 & cmd[1]) { /* EVPD bit set */
int dev_id_num, len; int dev_id_num, len;
char dev_id_str[6]; char dev_id_str[6];
dev_id_num = ((devip->host->host_no + 1) * 2000) + dev_id_num = ((devip->sdbg_host->shost->host_no + 1) * 2000) +
(devip->target * 1000) + devip->lun; (devip->target * 1000) + devip->lun;
len = snprintf(dev_id_str, 6, "%d", dev_id_num); len = snprintf(dev_id_str, 6, "%d", dev_id_num);
len = (len > 6) ? 6 : len; len = (len > 6) ? 6 : len;
...@@ -506,7 +542,7 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff, ...@@ -506,7 +542,7 @@ static int resp_inquiry(unsigned char * cmd, int target, unsigned char * buff,
} else { } else {
/* Illegal request, invalid field in cdb */ /* Illegal request, invalid field in cdb */
mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x24, 0, 14); mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x24, 0, 14);
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); return check_condition_result;
} }
memcpy(buff, arr, min_len); memcpy(buff, arr, min_len);
return 0; return 0;
...@@ -619,7 +655,7 @@ static int resp_mode_sense(unsigned char * cmd, int target, ...@@ -619,7 +655,7 @@ static int resp_mode_sense(unsigned char * cmd, int target,
memset(arr, 0, SDEBUG_MAX_MSENSE_SZ); memset(arr, 0, SDEBUG_MAX_MSENSE_SZ);
if (0x3 == pcontrol) { /* Saving values not supported */ if (0x3 == pcontrol) { /* Saving values not supported */
mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x39, 0, 14); mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x39, 0, 14);
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); return check_condition_result;
} }
dev_spec = DEV_READONLY(target) ? 0x80 : 0x0; dev_spec = DEV_READONLY(target) ? 0x80 : 0x0;
if (msense_6) { if (msense_6) {
...@@ -662,7 +698,7 @@ static int resp_mode_sense(unsigned char * cmd, int target, ...@@ -662,7 +698,7 @@ static int resp_mode_sense(unsigned char * cmd, int target,
break; break;
default: default:
mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x24, 0, 14); mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x24, 0, 14);
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); return check_condition_result;
} }
if (msense_6) if (msense_6)
arr[0] = offset - 1; arr[0] = offset - 1;
...@@ -686,14 +722,14 @@ static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, ...@@ -686,14 +722,14 @@ static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block,
if (upper_blk || (block + num > sdebug_capacity)) { if (upper_blk || (block + num > sdebug_capacity)) {
mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x21, 0, 14); mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x21, 0, 14);
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); 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 < (OPT_MEDIUM_ERR_ADDR + num))) { ((block + num) > OPT_MEDIUM_ERR_ADDR)) {
mk_sense_buffer(devip, MEDIUM_ERROR, 0x11, 0, 14); mk_sense_buffer(devip, MEDIUM_ERROR, 0x11, 0, 14);
/* claim unrecoverable read error */ /* claim unrecoverable read error */
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); return check_condition_result;
} }
read_lock_irqsave(&atomic_rw, iflags); read_lock_irqsave(&atomic_rw, iflags);
sgcount = 0; sgcount = 0;
...@@ -735,7 +771,7 @@ static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, ...@@ -735,7 +771,7 @@ static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block,
if (upper_blk || (block + num > sdebug_capacity)) { if (upper_blk || (block + num > sdebug_capacity)) {
mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x21, 0, 14); mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x21, 0, 14);
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); return check_condition_result;
} }
write_lock_irqsave(&atomic_rw, iflags); write_lock_irqsave(&atomic_rw, iflags);
...@@ -776,7 +812,7 @@ static int resp_report_luns(unsigned char * cmd, unsigned char * buff, ...@@ -776,7 +812,7 @@ static int resp_report_luns(unsigned char * cmd, unsigned char * buff,
alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24); alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24);
if ((alloc_len < 16) || (select_report > 2)) { if ((alloc_len < 16) || (select_report > 2)) {
mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x24, 0, 14); mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x24, 0, 14);
return (DRIVER_SENSE << 24) | (CHECK_CONDITION << 1); return check_condition_result;
} }
if (bufflen > 3) { if (bufflen > 3) {
lun_cnt = min((int)(bufflen / sizeof(ScsiLun)), lun_cnt = min((int)(bufflen / sizeof(ScsiLun)),
...@@ -810,15 +846,24 @@ static void timer_intr_handler(unsigned long indx) ...@@ -810,15 +846,24 @@ static void timer_intr_handler(unsigned long indx)
return; return;
} }
sqcp->in_use = 0; sqcp->in_use = 0;
if (sqcp->done_funct) if (sqcp->done_funct) {
sqcp->a_cmnd->result = sqcp->scsi_result;
sqcp->done_funct(sqcp->a_cmnd); /* callback to mid level */ sqcp->done_funct(sqcp->a_cmnd); /* callback to mid level */
}
sqcp->done_funct = NULL; sqcp->done_funct = NULL;
spin_unlock_irqrestore(&queued_arr_lock, iflags); spin_unlock_irqrestore(&queued_arr_lock, iflags);
} }
static int scsi_debug_slave_alloc(struct scsi_device * sdp)
{
if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
printk(KERN_INFO "scsi_debug: slave_alloc <%u %u %u %u>\n",
sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
return 0;
}
static int scsi_debug_slave_configure(struct scsi_device * sdp) static int scsi_debug_slave_configure(struct scsi_device * sdp)
{ {
int k;
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)
...@@ -826,16 +871,8 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp) ...@@ -826,16 +871,8 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp)
sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN)
sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN; sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN;
for (k = 0; k < scsi_debug_num_devs; ++k) { devip = devInfoReg(sdp);
devip = &devInfop[k];
if ((devip->channel == sdp->channel) &&
(devip->target == sdp->id) &&
(devip->lun == sdp->lun) &&
(devip->host == sdp->host)) {
sdp->hostdata = devip; sdp->hostdata = devip;
break;
}
}
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);
...@@ -852,41 +889,45 @@ static void scsi_debug_slave_destroy(struct scsi_device * sdp) ...@@ -852,41 +889,45 @@ static void scsi_debug_slave_destroy(struct scsi_device * sdp)
sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
if (devip) { if (devip) {
/* make this slot avaliable for re-use */ /* make this slot avaliable for re-use */
memset(devip, 0, sizeof(struct sdebug_dev_info)); devip->used = 0;
sdp->hostdata = NULL; sdp->hostdata = NULL;
} }
} }
static struct sdebug_dev_info * devInfoReg(struct scsi_cmnd *scmd) static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
{ {
int k; struct sdebug_host_info * sdbg_host;
struct scsi_device * sdp = scmd->device; struct sdebug_dev_info * open_devip = NULL;
struct sdebug_dev_info * devip = struct sdebug_dev_info * devip =
(struct sdebug_dev_info *)sdp->hostdata; (struct sdebug_dev_info *)sdev->hostdata;
if (devip) if (devip)
return devip; return devip;
for (k = 0; k < scsi_debug_num_devs; ++k) { sdbg_host = sdebug_shost_to_host_info(sdev->host);
devip = &devInfop[k]; if(! sdbg_host) {
if ((devip->channel == scmd->device->channel) && printk(KERN_ERR "Unable to locate host info\n");
(devip->target == scmd->device->id) && return NULL;
(devip->lun == scmd->device->lun) &&
(devip->host == scmd->device->host))
return devip;
} }
for (k = 0; k < scsi_debug_num_devs; ++k) { list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) {
devip = &devInfop[k]; if ((devip->used) && (devip->channel == sdev->channel) &&
if (!devip->used) { (devip->target == sdev->id) &&
devip->channel = scmd->device->channel; (devip->lun == sdev->lun))
devip->target = scmd->device->id;
devip->lun = scmd->device->lun;
devip->host = scmd->device->host;
devip->reset = 1;
devip->used = 1;
memset(devip->sense_buff, 0, SDEBUG_SENSE_LEN);
devip->sense_buff[0] = 0x70;
return devip; return devip;
else {
if ((!devip->used) && (!open_devip))
open_devip = devip;
}
} }
if (open_devip) {
open_devip->channel = sdev->channel;
open_devip->target = sdev->id;
open_devip->lun = sdev->lun;
open_devip->sdbg_host = sdbg_host;
open_devip->reset = 1;
open_devip->used = 1;
memset(open_devip->sense_buff, 0, SDEBUG_SENSE_LEN);
open_devip->sense_buff[0] = 0x70;
return open_devip;
} }
return NULL; return NULL;
} }
...@@ -946,7 +987,7 @@ static int scsi_debug_device_reset(struct scsi_cmnd * SCpnt) ...@@ -946,7 +987,7 @@ static int scsi_debug_device_reset(struct scsi_cmnd * SCpnt)
printk(KERN_INFO "scsi_debug: device_reset\n"); printk(KERN_INFO "scsi_debug: device_reset\n");
++num_dev_resets; ++num_dev_resets;
if (SCpnt) { if (SCpnt) {
devip = devInfoReg(SCpnt); devip = devInfoReg(SCpnt->device);
if (devip) if (devip)
devip->reset = 1; devip->reset = 1;
} }
...@@ -955,17 +996,21 @@ static int scsi_debug_device_reset(struct scsi_cmnd * SCpnt) ...@@ -955,17 +996,21 @@ static int scsi_debug_device_reset(struct scsi_cmnd * SCpnt)
static int scsi_debug_bus_reset(struct scsi_cmnd * SCpnt) static int scsi_debug_bus_reset(struct scsi_cmnd * SCpnt)
{ {
struct sdebug_host_info *sdbg_host;
struct sdebug_dev_info * dev_info;
struct scsi_device * sdp; struct scsi_device * sdp;
struct Scsi_Host * hp; struct Scsi_Host * hp;
int k;
if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
printk(KERN_INFO "scsi_debug: bus_reset\n"); printk(KERN_INFO "scsi_debug: bus_reset\n");
++num_bus_resets; ++num_bus_resets;
if (SCpnt && ((sdp = SCpnt->device)) && ((hp = SCpnt->device->host))) { if (SCpnt && ((sdp = SCpnt->device)) && ((hp = sdp->host))) {
for (k = 0; k < scsi_debug_num_devs; ++k) { sdbg_host = sdebug_shost_to_host_info(hp);
if (hp == devInfop[k].host) if (sdbg_host) {
devInfop[k].reset = 1; list_for_each_entry(dev_info,
&sdbg_host->dev_info_list,
dev_list)
dev_info->reset = 1;
} }
} }
return SUCCESS; return SUCCESS;
...@@ -973,15 +1018,20 @@ static int scsi_debug_bus_reset(struct scsi_cmnd * SCpnt) ...@@ -973,15 +1018,20 @@ static int scsi_debug_bus_reset(struct scsi_cmnd * SCpnt)
static int scsi_debug_host_reset(struct scsi_cmnd * SCpnt) static int scsi_debug_host_reset(struct scsi_cmnd * SCpnt)
{ {
int k; struct sdebug_host_info * sdbg_host;
struct sdebug_dev_info * dev_info;
if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
printk(KERN_INFO "scsi_debug: host_reset\n"); printk(KERN_INFO "scsi_debug: host_reset\n");
++num_host_resets; ++num_host_resets;
for (k = 0; k < scsi_debug_num_devs; ++k) spin_lock(&sdebug_host_list_lock);
devInfop[k].reset = 1; list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
list_for_each_entry(dev_info, &sdbg_host->dev_info_list,
dev_list)
dev_info->reset = 1;
}
spin_unlock(&sdebug_host_list_lock);
stop_all_queued(); stop_all_queued();
return SUCCESS; return SUCCESS;
} }
...@@ -1063,7 +1113,7 @@ static int schedule_resp(struct scsi_cmnd * cmnd, ...@@ -1063,7 +1113,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 (CHECK_CONDITION == status_byte(scsi_result)) 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);
...@@ -1099,6 +1149,8 @@ static int schedule_resp(struct scsi_cmnd * cmnd, ...@@ -1099,6 +1149,8 @@ static int schedule_resp(struct scsi_cmnd * cmnd,
sqcp->cmnd_timer.expires = jiffies + delta_jiff; sqcp->cmnd_timer.expires = jiffies + delta_jiff;
add_timer(&sqcp->cmnd_timer); add_timer(&sqcp->cmnd_timer);
spin_unlock_irqrestore(&queued_arr_lock, iflags); spin_unlock_irqrestore(&queued_arr_lock, iflags);
if (cmnd)
cmnd->result = 0;
return 0; return 0;
} }
} }
...@@ -1120,7 +1172,7 @@ MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); ...@@ -1120,7 +1172,7 @@ 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_PARM_DESC(num_devs, "number of SCSI devices to simulate"); MODULE_PARM_DESC(num_devs, "number of SCSI devices per host to simulate");
MODULE_PARM_DESC(max_luns, "number of SCSI LUNs per target to simulate"); MODULE_PARM_DESC(max_luns, "number of SCSI LUNs per target to simulate");
MODULE_PARM_DESC(scsi_level, "SCSI level to simulate"); 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");
...@@ -1163,7 +1215,7 @@ static int scsi_debug_proc_info(char *buffer, char **start, off_t offset, ...@@ -1163,7 +1215,7 @@ static int scsi_debug_proc_info(char *buffer, char **start, off_t offset,
if (1 != sscanf(arr, "%d", &pos)) if (1 != sscanf(arr, "%d", &pos))
return -EINVAL; return -EINVAL;
scsi_debug_opts = pos; scsi_debug_opts = pos;
if (SCSI_DEBUG_OPT_EVERY_NTH & scsi_debug_opts) if (scsi_debug_every_nth > 0)
scsi_debug_cmnd_count = 0; scsi_debug_cmnd_count = 0;
return length; return length;
} }
...@@ -1192,12 +1244,12 @@ static int scsi_debug_proc_info(char *buffer, char **start, off_t offset, ...@@ -1192,12 +1244,12 @@ static int scsi_debug_proc_info(char *buffer, char **start, off_t offset,
return len; return len;
} }
static ssize_t sdebug_delay_read(struct device_driver * ddp, char * buf) static ssize_t sdebug_delay_show(struct device_driver * ddp, char * buf)
{ {
return sprintf(buf, "%d\n", scsi_debug_delay); return snprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_delay);
} }
static ssize_t sdebug_delay_write(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;
...@@ -1211,15 +1263,15 @@ static ssize_t sdebug_delay_write(struct device_driver * ddp, ...@@ -1211,15 +1263,15 @@ static ssize_t sdebug_delay_write(struct device_driver * ddp,
} }
return -EINVAL; return -EINVAL;
} }
DRIVER_ATTR(delay, S_IRUGO | S_IWUSR, sdebug_delay_read, DRIVER_ATTR(delay, S_IRUGO | S_IWUSR, sdebug_delay_show,
sdebug_delay_write) sdebug_delay_store)
static ssize_t sdebug_opts_read(struct device_driver * ddp, char * buf) static ssize_t sdebug_opts_show(struct device_driver * ddp, char * buf)
{ {
return sprintf(buf, "0x%x\n", scsi_debug_opts); return snprintf(buf, PAGE_SIZE, "0x%x\n", scsi_debug_opts);
} }
static ssize_t sdebug_opts_write(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;
...@@ -1237,50 +1289,76 @@ static ssize_t sdebug_opts_write(struct device_driver * ddp, ...@@ -1237,50 +1289,76 @@ static ssize_t sdebug_opts_write(struct device_driver * ddp,
return -EINVAL; return -EINVAL;
opts_done: opts_done:
scsi_debug_opts = opts; scsi_debug_opts = opts;
scsi_debug_cmnd_count = 0;
return count; return count;
} }
DRIVER_ATTR(opts, S_IRUGO | S_IWUSR, sdebug_opts_read, DRIVER_ATTR(opts, S_IRUGO | S_IWUSR, sdebug_opts_show,
sdebug_opts_write) sdebug_opts_store)
static ssize_t sdebug_num_devs_read(struct device_driver * ddp, char * buf) static ssize_t sdebug_num_devs_show(struct device_driver * ddp, char * buf)
{ {
return sprintf(buf, "%d\n", scsi_debug_num_devs); return snprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_devs);
}
static ssize_t sdebug_num_devs_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_num_devs = n;
return count;
}
return -EINVAL;
} }
DRIVER_ATTR(num_devs, S_IRUGO, sdebug_num_devs_read, NULL) DRIVER_ATTR(num_devs, S_IRUGO | S_IWUSR, sdebug_num_devs_show,
sdebug_num_devs_store)
static ssize_t sdebug_dev_size_mb_read(struct device_driver * ddp, char * buf) static ssize_t sdebug_dev_size_mb_show(struct device_driver * ddp, char * buf)
{ {
return sprintf(buf, "%d\n", scsi_debug_dev_size_mb); return snprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dev_size_mb);
} }
DRIVER_ATTR(dev_size_mb, S_IRUGO, sdebug_dev_size_mb_read, NULL) DRIVER_ATTR(dev_size_mb, S_IRUGO, sdebug_dev_size_mb_show, NULL)
static ssize_t sdebug_every_nth_read(struct device_driver * ddp, char * buf) static ssize_t sdebug_every_nth_show(struct device_driver * ddp, char * buf)
{ {
return sprintf(buf, "%d\n", scsi_debug_every_nth); return snprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_every_nth);
} }
DRIVER_ATTR(every_nth, S_IRUGO, sdebug_every_nth_read, NULL) static ssize_t sdebug_every_nth_store(struct device_driver * ddp,
const char * buf, size_t count)
{
int nth;
static ssize_t sdebug_max_luns_read(struct device_driver * ddp, char * buf) if ((count > 0) && (1 == sscanf(buf, "%d", &nth)) && (nth >= 0)) {
scsi_debug_every_nth = nth;
scsi_debug_cmnd_count = 0;
return count;
}
return -EINVAL;
}
DRIVER_ATTR(every_nth, S_IRUGO | S_IWUSR, sdebug_every_nth_show,
sdebug_every_nth_store)
static ssize_t sdebug_max_luns_show(struct device_driver * ddp, char * buf)
{ {
return sprintf(buf, "%d\n", scsi_debug_max_luns); return snprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_luns);
} }
DRIVER_ATTR(max_luns, S_IRUGO, sdebug_max_luns_read, NULL) DRIVER_ATTR(max_luns, S_IRUGO, sdebug_max_luns_show, NULL)
static ssize_t sdebug_scsi_level_read(struct device_driver * ddp, char * buf) static ssize_t sdebug_scsi_level_show(struct device_driver * ddp, char * buf)
{ {
return sprintf(buf, "%d\n", scsi_debug_scsi_level); return snprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_scsi_level);
} }
DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_read, NULL) DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL)
static ssize_t sdebug_add_host_read(struct device_driver * ddp, char * buf) static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf)
{ {
return sprintf(buf, "%d\n", scsi_debug_add_host); return snprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host);
} }
static ssize_t sdebug_add_host_write(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, k; int delta_hosts;
char work[20]; char work[20];
if (1 != sscanf(buf, "%10s", work)) if (1 != sscanf(buf, "%10s", work))
...@@ -1297,33 +1375,17 @@ static ssize_t sdebug_add_host_write(struct device_driver * ddp, ...@@ -1297,33 +1375,17 @@ static ssize_t sdebug_add_host_write(struct device_driver * ddp,
} }
if (delta_hosts > 0) { if (delta_hosts > 0) {
do { do {
for (k = 0; k < MAX_NUM_HOSTS; ++k) { sdebug_add_adapter();
if (NULL == scsi_debug_hosts[k].shost) {
sdebug_add_shost(k);
break;
}
}
if (k == MAX_NUM_HOSTS)
break;
++scsi_debug_add_host;
} while (--delta_hosts); } while (--delta_hosts);
} else if (delta_hosts < 0) { } else if (delta_hosts < 0) {
do { do {
for (k = MAX_NUM_HOSTS - 1; k >= 0; --k) { sdebug_remove_adapter();
if (scsi_debug_hosts[k].shost) {
sdebug_remove_shost(k);
break;
}
}
if (k < 0)
break;
--scsi_debug_add_host;
} while (++delta_hosts); } while (++delta_hosts);
} }
return count; return count;
} }
DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_read, DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show,
sdebug_add_host_write) sdebug_add_host_store)
static void do_create_driverfs_files() static void do_create_driverfs_files()
{ {
...@@ -1349,44 +1411,10 @@ static void do_remove_driverfs_files() ...@@ -1349,44 +1411,10 @@ static void do_remove_driverfs_files()
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_delay); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_delay);
} }
static void sdebug_add_shost(int num)
{
struct Scsi_Host * hpnt;
int err;
if (sdebug_add_adapter(num)){
printk(KERN_ERR "sdebug_add_shost: sdebug_add_adapter failed\n");
return;
}
hpnt = scsi_register(&sdebug_driver_template, 0);
if (NULL == hpnt) {
sdebug_remove_adapter(num);
printk(KERN_ERR "sdebug_add_shost: scsi_register failed\n");
return;
}
err = scsi_add_host(hpnt, scsi_debug_hosts[num].dev);
if (err) {
printk(KERN_ERR "sdebug_add_shost: scsi_add_host failed\n");
scsi_unregister(hpnt);
sdebug_remove_adapter(num);
return;
}
hpnt->max_lun = scsi_debug_max_luns;
scsi_debug_hosts[num].shost = hpnt;
}
static void sdebug_remove_shost(int num)
{
scsi_remove_host(scsi_debug_hosts[num].shost);
scsi_unregister(scsi_debug_hosts[num].shost);
sdebug_remove_adapter(num);
scsi_debug_hosts[num].shost = NULL;
}
static int __init scsi_debug_init(void) static int __init scsi_debug_init(void)
{ {
unsigned long sz; unsigned long sz;
int host_to_add;
int k; int k;
sdebug_store_size = (unsigned long)scsi_debug_dev_size_mb * 1048576; sdebug_store_size = (unsigned long)scsi_debug_dev_size_mb * 1048576;
...@@ -1409,30 +1437,10 @@ static int __init scsi_debug_init(void) ...@@ -1409,30 +1437,10 @@ static int __init scsi_debug_init(void)
(sdebug_sectors_per * sdebug_heads); (sdebug_sectors_per * sdebug_heads);
} }
if (scsi_debug_num_devs > 0) {
sz = sizeof(struct sdebug_dev_info) * scsi_debug_num_devs;
devInfop = vmalloc(sz);
if (NULL == devInfop) {
printk(KERN_ERR "scsi_debug_init: out of memory\n");
return -ENOMEM;
}
memset(devInfop, 0, sz);
}
sz = sizeof(struct sdebug_host_info) * MAX_NUM_HOSTS;
scsi_debug_hosts = vmalloc(sz);
if (NULL == scsi_debug_hosts) {
printk(KERN_ERR "scsi_debug_init: out of memory 1\n");
return -ENOMEM;
}
memset(scsi_debug_hosts, 0, sz);
sz = sdebug_store_size; sz = sdebug_store_size;
fake_storep = vmalloc(sz); fake_storep = vmalloc(sz);
if (NULL == fake_storep) { if (NULL == fake_storep) {
printk(KERN_ERR "scsi_debug_init: out of memory, 1\n"); printk(KERN_ERR "scsi_debug_init: out of memory, 1\n");
if (devInfop)
vfree(devInfop);
return -ENOMEM; return -ENOMEM;
} }
memset(fake_storep, 0, sz); memset(fake_storep, 0, sz);
...@@ -1446,15 +1454,16 @@ static int __init scsi_debug_init(void) ...@@ -1446,15 +1454,16 @@ static int __init scsi_debug_init(void)
sdebug_driver_template.proc_name = (char *)sdebug_proc_name; sdebug_driver_template.proc_name = (char *)sdebug_proc_name;
for (k = 0; (k < scsi_debug_add_host) && (k < MAX_NUM_HOSTS); k++) { host_to_add = scsi_debug_add_host;
sdebug_add_shost(k); scsi_debug_add_host = 0;
if (NULL == scsi_debug_hosts[k].shost) {
for (k = 0; k < host_to_add; k++) {
if (sdebug_add_adapter()) {
printk(KERN_ERR "scsi_debug_init: " printk(KERN_ERR "scsi_debug_init: "
"sdebug_add_shost failed k=%d\n", k); "sdebug_add_adapter failed k=%d\n", k);
break; break;
} }
} }
scsi_debug_add_host = k; // number of hosts actually present
if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) { if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) {
printk(KERN_INFO "scsi_debug: ... built %d host(s)\n", printk(KERN_INFO "scsi_debug: ... built %d host(s)\n",
...@@ -1465,13 +1474,7 @@ static int __init scsi_debug_init(void) ...@@ -1465,13 +1474,7 @@ static int __init scsi_debug_init(void)
static void __exit scsi_debug_exit(void) static void __exit scsi_debug_exit(void)
{ {
int k; /* free up adapters here ?? */
for (k = MAX_NUM_HOSTS - 1; k >= 0; --k) {
if (scsi_debug_hosts[k].shost) {
sdebug_remove_shost(k);
}
}
stop_all_queued(); stop_all_queued();
do_remove_driverfs_files(); do_remove_driverfs_files();
scsi_debug_unregister_driver(&sdebug_driverfs_driver); scsi_debug_unregister_driver(&sdebug_driverfs_driver);
...@@ -1479,8 +1482,6 @@ static void __exit scsi_debug_exit(void) ...@@ -1479,8 +1482,6 @@ static void __exit scsi_debug_exit(void)
device_unregister(&pseudo_primary); device_unregister(&pseudo_primary);
vfree(fake_storep); vfree(fake_storep);
if (devInfop)
vfree(devInfop);
} }
device_initcall(scsi_debug_init); device_initcall(scsi_debug_init);
...@@ -1502,7 +1503,7 @@ static struct bus_type pseudo_lld_bus = { ...@@ -1502,7 +1503,7 @@ static struct bus_type pseudo_lld_bus = {
.match = pseudo_lld_bus_match, .match = pseudo_lld_bus_match,
}; };
int scsi_debug_register_driver(struct device_driver *dev_driver) static int scsi_debug_register_driver(struct device_driver *dev_driver)
{ {
dev_driver->bus = &pseudo_lld_bus; dev_driver->bus = &pseudo_lld_bus;
driver_register(dev_driver); driver_register(dev_driver);
...@@ -1510,36 +1511,168 @@ int scsi_debug_register_driver(struct device_driver *dev_driver) ...@@ -1510,36 +1511,168 @@ int scsi_debug_register_driver(struct device_driver *dev_driver)
return 0; return 0;
} }
int scsi_debug_unregister_driver(struct device_driver *dev_driver) static int scsi_debug_unregister_driver(struct device_driver *dev_driver)
{ {
driver_unregister(dev_driver); driver_unregister(dev_driver);
return 0; return 0;
} }
static int sdebug_add_adapter(int num) static void sdebug_release_adapter(struct device * dev)
{
kfree(dev);
}
static int sdebug_add_adapter()
{ {
struct device * dev; struct device * dev;
int error;
dev = kmalloc(sizeof(*dev),GFP_KERNEL); dev = kmalloc(sizeof(*dev),GFP_KERNEL);
if (NULL == dev) { if (NULL == dev) {
printk(KERN_ERR "%s: out of memory\n", __FUNCTION__); printk(KERN_ERR "%s: out of memory at line %d\n",
return 1; __FUNCTION__, __LINE__);
return -ENOMEM;
} }
memset(dev, 0, sizeof(*dev)); memset(dev, 0, sizeof(*dev));
dev->bus = &pseudo_lld_bus; dev->bus = &pseudo_lld_bus;
dev->parent = &pseudo_primary; dev->parent = &pseudo_primary;
dev->release = &sdebug_release_adapter;
sprintf(dev->name, "scsi debug adapter"); sprintf(dev->name, "scsi debug adapter");
sprintf(dev->bus_id, "adapter%d", num); sprintf(dev->bus_id, "adapter%d", scsi_debug_add_host);
error = device_register(dev);
if (error)
kfree(dev);
else
++scsi_debug_add_host;
device_register(dev); return error;
}
static void sdebug_remove_adapter()
{
struct sdebug_host_info * sdbg_host = NULL;
spin_lock(&sdebug_host_list_lock);
if (!list_empty(&sdebug_host_list))
sdbg_host = list_entry(sdebug_host_list.prev,
struct sdebug_host_info, host_list);
spin_unlock(&sdebug_host_list_lock);
device_unregister(sdbg_host->dev);
--scsi_debug_add_host;
}
static int sdebug_driver_probe(struct device * dev)
{
int k;
int error = 0;
struct sdebug_host_info *sdbg_host;
struct sdebug_dev_info *sdbg_devinfo;
struct list_head *lh, *lh_sf;
struct Scsi_Host *hpnt;
sdbg_host = kmalloc(sizeof(*sdbg_host),GFP_KERNEL);
if (NULL == sdbg_host) {
printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__);
return -ENOMEM;
}
memset(sdbg_host, 0, sizeof(*sdbg_host));
INIT_LIST_HEAD(&sdbg_host->dev_info_list);
for (k = 0; k < scsi_debug_num_devs; k++) {
sdbg_devinfo = kmalloc(sizeof(*sdbg_devinfo),GFP_KERNEL);
if (NULL == sdbg_devinfo) {
printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__);
error = -ENOMEM;
}
memset(sdbg_devinfo, 0, sizeof(*sdbg_devinfo));
sdbg_devinfo->sdbg_host = sdbg_host;
list_add_tail(&sdbg_devinfo->dev_list,
&sdbg_host->dev_info_list);
}
list_add_tail(&sdbg_host->host_list, &sdebug_host_list);
hpnt = scsi_register(&sdebug_driver_template, 0);
if (NULL == hpnt) {
printk(KERN_ERR "%s: scsi_register failed\n", __FUNCTION__);
error = -ENODEV;
goto clean1;
}
sdbg_host->shost = hpnt;
sdbg_host->dev = dev;
hpnt->max_lun = scsi_debug_max_luns;
error = scsi_add_host(hpnt, sdbg_host->dev);
if (error) {
printk(KERN_ERR "%s: scsi_add_host failed\n", __FUNCTION__);
error = -ENODEV;
goto clean2;
}
scsi_debug_hosts[num].dev = dev;
return 0; return 0;
clean2:
scsi_unregister(hpnt);
clean1:
list_for_each_safe(lh, lh_sf, &sdbg_host->dev_info_list) {
sdbg_devinfo = list_entry(lh, struct sdebug_dev_info,
dev_list);
list_del(&sdbg_devinfo->dev_list);
kfree(sdbg_devinfo);
}
kfree(sdbg_host);
return error;
} }
static void sdebug_remove_adapter(int num) static int sdebug_driver_remove(struct device * dev)
{ {
device_unregister(scsi_debug_hosts[num].dev); struct list_head *lh, *lh_sf;
struct sdebug_dev_info *sdbg_devinfo;
struct sdebug_host_info *sdbg_host, *found = NULL;
spin_lock(&sdebug_host_list_lock);
list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
if (sdbg_host->dev == dev) {
list_del(&sdbg_host->host_list);
found = sdbg_host;
break;
}
}
spin_unlock(&sdebug_host_list_lock);
if (!found) {
printk(KERN_ERR "%s: sdebug_host_info not found\n",
__FUNCTION__);
return -ENODEV;
}
if (scsi_remove_host(sdbg_host->shost)) {
printk(KERN_ERR "%s: scsi_remove_host failed\n", __FUNCTION__);
return -EBUSY;
}
scsi_unregister(sdbg_host->shost);
list_for_each_safe(lh, lh_sf, &sdbg_host->dev_info_list) {
sdbg_devinfo = list_entry(lh, struct sdebug_dev_info,
dev_list);
list_del(&sdbg_devinfo->dev_list);
kfree(sdbg_devinfo);
}
kfree(sdbg_host);
return 0;
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <linux/types.h> #include <linux/types.h>
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 *,
...@@ -27,6 +28,7 @@ static Scsi_Host_Template sdebug_driver_template = { ...@@ -27,6 +28,7 @@ static Scsi_Host_Template sdebug_driver_template = {
.proc_info = scsi_debug_proc_info, .proc_info = scsi_debug_proc_info,
.name = "SCSI DEBUG", .name = "SCSI DEBUG",
.info = scsi_debug_info, .info = scsi_debug_info,
.slave_alloc = scsi_debug_slave_alloc,
.slave_configure = scsi_debug_slave_configure, .slave_configure = scsi_debug_slave_configure,
.slave_destroy = scsi_debug_slave_destroy, .slave_destroy = scsi_debug_slave_destroy,
.ioctl = scsi_debug_ioctl, .ioctl = scsi_debug_ioctl,
......
...@@ -596,28 +596,6 @@ static int scsi_request_sense(struct scsi_cmnd *scmd) ...@@ -596,28 +596,6 @@ static int scsi_request_sense(struct scsi_cmnd *scmd)
return rtn; return rtn;
} }
/**
* scsi_eh_retry_cmd - Retry the original command
* @scmd: Original failed SCSI cmd.
*
* Notes:
* This function will *not* return until the command either times out,
* or it completes.
**/
static int scsi_eh_retry_cmd(struct scsi_cmnd *scmd)
{
int rtn = SUCCESS;
for (; scmd->retries < scmd->allowed; scmd->retries++) {
scsi_setup_cmd_retry(scmd);
rtn = scsi_send_eh_cmnd(scmd, scmd->timeout_per_command);
if (rtn != NEEDS_RETRY)
break;
}
return rtn;
}
/** /**
* scsi_eh_finish_cmd - Handle a cmd that eh is finished with. * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
* @scmd: Original SCSI cmd that eh has finished. * @scmd: Original SCSI cmd that eh has finished.
......
...@@ -125,7 +125,6 @@ int scsi_queue_insert(struct scsi_cmnd *cmd, int reason) ...@@ -125,7 +125,6 @@ int scsi_queue_insert(struct scsi_cmnd *cmd, int reason)
*/ */
cmd->state = SCSI_STATE_MLQUEUE; cmd->state = SCSI_STATE_MLQUEUE;
cmd->owner = SCSI_OWNER_MIDLEVEL; cmd->owner = SCSI_OWNER_MIDLEVEL;
cmd->bh_next = NULL;
/* /*
* Decrement the counters, since these commands are no longer * Decrement the counters, since these commands are no longer
......
...@@ -385,8 +385,10 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -385,8 +385,10 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
struct scsi_device *sdev, *device; struct scsi_device *sdev, *device;
sdev = kmalloc(sizeof(*sdev), GFP_ATOMIC); sdev = kmalloc(sizeof(*sdev), GFP_ATOMIC);
if (sdev != NULL) { if (!sdev)
memset(sdev, 0, sizeof(Scsi_Device)); goto out;
memset(sdev, 0, sizeof(*sdev));
sdev->vendor = scsi_null_device_strs; sdev->vendor = scsi_null_device_strs;
sdev->model = scsi_null_device_strs; sdev->model = scsi_null_device_strs;
sdev->rev = scsi_null_device_strs; sdev->rev = scsi_null_device_strs;
...@@ -399,10 +401,12 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -399,10 +401,12 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
INIT_LIST_HEAD(&sdev->same_target_siblings); INIT_LIST_HEAD(&sdev->same_target_siblings);
INIT_LIST_HEAD(&sdev->cmd_list); INIT_LIST_HEAD(&sdev->cmd_list);
spin_lock_init(&sdev->list_lock); spin_lock_init(&sdev->list_lock);
/* /*
* Some low level driver could use device->type * Some low level driver could use device->type
*/ */
sdev->type = -1; sdev->type = -1;
/* /*
* Assume that the device will have handshaking problems, * Assume that the device will have handshaking problems,
* and then fix this field later if it turns out it * and then fix this field later if it turns out it
...@@ -413,7 +417,7 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -413,7 +417,7 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
if (!q || *q == NULL) { if (!q || *q == NULL) {
sdev->request_queue = scsi_alloc_queue(shost); sdev->request_queue = scsi_alloc_queue(shost);
if (!sdev->request_queue) if (!sdev->request_queue)
goto out_bail; goto out_free_dev;
} else { } else {
sdev->request_queue = *q; sdev->request_queue = *q;
*q = NULL; *q = NULL;
...@@ -423,16 +427,17 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -423,16 +427,17 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
init_waitqueue_head(&sdev->scpnt_wait); init_waitqueue_head(&sdev->scpnt_wait);
if (shost->hostt->slave_alloc) if (shost->hostt->slave_alloc) {
if (shost->hostt->slave_alloc(sdev)) { if (shost->hostt->slave_alloc(sdev))
goto out_bail; goto out_free_queue;
} }
/* /*
* If there are any same target siblings, add this to the * If there are any same target siblings, add this to the
* sibling list * sibling list
*/ */
list_for_each_entry(device, &shost->my_devices, siblings) { list_for_each_entry(device, &shost->my_devices, siblings) {
if(device->id == sdev->id && if (device->id == sdev->id &&
device->channel == sdev->channel) { device->channel == sdev->channel) {
list_add_tail(&sdev->same_target_siblings, list_add_tail(&sdev->same_target_siblings,
&device->same_target_siblings); &device->same_target_siblings);
...@@ -440,28 +445,32 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -440,28 +445,32 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
break; break;
} }
} }
/* /*
* If there wasn't another lun already configured at this * If there wasn't another lun already configured at this
* target, then default this device to SCSI_2 until we * target, then default this device to SCSI_2 until we
* know better * know better
*/ */
if(!sdev->scsi_level) if (!sdev->scsi_level)
sdev->scsi_level = SCSI_2; sdev->scsi_level = SCSI_2;
/* /*
* Add it to the end of the shost->my_devices list. * Add it to the end of the shost->my_devices list.
*/ */
list_add_tail(&sdev->siblings, &shost->my_devices); list_add_tail(&sdev->siblings, &shost->my_devices);
return (sdev); return sdev;
}
out_bail: out_free_queue:
printk(ALLOC_FAILURE_MSG, __FUNCTION__);
if (q && sdev->request_queue) { if (q && sdev->request_queue) {
*q = sdev->request_queue; *q = sdev->request_queue;
sdev->request_queue = NULL; sdev->request_queue = NULL;
} else if (sdev->request_queue) } else if (sdev->request_queue)
scsi_free_queue(sdev->request_queue); scsi_free_queue(sdev->request_queue);
out_free_dev:
kfree(sdev); kfree(sdev);
out:
printk(ALLOC_FAILURE_MSG, __FUNCTION__);
return NULL; return NULL;
} }
......
...@@ -266,6 +266,25 @@ sdev_rd_attr (model, "%.16s\n"); ...@@ -266,6 +266,25 @@ sdev_rd_attr (model, "%.16s\n");
sdev_rd_attr (rev, "%.4s\n"); sdev_rd_attr (rev, "%.4s\n");
sdev_rw_attr_bit (online); sdev_rw_attr_bit (online);
static ssize_t
show_rescan_field (struct device *dev, char *buf)
{
return 0;
}
static ssize_t
store_rescan_field (struct device *dev, const char *buf, size_t count)
{
int ret = ENODEV;
struct scsi_device *sdev;
sdev = to_scsi_device(dev);
if (sdev)
ret = scsi_rescan_device(sdev);
return ret;
}
static DEVICE_ATTR(rescan, S_IRUGO | S_IWUSR, show_rescan_field, store_rescan_field)
static struct device_attribute * const sdev_attrs[] = { static struct device_attribute * const sdev_attrs[] = {
&dev_attr_device_blocked, &dev_attr_device_blocked,
&dev_attr_queue_depth, &dev_attr_queue_depth,
...@@ -276,6 +295,7 @@ static struct device_attribute * const sdev_attrs[] = { ...@@ -276,6 +295,7 @@ static struct device_attribute * const sdev_attrs[] = {
&dev_attr_model, &dev_attr_model,
&dev_attr_rev, &dev_attr_rev,
&dev_attr_online, &dev_attr_online,
&dev_attr_rescan,
}; };
/** /**
......
...@@ -93,10 +93,12 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt); ...@@ -93,10 +93,12 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt);
static int sd_attach(struct scsi_device *); static int sd_attach(struct scsi_device *);
static void sd_detach(struct scsi_device *); static void sd_detach(struct scsi_device *);
static void sd_rescan(struct scsi_device *);
static int sd_init_command(struct scsi_cmnd *); static int sd_init_command(struct scsi_cmnd *);
static int sd_synchronize_cache(struct scsi_disk *, int); static int sd_synchronize_cache(struct scsi_disk *, int);
static int sd_notifier(struct notifier_block *, unsigned long, void *); static int sd_notifier(struct notifier_block *, unsigned long, void *);
static void sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
struct scsi_request *SRpnt, unsigned char *buffer);
static struct notifier_block sd_notifier_block = {sd_notifier, NULL, 0}; static struct notifier_block sd_notifier_block = {sd_notifier, NULL, 0};
static struct Scsi_Device_Template sd_template = { static struct Scsi_Device_Template sd_template = {
...@@ -106,6 +108,7 @@ static struct Scsi_Device_Template sd_template = { ...@@ -106,6 +108,7 @@ static struct Scsi_Device_Template sd_template = {
.scsi_type = TYPE_DISK, .scsi_type = TYPE_DISK,
.attach = sd_attach, .attach = sd_attach,
.detach = sd_detach, .detach = sd_detach,
.rescan = sd_rescan,
.init_command = sd_init_command, .init_command = sd_init_command,
.scsi_driverfs_driver = { .scsi_driverfs_driver = {
.name = "sd", .name = "sd",
...@@ -629,6 +632,38 @@ static int sd_media_changed(struct gendisk *disk) ...@@ -629,6 +632,38 @@ static int sd_media_changed(struct gendisk *disk)
return 1; return 1;
} }
static void sd_rescan(struct scsi_device * sdp)
{
unsigned char *buffer;
struct scsi_disk *sdkp = sd_find_by_sdev(sdp);
struct gendisk *gd;
struct scsi_request *SRpnt;
if (!sdkp || sdp->online == FALSE || !sdkp->media_present)
return;
gd = sdkp->disk;
SCSI_LOG_HLQUEUE(3, printk("sd_rescan: disk=%s\n", gd->disk_name));
SRpnt = scsi_allocate_request(sdp);
if (!SRpnt) {
printk(KERN_WARNING "(sd_rescan:) Request allocation "
"failure.\n");
return;
}
if (sdkp->device->host->unchecked_isa_dma)
buffer = kmalloc(512, GFP_DMA);
else
buffer = kmalloc(512, GFP_KERNEL);
sd_read_capacity(sdkp, gd->disk_name, SRpnt, buffer);
set_capacity(gd, sdkp->capacity);
scsi_release_request(SRpnt);
kfree(buffer);
}
static int sd_revalidate_disk(struct gendisk *disk) static int sd_revalidate_disk(struct gendisk *disk)
{ {
struct scsi_disk *sdkp = scsi_disk(disk); struct scsi_disk *sdkp = scsi_disk(disk);
......
...@@ -18,10 +18,8 @@ ...@@ -18,10 +18,8 @@
* *
*/ */
#include <linux/config.h> #include <linux/config.h>
#ifdef CONFIG_PROC_FS static char *sg_version_str = "3.5.28 [20030308]";
static char *sg_version_str = "Version: 3.5.27 (20030130)"; static int sg_version_num = 30528; /* 2 digits for each component */
#endif
static int sg_version_num = 30527; /* 2 digits for each component */
/* /*
* D. P. Gilbert (dgilbert@interlog.com, dougg@triode.net.au), notes: * D. P. Gilbert (dgilbert@interlog.com, dougg@triode.net.au), notes:
* - scsi logging is available via SCSI_LOG_TIMEOUT macros. First * - scsi logging is available via SCSI_LOG_TIMEOUT macros. First
...@@ -56,6 +54,7 @@ static int sg_version_num = 30527; /* 2 digits for each component */ ...@@ -56,6 +54,7 @@ static int sg_version_num = 30527; /* 2 digits for each component */
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/moduleparam.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -1327,27 +1326,6 @@ static struct file_operations sg_fops = { ...@@ -1327,27 +1326,6 @@ static struct file_operations sg_fops = {
.fasync = sg_fasync, .fasync = sg_fasync,
}; };
#ifndef MODULE
static int __init
sg_def_reserved_size_setup(char *str)
{
int tmp;
if (get_option(&str, &tmp) == 1) {
def_reserved_size = tmp;
if (tmp >= 0)
sg_big_buff = tmp;
return 1;
} else {
printk(KERN_WARNING "sg_def_reserved_size : usage "
"sg_def_reserved_size=n (n could be 65536, 131072 or 262144)\n");
return 0;
}
}
__setup("sg_def_reserved_size=", sg_def_reserved_size_setup);
#endif
/* Driverfs file support */ /* Driverfs file support */
static ssize_t static ssize_t
sg_device_kdev_read(struct device *driverfs_dev, char *page) sg_device_kdev_read(struct device *driverfs_dev, char *page)
...@@ -1564,16 +1542,77 @@ sg_detach(Scsi_Device * scsidp) ...@@ -1564,16 +1542,77 @@ sg_detach(Scsi_Device * scsidp)
scsi_sleep(2); /* dirty detach so delay device destruction */ scsi_sleep(2); /* dirty detach so delay device destruction */
} }
/* Set 'perm' (4th argument) to 0 to disable module_param's definition
* of sysfs parameters (which module_param doesn't yet support).
* Sysfs parameters defined explicitly below.
*/
module_param_named(def_reserved_size, def_reserved_size, int, 0);
module_param_named(allow_dio, sg_allow_dio, int, 0);
MODULE_AUTHOR("Douglas Gilbert"); MODULE_AUTHOR("Douglas Gilbert");
MODULE_DESCRIPTION("SCSI generic (sg) driver"); MODULE_DESCRIPTION("SCSI generic (sg) driver");
#ifdef MODULE_LICENSE
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
#endif
MODULE_PARM(def_reserved_size, "i");
MODULE_PARM_DESC(def_reserved_size, "size of buffer reserved for each fd"); MODULE_PARM_DESC(def_reserved_size, "size of buffer reserved for each fd");
static ssize_t sg_allow_dio_show(struct device_driver * ddp, char * buf)
{
return snprintf(buf, PAGE_SIZE, "%d\n", sg_allow_dio);
}
static ssize_t sg_allow_dio_store(struct device_driver * ddp,
const char * buf, size_t count)
{
if (1 == sscanf(buf, "%d", &sg_allow_dio)) {
sg_allow_dio = sg_allow_dio ? 1 : 0;
return count;
}
return -EINVAL;
}
DRIVER_ATTR(allow_dio, S_IRUGO | S_IWUSR, sg_allow_dio_show,
sg_allow_dio_store)
static ssize_t sg_def_reserved_show(struct device_driver * ddp, char * buf)
{
return snprintf(buf, PAGE_SIZE, "%d\n", sg_big_buff);
}
static ssize_t sg_def_reserved_store(struct device_driver * ddp,
const char * buf, size_t count)
{
if (1 == sscanf(buf, "%d", &def_reserved_size)) {
if (def_reserved_size >= 0) {
sg_big_buff = def_reserved_size;
return count;
}
}
return -EINVAL;
}
DRIVER_ATTR(def_reserved_size, S_IRUGO | S_IWUSR, sg_def_reserved_show,
sg_def_reserved_store)
static ssize_t sg_version_show(struct device_driver * ddp, char * buf)
{
return snprintf(buf, PAGE_SIZE, "%s\n", sg_version_str);
}
DRIVER_ATTR(version, S_IRUGO, sg_version_show, NULL)
static void do_create_driverfs_files(void)
{
struct device_driver * driverfs = &sg_template.scsi_driverfs_driver;
driver_create_file(driverfs, &driver_attr_allow_dio);
driver_create_file(driverfs, &driver_attr_def_reserved_size);
driver_create_file(driverfs, &driver_attr_version);
}
static void do_remove_driverfs_files(void)
{
struct device_driver * driverfs = &sg_template.scsi_driverfs_driver;
driver_remove_file(driverfs, &driver_attr_version);
driver_remove_file(driverfs, &driver_attr_def_reserved_size);
driver_remove_file(driverfs, &driver_attr_allow_dio);
}
static int __init static int __init
init_sg(void) init_sg(void)
{ {
...@@ -1591,12 +1630,14 @@ init_sg(void) ...@@ -1591,12 +1630,14 @@ init_sg(void)
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
sg_proc_init(); sg_proc_init();
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
do_create_driverfs_files();
return 0; return 0;
} }
static void __exit static void __exit
exit_sg(void) exit_sg(void)
{ {
do_remove_driverfs_files();
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
sg_proc_cleanup(); sg_proc_cleanup();
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
...@@ -2656,10 +2697,6 @@ sg_get_dev(int dev) ...@@ -2656,10 +2697,6 @@ sg_get_dev(int dev)
static struct proc_dir_entry *sg_proc_sgp = NULL; static struct proc_dir_entry *sg_proc_sgp = NULL;
static char sg_proc_sg_dirname[] = "sg"; static char sg_proc_sg_dirname[] = "sg";
static const char *sg_proc_leaf_names[] = { "allow_dio", "def_reserved_size",
"debug", "devices", "device_hdr", "device_strs",
"hosts", "host_hdr", "host_strs", "version"
};
static int sg_proc_adio_read(char *buffer, char **start, off_t offset, static int sg_proc_adio_read(char *buffer, char **start, off_t offset,
int size, int *eof, void *data); int size, int *eof, void *data);
...@@ -2693,13 +2730,21 @@ static int sg_proc_version_read(char *buffer, char **start, off_t offset, ...@@ -2693,13 +2730,21 @@ static int sg_proc_version_read(char *buffer, char **start, off_t offset,
int size, int *eof, void *data); int size, int *eof, void *data);
static int sg_proc_version_info(char *buffer, int *len, off_t * begin, static int sg_proc_version_info(char *buffer, int *len, off_t * begin,
off_t offset, int size); off_t offset, int size);
static read_proc_t *sg_proc_leaf_reads[] = {
sg_proc_adio_read, sg_proc_dressz_read, sg_proc_debug_read, struct sg_proc_leaf {
sg_proc_dev_read, sg_proc_devhdr_read, sg_proc_devstrs_read, const char * name;
sg_proc_version_read read_proc_t * rf;
write_proc_t * wf;
}; };
static write_proc_t *sg_proc_leaf_writes[] = {
sg_proc_adio_write, sg_proc_dressz_write, 0, 0, 0, 0, 0, 0, 0, 0 static struct sg_proc_leaf sg_proc_leaf_arr[] = {
{"allow_dio", sg_proc_adio_read, sg_proc_adio_write},
{"def_reserved_size", sg_proc_dressz_read, sg_proc_dressz_write},
{"debug", sg_proc_debug_read, NULL},
{"devices", sg_proc_dev_read, NULL},
{"device_hdr", sg_proc_devhdr_read, NULL},
{"device_strs", sg_proc_devstrs_read, NULL},
{"version", sg_proc_version_read, NULL}
}; };
#define PRINT_PROC(fmt,args...) \ #define PRINT_PROC(fmt,args...) \
...@@ -2729,9 +2774,10 @@ static int ...@@ -2729,9 +2774,10 @@ static int
sg_proc_init() sg_proc_init()
{ {
int k, mask; int k, mask;
int leaves = int num_leaves =
sizeof (sg_proc_leaf_names) / sizeof (sg_proc_leaf_names[0]); sizeof (sg_proc_leaf_arr) / sizeof (sg_proc_leaf_arr[0]);
struct proc_dir_entry *pdep; struct proc_dir_entry *pdep;
struct sg_proc_leaf * leaf;
if (!proc_scsi) if (!proc_scsi)
return 1; return 1;
...@@ -2739,14 +2785,14 @@ sg_proc_init() ...@@ -2739,14 +2785,14 @@ sg_proc_init()
S_IFDIR | S_IRUGO | S_IXUGO, proc_scsi); S_IFDIR | S_IRUGO | S_IXUGO, proc_scsi);
if (!sg_proc_sgp) if (!sg_proc_sgp)
return 1; return 1;
for (k = 0; k < leaves; ++k) { for (k = 0; k < num_leaves; ++k) {
mask = sg_proc_leaf_writes[k] ? S_IRUGO | S_IWUSR : S_IRUGO; leaf = &sg_proc_leaf_arr[k];
pdep = mask = leaf->wf ? S_IRUGO | S_IWUSR : S_IRUGO;
create_proc_entry(sg_proc_leaf_names[k], mask, sg_proc_sgp); pdep = create_proc_entry(leaf->name, mask, sg_proc_sgp);
if (pdep) { if (pdep) {
pdep->read_proc = sg_proc_leaf_reads[k]; pdep->read_proc = leaf->rf;
if (sg_proc_leaf_writes[k]) if (leaf->wf)
pdep->write_proc = sg_proc_leaf_writes[k]; pdep->write_proc = leaf->wf;
} }
} }
return 0; return 0;
...@@ -2756,13 +2802,13 @@ static void ...@@ -2756,13 +2802,13 @@ static void
sg_proc_cleanup() sg_proc_cleanup()
{ {
int k; int k;
int leaves = int num_leaves =
sizeof (sg_proc_leaf_names) / sizeof (sg_proc_leaf_names[0]); sizeof (sg_proc_leaf_arr) / sizeof (sg_proc_leaf_arr[0]);
if ((!proc_scsi) || (!sg_proc_sgp)) if ((!proc_scsi) || (!sg_proc_sgp))
return; return;
for (k = 0; k < leaves; ++k) for (k = 0; k < num_leaves; ++k)
remove_proc_entry(sg_proc_leaf_names[k], sg_proc_sgp); remove_proc_entry(sg_proc_leaf_arr[k].name, sg_proc_sgp);
remove_proc_entry(sg_proc_sg_dirname, proc_scsi); remove_proc_entry(sg_proc_sg_dirname, proc_scsi);
} }
......
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