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.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ecfbbd30dce5..f2f51e0333eb 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -183,13 +183,15 @@ int scsi_queue_insert(struct scsi_cmnd *cmd, int reason)
183 * @timeout: request timeout in seconds 183 * @timeout: request timeout in seconds
184 * @retries: number of times to retry request 184 * @retries: number of times to retry request
185 * @flags: or into request flags; 185 * @flags: or into request flags;
186 * @resid: optional residual length
186 * 187 *
187 * returns the req->errors value which is the scsi_cmnd result 188 * returns the req->errors value which is the scsi_cmnd result
188 * field. 189 * field.
189 */ 190 */
190int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, 191int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
191 int data_direction, void *buffer, unsigned bufflen, 192 int data_direction, void *buffer, unsigned bufflen,
192 unsigned char *sense, int timeout, int retries, int flags) 193 unsigned char *sense, int timeout, int retries, int flags,
194 int *resid)
193{ 195{
194 struct request *req; 196 struct request *req;
195 int write = (data_direction == DMA_TO_DEVICE); 197 int write = (data_direction == DMA_TO_DEVICE);
@@ -224,6 +226,8 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
224 if (unlikely(req->data_len > 0 && req->data_len <= bufflen)) 226 if (unlikely(req->data_len > 0 && req->data_len <= bufflen))
225 memset(buffer + (bufflen - req->data_len), 0, req->data_len); 227 memset(buffer + (bufflen - req->data_len), 0, req->data_len);
226 228
229 if (resid)
230 *resid = req->data_len;
227 ret = req->errors; 231 ret = req->errors;
228 out: 232 out:
229 blk_put_request(req); 233 blk_put_request(req);
@@ -235,7 +239,8 @@ EXPORT_SYMBOL(scsi_execute);
235 239
236int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd, 240int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
237 int data_direction, void *buffer, unsigned bufflen, 241 int data_direction, void *buffer, unsigned bufflen,
238 struct scsi_sense_hdr *sshdr, int timeout, int retries) 242 struct scsi_sense_hdr *sshdr, int timeout, int retries,
243 int *resid)
239{ 244{
240 char *sense = NULL; 245 char *sense = NULL;
241 int result; 246 int result;
@@ -246,7 +251,7 @@ int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
246 return DRIVER_ERROR << 24; 251 return DRIVER_ERROR << 24;
247 } 252 }
248 result = scsi_execute(sdev, cmd, data_direction, buffer, bufflen, 253 result = scsi_execute(sdev, cmd, data_direction, buffer, bufflen,
249 sense, timeout, retries, 0); 254 sense, timeout, retries, 0, resid);
250 if (sshdr) 255 if (sshdr)
251 scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, sshdr); 256 scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, sshdr);
252 257
@@ -2016,7 +2021,7 @@ scsi_mode_select(struct scsi_device *sdev, int pf, int sp, int modepage,
2016 } 2021 }
2017 2022
2018 ret = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, real_buffer, len, 2023 ret = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, real_buffer, len,
2019 sshdr, timeout, retries); 2024 sshdr, timeout, retries, NULL);
2020 kfree(real_buffer); 2025 kfree(real_buffer);
2021 return ret; 2026 return ret;
2022} 2027}
@@ -2081,7 +2086,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
2081 memset(buffer, 0, len); 2086 memset(buffer, 0, len);
2082 2087
2083 result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer, len, 2088 result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer, len,
2084 sshdr, timeout, retries); 2089 sshdr, timeout, retries, NULL);
2085 2090
2086 /* This code looks awful: what it's doing is making sure an 2091 /* This code looks awful: what it's doing is making sure an
2087 * ILLEGAL REQUEST sense return identifies the actual command 2092 * ILLEGAL REQUEST sense return identifies the actual command
@@ -2163,7 +2168,7 @@ scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries,
2163 /* try to eat the UNIT_ATTENTION if there are enough retries */ 2168 /* try to eat the UNIT_ATTENTION if there are enough retries */
2164 do { 2169 do {
2165 result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, sshdr, 2170 result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, sshdr,
2166 timeout, retries); 2171 timeout, retries, NULL);
2167 if (sdev->removable && scsi_sense_valid(sshdr) && 2172 if (sdev->removable && scsi_sense_valid(sshdr) &&
2168 sshdr->sense_key == UNIT_ATTENTION) 2173 sshdr->sense_key == UNIT_ATTENTION)
2169 sdev->changed = 1; 2174 sdev->changed = 1;