40 #include <linux/module.h>
42 #include <linux/kernel.h>
44 #include <linux/string.h>
45 #include <linux/slab.h>
58 #include <asm/unaligned.h>
60 #include <scsi/scsi.h>
72 #define CREATE_TRACE_POINTS
81 #define MIN_RESET_DELAY (2*HZ)
84 #define MIN_RESET_PERIOD (15*HZ)
91 #if defined(CONFIG_SCSI_LOGGING)
103 static const char *
const scsi_device_types[] = {
133 return "Well-known LUN ";
138 return scsi_device_types[
type];
154 .cmd_name =
"scsi_cmd_cache",
155 .sense_name =
"scsi_sense_cache",
160 .cmd_name =
"scsi_cmd_cache(DMA)",
161 .sense_name =
"scsi_sense_cache(DMA)",
227 cmd = scsi_pool_alloc_command(shost->
cmd_pool, gfp_mask);
235 scsi_pool_free_command(shost->
cmd_pool, cmd);
253 struct scsi_cmnd *cmd = scsi_host_alloc_command(shost, gfp_mask);
262 list_del_init(&cmd->
list);
272 memset(cmd, 0,
sizeof(*cmd));
304 INIT_LIST_HEAD(&cmd->
list);
307 spin_unlock_irqrestore(&dev->
list_lock, flags);
336 scsi_pool_free_command(shost->
cmd_pool, cmd);
358 list_del_init(&cmd->
list);
359 spin_unlock_irqrestore(&cmd->
device->list_lock, flags);
373 pool = (gfp_mask &
__GFP_DMA) ? &scsi_cmd_dma_pool :
378 pool->slab_flags,
NULL);
384 pool->slab_flags,
NULL);
385 if (!pool->sense_slab) {
398 static void scsi_put_host_cmd_pool(
gfp_t gfp_mask)
403 pool = (gfp_mask &
__GFP_DMA) ? &scsi_cmd_dma_pool :
412 if (!--pool->
users) {
439 return scsi_pool_alloc_command(pool, gfp_mask);
464 scsi_pool_free_command(pool, cmd);
470 scsi_put_host_cmd_pool(gfp_mask);
471 scsi_put_host_cmd_pool(gfp_mask);
493 shost->
cmd_pool = scsi_get_host_cmd_pool(gfp_mask);
501 cmd = scsi_host_alloc_command(shost, gfp_mask);
503 scsi_put_host_cmd_pool(gfp_mask);
528 list_del_init(&cmd->
list);
529 scsi_pool_free_command(shost->
cmd_pool, cmd);
535 #ifdef CONFIG_SCSI_LOGGING
536 void scsi_log_send(
struct scsi_cmnd *cmd)
562 " queuecommand 0x%p\n",
563 scsi_sglist(cmd), scsi_bufflen(cmd),
564 cmd->
device->host->hostt->queuecommand);
571 void scsi_log_completion(
struct scsi_cmnd *cmd,
int disposition)
590 if (((level > 0) && (cmd->
result || disposition !=
SUCCESS)) ||
599 switch (disposition) {
627 "scsi host busy %d failed %d\n",
628 cmd->
device->host->host_busy,
629 cmd->
device->host->host_failed);
703 cmd->
cmnd[1] = (cmd->
cmnd[1] & 0x1f) |
704 (cmd->
device->lun << 5 & 0xe0);
714 int ticks_remaining = timeout -
jiffies;
724 while (--ticks_remaining >= 0)
737 printk(
"queuecommand : command too long. "
738 "cdb_size=%d host->max_cmd_len=%d\n",
750 trace_scsi_dispatch_cmd_start(cmd);
752 rtn = host->
hostt->queuecommand(host, cmd);
756 trace_scsi_dispatch_cmd_error(cmd, rtn);
764 printk(
"queuecommand : request rejected\n"));
785 static void scsi_done(
struct scsi_cmnd *cmd)
787 trace_scsi_dispatch_cmd_done(cmd);
805 unsigned int good_bytes;
829 "Notifying upper driver of completion "
830 "(result %x)\n", cmd->
result));
832 good_bytes = scsi_bufflen(cmd);
833 if (cmd->
request->cmd_type != REQ_TYPE_BLOCK_PC) {
834 int old_good_bytes = good_bytes;
835 drv = scsi_cmd_to_driver(cmd);
837 good_bytes = drv->
done(cmd);
844 if (good_bytes == old_good_bytes)
845 good_bytes -= scsi_get_resid(cmd);
890 if (!sdev->
host->bqt) {
908 "scsi_adjust_queue_depth, bad queue type, "
916 spin_unlock_irqrestore(sdev->
request_queue->queue_lock, flags);
990 unsigned char cmd[16];
1009 if (buffer[1] != page)
1035 result = scsi_vpd_inquiry(sdev, buf, 0, buf_len);
1043 for (i = 0; i <
min((
int)buf[3], buf_len - 4); i++)
1044 if (buf[i + 4] == page)
1047 if (i < buf[3] && i >= buf_len - 4)
1054 result = scsi_vpd_inquiry(sdev, buf, page, buf_len);
1077 unsigned int len,
unsigned char opcode)
1079 unsigned char cmd[16];
1095 &sshdr, 30 *
HZ, 3,
NULL);
1097 if (result && scsi_sense_valid(&sshdr) &&
1099 (sshdr.
asc == 0x20 || sshdr.
asc == 0x24) && sshdr.
ascq == 0x00)
1102 if ((buffer[1] & 3) == 3)
1125 try_module_get(sdev->
host->hostt->module);
1141 #ifdef CONFIG_MODULE_UNLOAD
1146 if (module && module_refcount(module) != 0)
1159 unsigned long flags;
1170 spin_unlock_irqrestore(shost->
host_lock, flags);
1191 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
1196 (sdev->
id == starget->
id))
1219 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
1224 (sdev->
id == starget->
id))
1253 if (sdev->
lun ==lun)
1274 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
1275 unsigned long flags;
1281 spin_unlock_irqrestore(shost->
host_lock, flags);
1309 if (sdev->
channel == channel && sdev->
id ==
id &&
1333 unsigned long flags;
1339 spin_unlock_irqrestore(shost->
host_lock, flags);
1351 static int __init init_scsi(
void)
1363 goto cleanup_procfs;
1366 goto cleanup_devlist;
1372 goto cleanup_sysctl;
1389 printk(
KERN_ERR "SCSI subsystem failed to initialize, error = %d\n",
1394 static void __exit exit_scsi(
void)