aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r--drivers/scsi/scsi_lib.c119
1 files changed, 79 insertions, 40 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f2f51e0333eb..940dc32ff0dc 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -91,26 +91,19 @@ static void scsi_unprep_request(struct request *req)
91 scsi_put_command(cmd); 91 scsi_put_command(cmd);
92} 92}
93 93
94/* 94/**
95 * Function: scsi_queue_insert() 95 * __scsi_queue_insert - private queue insertion
96 * 96 * @cmd: The SCSI command being requeued
97 * Purpose: Insert a command in the midlevel queue. 97 * @reason: The reason for the requeue
98 * 98 * @unbusy: Whether the queue should be unbusied
99 * Arguments: cmd - command that we are adding to queue. 99 *
100 * reason - why we are inserting command to queue. 100 * This is a private queue insertion. The public interface
101 * 101 * scsi_queue_insert() always assumes the queue should be unbusied
102 * Lock status: Assumed that lock is not held upon entry. 102 * because it's always called before the completion. This function is
103 * 103 * for a requeue after completion, which should only occur in this
104 * Returns: Nothing. 104 * file.
105 *
106 * Notes: We do this for one of two cases. Either the host is busy
107 * and it cannot accept any more commands for the time being,
108 * or the device returned QUEUE_FULL and can accept no more
109 * commands.
110 * Notes: This could be called either from an interrupt context or a
111 * normal process context.
112 */ 105 */
113int scsi_queue_insert(struct scsi_cmnd *cmd, int reason) 106static int __scsi_queue_insert(struct scsi_cmnd *cmd, int reason, int unbusy)
114{ 107{
115 struct Scsi_Host *host = cmd->device->host; 108 struct Scsi_Host *host = cmd->device->host;
116 struct scsi_device *device = cmd->device; 109 struct scsi_device *device = cmd->device;
@@ -150,7 +143,8 @@ int scsi_queue_insert(struct scsi_cmnd *cmd, int reason)
150 * Decrement the counters, since these commands are no longer 143 * Decrement the counters, since these commands are no longer
151 * active on the host/device. 144 * active on the host/device.
152 */ 145 */
153 scsi_device_unbusy(device); 146 if (unbusy)
147 scsi_device_unbusy(device);
154 148
155 /* 149 /*
156 * Requeue this command. It will go before all other commands 150 * Requeue this command. It will go before all other commands
@@ -172,6 +166,29 @@ int scsi_queue_insert(struct scsi_cmnd *cmd, int reason)
172 return 0; 166 return 0;
173} 167}
174 168
169/*
170 * Function: scsi_queue_insert()
171 *
172 * Purpose: Insert a command in the midlevel queue.
173 *
174 * Arguments: cmd - command that we are adding to queue.
175 * reason - why we are inserting command to queue.
176 *
177 * Lock status: Assumed that lock is not held upon entry.
178 *
179 * Returns: Nothing.
180 *
181 * Notes: We do this for one of two cases. Either the host is busy
182 * and it cannot accept any more commands for the time being,
183 * or the device returned QUEUE_FULL and can accept no more
184 * commands.
185 * Notes: This could be called either from an interrupt context or a
186 * normal process context.
187 */
188int scsi_queue_insert(struct scsi_cmnd *cmd, int reason)
189{
190 return __scsi_queue_insert(cmd, reason, 1);
191}
175/** 192/**
176 * scsi_execute - insert request and wait for the result 193 * scsi_execute - insert request and wait for the result
177 * @sdev: scsi device 194 * @sdev: scsi device
@@ -684,6 +701,8 @@ void scsi_run_host_queues(struct Scsi_Host *shost)
684 scsi_run_queue(sdev->request_queue); 701 scsi_run_queue(sdev->request_queue);
685} 702}
686 703
704static void __scsi_release_buffers(struct scsi_cmnd *, int);
705
687/* 706/*
688 * Function: scsi_end_request() 707 * Function: scsi_end_request()
689 * 708 *
@@ -732,6 +751,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
732 * leftovers in the front of the 751 * leftovers in the front of the
733 * queue, and goose the queue again. 752 * queue, and goose the queue again.
734 */ 753 */
754 scsi_release_buffers(cmd);
735 scsi_requeue_command(q, cmd); 755 scsi_requeue_command(q, cmd);
736 cmd = NULL; 756 cmd = NULL;
737 } 757 }
@@ -743,6 +763,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
743 * This will goose the queue request function at the end, so we don't 763 * This will goose the queue request function at the end, so we don't
744 * need to worry about launching another command. 764 * need to worry about launching another command.
745 */ 765 */
766 __scsi_release_buffers(cmd, 0);
746 scsi_next_command(cmd); 767 scsi_next_command(cmd);
747 return NULL; 768 return NULL;
748} 769}
@@ -798,6 +819,26 @@ static void scsi_free_sgtable(struct scsi_data_buffer *sdb)
798 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free); 819 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free);
799} 820}
800 821
822static void __scsi_release_buffers(struct scsi_cmnd *cmd, int do_bidi_check)
823{
824
825 if (cmd->sdb.table.nents)
826 scsi_free_sgtable(&cmd->sdb);
827
828 memset(&cmd->sdb, 0, sizeof(cmd->sdb));
829
830 if (do_bidi_check && scsi_bidi_cmnd(cmd)) {
831 struct scsi_data_buffer *bidi_sdb =
832 cmd->request->next_rq->special;
833 scsi_free_sgtable(bidi_sdb);
834 kmem_cache_free(scsi_sdb_cache, bidi_sdb);
835 cmd->request->next_rq->special = NULL;
836 }
837
838 if (scsi_prot_sg_count(cmd))
839 scsi_free_sgtable(cmd->prot_sdb);
840}
841
801/* 842/*
802 * Function: scsi_release_buffers() 843 * Function: scsi_release_buffers()
803 * 844 *
@@ -817,21 +858,7 @@ static void scsi_free_sgtable(struct scsi_data_buffer *sdb)
817 */ 858 */
818void scsi_release_buffers(struct scsi_cmnd *cmd) 859void scsi_release_buffers(struct scsi_cmnd *cmd)
819{ 860{
820 if (cmd->sdb.table.nents) 861 __scsi_release_buffers(cmd, 1);
821 scsi_free_sgtable(&cmd->sdb);
822
823 memset(&cmd->sdb, 0, sizeof(cmd->sdb));
824
825 if (scsi_bidi_cmnd(cmd)) {
826 struct scsi_data_buffer *bidi_sdb =
827 cmd->request->next_rq->special;
828 scsi_free_sgtable(bidi_sdb);
829 kmem_cache_free(scsi_sdb_cache, bidi_sdb);
830 cmd->request->next_rq->special = NULL;
831 }
832
833 if (scsi_prot_sg_count(cmd))
834 scsi_free_sgtable(cmd->prot_sdb);
835} 862}
836EXPORT_SYMBOL(scsi_release_buffers); 863EXPORT_SYMBOL(scsi_release_buffers);
837 864
@@ -945,7 +972,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
945 } 972 }
946 973
947 BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */ 974 BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */
948 scsi_release_buffers(cmd);
949 975
950 /* 976 /*
951 * Next deal with any sectors which we were able to correctly 977 * Next deal with any sectors which we were able to correctly
@@ -963,6 +989,8 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
963 return; 989 return;
964 this_count = blk_rq_bytes(req); 990 this_count = blk_rq_bytes(req);
965 991
992 error = -EIO;
993
966 if (host_byte(result) == DID_RESET) { 994 if (host_byte(result) == DID_RESET) {
967 /* Third party bus reset or reset for error recovery 995 /* Third party bus reset or reset for error recovery
968 * reasons. Just retry the command and see what 996 * reasons. Just retry the command and see what
@@ -1004,13 +1032,18 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1004 /* This will issue a new 6-byte command. */ 1032 /* This will issue a new 6-byte command. */
1005 cmd->device->use_10_for_rw = 0; 1033 cmd->device->use_10_for_rw = 0;
1006 action = ACTION_REPREP; 1034 action = ACTION_REPREP;
1035 } else if (sshdr.asc == 0x10) /* DIX */ {
1036 description = "Host Data Integrity Failure";
1037 action = ACTION_FAIL;
1038 error = -EILSEQ;
1007 } else 1039 } else
1008 action = ACTION_FAIL; 1040 action = ACTION_FAIL;
1009 break; 1041 break;
1010 case ABORTED_COMMAND: 1042 case ABORTED_COMMAND:
1011 if (sshdr.asc == 0x10) { /* DIF */ 1043 if (sshdr.asc == 0x10) { /* DIF */
1044 description = "Target Data Integrity Failure";
1012 action = ACTION_FAIL; 1045 action = ACTION_FAIL;
1013 description = "Data Integrity Failure"; 1046 error = -EILSEQ;
1014 } else 1047 } else
1015 action = ACTION_RETRY; 1048 action = ACTION_RETRY;
1016 break; 1049 break;
@@ -1029,6 +1062,10 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1029 case 0x09: /* self test in progress */ 1062 case 0x09: /* self test in progress */
1030 action = ACTION_DELAYED_RETRY; 1063 action = ACTION_DELAYED_RETRY;
1031 break; 1064 break;
1065 default:
1066 description = "Device not ready";
1067 action = ACTION_FAIL;
1068 break;
1032 } 1069 }
1033 } else { 1070 } else {
1034 description = "Device not ready"; 1071 description = "Device not ready";
@@ -1052,9 +1089,10 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1052 switch (action) { 1089 switch (action) {
1053 case ACTION_FAIL: 1090 case ACTION_FAIL:
1054 /* Give up and fail the remainder of the request */ 1091 /* Give up and fail the remainder of the request */
1092 scsi_release_buffers(cmd);
1055 if (!(req->cmd_flags & REQ_QUIET)) { 1093 if (!(req->cmd_flags & REQ_QUIET)) {
1056 if (description) 1094 if (description)
1057 scmd_printk(KERN_INFO, cmd, "%s", 1095 scmd_printk(KERN_INFO, cmd, "%s\n",
1058 description); 1096 description);
1059 scsi_print_result(cmd); 1097 scsi_print_result(cmd);
1060 if (driver_byte(result) & DRIVER_SENSE) 1098 if (driver_byte(result) & DRIVER_SENSE)
@@ -1067,15 +1105,16 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1067 /* Unprep the request and put it back at the head of the queue. 1105 /* Unprep the request and put it back at the head of the queue.
1068 * A new command will be prepared and issued. 1106 * A new command will be prepared and issued.
1069 */ 1107 */
1108 scsi_release_buffers(cmd);
1070 scsi_requeue_command(q, cmd); 1109 scsi_requeue_command(q, cmd);
1071 break; 1110 break;
1072 case ACTION_RETRY: 1111 case ACTION_RETRY:
1073 /* Retry the same command immediately */ 1112 /* Retry the same command immediately */
1074 scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY); 1113 __scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY, 0);
1075 break; 1114 break;
1076 case ACTION_DELAYED_RETRY: 1115 case ACTION_DELAYED_RETRY:
1077 /* Retry the same command after a delay */ 1116 /* Retry the same command after a delay */
1078 scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY); 1117 __scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY, 0);
1079 break; 1118 break;
1080 } 1119 }
1081} 1120}