diff options
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r-- | drivers/scsi/libata-core.c | 362 |
1 files changed, 202 insertions, 160 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index d0a0fdbd0fc4..9ea102587914 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -605,7 +605,7 @@ void ata_rwcmd_protocol(struct ata_queued_cmd *qc) | |||
605 | tf->command = ata_rw_cmds[index + lba48 + write]; | 605 | tf->command = ata_rw_cmds[index + lba48 + write]; |
606 | } | 606 | } |
607 | 607 | ||
608 | static const char * xfer_mode_str[] = { | 608 | static const char * const xfer_mode_str[] = { |
609 | "UDMA/16", | 609 | "UDMA/16", |
610 | "UDMA/25", | 610 | "UDMA/25", |
611 | "UDMA/33", | 611 | "UDMA/33", |
@@ -1046,28 +1046,103 @@ static unsigned int ata_pio_modes(const struct ata_device *adev) | |||
1046 | return modes; | 1046 | return modes; |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | static int ata_qc_wait_err(struct ata_queued_cmd *qc, | 1049 | struct ata_exec_internal_arg { |
1050 | struct completion *wait) | 1050 | unsigned int err_mask; |
1051 | struct ata_taskfile *tf; | ||
1052 | struct completion *waiting; | ||
1053 | }; | ||
1054 | |||
1055 | int ata_qc_complete_internal(struct ata_queued_cmd *qc) | ||
1051 | { | 1056 | { |
1052 | int rc = 0; | 1057 | struct ata_exec_internal_arg *arg = qc->private_data; |
1058 | struct completion *waiting = arg->waiting; | ||
1053 | 1059 | ||
1054 | if (wait_for_completion_timeout(wait, 30 * HZ) < 1) { | 1060 | if (!(qc->err_mask & ~AC_ERR_DEV)) |
1055 | /* timeout handling */ | 1061 | qc->ap->ops->tf_read(qc->ap, arg->tf); |
1056 | unsigned int err_mask = ac_err_mask(ata_chk_status(qc->ap)); | 1062 | arg->err_mask = qc->err_mask; |
1063 | arg->waiting = NULL; | ||
1064 | complete(waiting); | ||
1057 | 1065 | ||
1058 | if (!err_mask) { | 1066 | return 0; |
1059 | printk(KERN_WARNING "ata%u: slow completion (cmd %x)\n", | 1067 | } |
1060 | qc->ap->id, qc->tf.command); | 1068 | |
1061 | } else { | 1069 | /** |
1062 | printk(KERN_WARNING "ata%u: qc timeout (cmd %x)\n", | 1070 | * ata_exec_internal - execute libata internal command |
1063 | qc->ap->id, qc->tf.command); | 1071 | * @ap: Port to which the command is sent |
1064 | rc = -EIO; | 1072 | * @dev: Device to which the command is sent |
1073 | * @tf: Taskfile registers for the command and the result | ||
1074 | * @dma_dir: Data tranfer direction of the command | ||
1075 | * @buf: Data buffer of the command | ||
1076 | * @buflen: Length of data buffer | ||
1077 | * | ||
1078 | * Executes libata internal command with timeout. @tf contains | ||
1079 | * command on entry and result on return. Timeout and error | ||
1080 | * conditions are reported via return value. No recovery action | ||
1081 | * is taken after a command times out. It's caller's duty to | ||
1082 | * clean up after timeout. | ||
1083 | * | ||
1084 | * LOCKING: | ||
1085 | * None. Should be called with kernel context, might sleep. | ||
1086 | */ | ||
1087 | |||
1088 | static unsigned | ||
1089 | ata_exec_internal(struct ata_port *ap, struct ata_device *dev, | ||
1090 | struct ata_taskfile *tf, | ||
1091 | int dma_dir, void *buf, unsigned int buflen) | ||
1092 | { | ||
1093 | u8 command = tf->command; | ||
1094 | struct ata_queued_cmd *qc; | ||
1095 | DECLARE_COMPLETION(wait); | ||
1096 | unsigned long flags; | ||
1097 | struct ata_exec_internal_arg arg; | ||
1098 | |||
1099 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
1100 | |||
1101 | qc = ata_qc_new_init(ap, dev); | ||
1102 | BUG_ON(qc == NULL); | ||
1103 | |||
1104 | qc->tf = *tf; | ||
1105 | qc->dma_dir = dma_dir; | ||
1106 | if (dma_dir != DMA_NONE) { | ||
1107 | ata_sg_init_one(qc, buf, buflen); | ||
1108 | qc->nsect = buflen / ATA_SECT_SIZE; | ||
1109 | } | ||
1110 | |||
1111 | arg.waiting = &wait; | ||
1112 | arg.tf = tf; | ||
1113 | qc->private_data = &arg; | ||
1114 | qc->complete_fn = ata_qc_complete_internal; | ||
1115 | |||
1116 | if (ata_qc_issue(qc)) | ||
1117 | goto issue_fail; | ||
1118 | |||
1119 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
1120 | |||
1121 | if (!wait_for_completion_timeout(&wait, ATA_TMOUT_INTERNAL)) { | ||
1122 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
1123 | |||
1124 | /* We're racing with irq here. If we lose, the | ||
1125 | * following test prevents us from completing the qc | ||
1126 | * again. If completion irq occurs after here but | ||
1127 | * before the caller cleans up, it will result in a | ||
1128 | * spurious interrupt. We can live with that. | ||
1129 | */ | ||
1130 | if (arg.waiting) { | ||
1131 | qc->err_mask = AC_ERR_OTHER; | ||
1132 | ata_qc_complete(qc); | ||
1133 | printk(KERN_WARNING "ata%u: qc timeout (cmd 0x%x)\n", | ||
1134 | ap->id, command); | ||
1065 | } | 1135 | } |
1066 | 1136 | ||
1067 | ata_qc_complete(qc, err_mask); | 1137 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
1068 | } | 1138 | } |
1069 | 1139 | ||
1070 | return rc; | 1140 | return arg.err_mask; |
1141 | |||
1142 | issue_fail: | ||
1143 | ata_qc_free(qc); | ||
1144 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
1145 | return AC_ERR_OTHER; | ||
1071 | } | 1146 | } |
1072 | 1147 | ||
1073 | /** | 1148 | /** |
@@ -1099,9 +1174,8 @@ static void ata_dev_identify(struct ata_port *ap, unsigned int device) | |||
1099 | u16 tmp; | 1174 | u16 tmp; |
1100 | unsigned long xfer_modes; | 1175 | unsigned long xfer_modes; |
1101 | unsigned int using_edd; | 1176 | unsigned int using_edd; |
1102 | DECLARE_COMPLETION(wait); | 1177 | struct ata_taskfile tf; |
1103 | struct ata_queued_cmd *qc; | 1178 | unsigned int err_mask; |
1104 | unsigned long flags; | ||
1105 | int rc; | 1179 | int rc; |
1106 | 1180 | ||
1107 | if (!ata_dev_present(dev)) { | 1181 | if (!ata_dev_present(dev)) { |
@@ -1122,40 +1196,26 @@ static void ata_dev_identify(struct ata_port *ap, unsigned int device) | |||
1122 | 1196 | ||
1123 | ata_dev_select(ap, device, 1, 1); /* select device 0/1 */ | 1197 | ata_dev_select(ap, device, 1, 1); /* select device 0/1 */ |
1124 | 1198 | ||
1125 | qc = ata_qc_new_init(ap, dev); | ||
1126 | BUG_ON(qc == NULL); | ||
1127 | |||
1128 | ata_sg_init_one(qc, dev->id, sizeof(dev->id)); | ||
1129 | qc->dma_dir = DMA_FROM_DEVICE; | ||
1130 | qc->tf.protocol = ATA_PROT_PIO; | ||
1131 | qc->nsect = 1; | ||
1132 | |||
1133 | retry: | 1199 | retry: |
1200 | ata_tf_init(ap, &tf, device); | ||
1201 | |||
1134 | if (dev->class == ATA_DEV_ATA) { | 1202 | if (dev->class == ATA_DEV_ATA) { |
1135 | qc->tf.command = ATA_CMD_ID_ATA; | 1203 | tf.command = ATA_CMD_ID_ATA; |
1136 | DPRINTK("do ATA identify\n"); | 1204 | DPRINTK("do ATA identify\n"); |
1137 | } else { | 1205 | } else { |
1138 | qc->tf.command = ATA_CMD_ID_ATAPI; | 1206 | tf.command = ATA_CMD_ID_ATAPI; |
1139 | DPRINTK("do ATAPI identify\n"); | 1207 | DPRINTK("do ATAPI identify\n"); |
1140 | } | 1208 | } |
1141 | 1209 | ||
1142 | qc->waiting = &wait; | 1210 | tf.protocol = ATA_PROT_PIO; |
1143 | qc->complete_fn = ata_qc_complete_noop; | ||
1144 | 1211 | ||
1145 | spin_lock_irqsave(&ap->host_set->lock, flags); | 1212 | err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, |
1146 | rc = ata_qc_issue(qc); | 1213 | dev->id, sizeof(dev->id)); |
1147 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
1148 | |||
1149 | if (rc) | ||
1150 | goto err_out; | ||
1151 | else | ||
1152 | ata_qc_wait_err(qc, &wait); | ||
1153 | 1214 | ||
1154 | spin_lock_irqsave(&ap->host_set->lock, flags); | 1215 | if (err_mask) { |
1155 | ap->ops->tf_read(ap, &qc->tf); | 1216 | if (err_mask & ~AC_ERR_DEV) |
1156 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | 1217 | goto err_out; |
1157 | 1218 | ||
1158 | if (qc->tf.command & ATA_ERR) { | ||
1159 | /* | 1219 | /* |
1160 | * arg! EDD works for all test cases, but seems to return | 1220 | * arg! EDD works for all test cases, but seems to return |
1161 | * the ATA signature for some ATAPI devices. Until the | 1221 | * the ATA signature for some ATAPI devices. Until the |
@@ -1168,13 +1228,9 @@ retry: | |||
1168 | * to have this problem. | 1228 | * to have this problem. |
1169 | */ | 1229 | */ |
1170 | if ((using_edd) && (dev->class == ATA_DEV_ATA)) { | 1230 | if ((using_edd) && (dev->class == ATA_DEV_ATA)) { |
1171 | u8 err = qc->tf.feature; | 1231 | u8 err = tf.feature; |
1172 | if (err & ATA_ABORTED) { | 1232 | if (err & ATA_ABORTED) { |
1173 | dev->class = ATA_DEV_ATAPI; | 1233 | dev->class = ATA_DEV_ATAPI; |
1174 | qc->cursg = 0; | ||
1175 | qc->cursg_ofs = 0; | ||
1176 | qc->cursect = 0; | ||
1177 | qc->nsect = 1; | ||
1178 | goto retry; | 1234 | goto retry; |
1179 | } | 1235 | } |
1180 | } | 1236 | } |
@@ -1444,11 +1500,23 @@ void __sata_phy_reset(struct ata_port *ap) | |||
1444 | } while (time_before(jiffies, timeout)); | 1500 | } while (time_before(jiffies, timeout)); |
1445 | 1501 | ||
1446 | /* TODO: phy layer with polling, timeouts, etc. */ | 1502 | /* TODO: phy layer with polling, timeouts, etc. */ |
1447 | if (sata_dev_present(ap)) | 1503 | sstatus = scr_read(ap, SCR_STATUS); |
1504 | if (sata_dev_present(ap)) { | ||
1505 | const char *speed; | ||
1506 | u32 tmp; | ||
1507 | |||
1508 | tmp = (sstatus >> 4) & 0xf; | ||
1509 | if (tmp & (1 << 0)) | ||
1510 | speed = "1.5"; | ||
1511 | else if (tmp & (1 << 1)) | ||
1512 | speed = "3.0"; | ||
1513 | else | ||
1514 | speed = "<unknown>"; | ||
1515 | printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n", | ||
1516 | ap->id, speed, sstatus); | ||
1448 | ata_port_probe(ap); | 1517 | ata_port_probe(ap); |
1449 | else { | 1518 | } else { |
1450 | sstatus = scr_read(ap, SCR_STATUS); | 1519 | printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n", |
1451 | printk(KERN_INFO "ata%u: no device found (phy stat %08x)\n", | ||
1452 | ap->id, sstatus); | 1520 | ap->id, sstatus); |
1453 | ata_port_disable(ap); | 1521 | ata_port_disable(ap); |
1454 | } | 1522 | } |
@@ -2071,7 +2139,7 @@ static void ata_pr_blacklisted(const struct ata_port *ap, | |||
2071 | ap->id, dev->devno); | 2139 | ap->id, dev->devno); |
2072 | } | 2140 | } |
2073 | 2141 | ||
2074 | static const char * ata_dma_blacklist [] = { | 2142 | static const char * const ata_dma_blacklist [] = { |
2075 | "WDC AC11000H", | 2143 | "WDC AC11000H", |
2076 | "WDC AC22100H", | 2144 | "WDC AC22100H", |
2077 | "WDC AC32500H", | 2145 | "WDC AC32500H", |
@@ -2266,34 +2334,23 @@ static int ata_choose_xfer_mode(const struct ata_port *ap, | |||
2266 | 2334 | ||
2267 | static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) | 2335 | static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) |
2268 | { | 2336 | { |
2269 | DECLARE_COMPLETION(wait); | 2337 | struct ata_taskfile tf; |
2270 | struct ata_queued_cmd *qc; | ||
2271 | int rc; | ||
2272 | unsigned long flags; | ||
2273 | 2338 | ||
2274 | /* set up set-features taskfile */ | 2339 | /* set up set-features taskfile */ |
2275 | DPRINTK("set features - xfer mode\n"); | 2340 | DPRINTK("set features - xfer mode\n"); |
2276 | 2341 | ||
2277 | qc = ata_qc_new_init(ap, dev); | 2342 | ata_tf_init(ap, &tf, dev->devno); |
2278 | BUG_ON(qc == NULL); | 2343 | tf.command = ATA_CMD_SET_FEATURES; |
2279 | 2344 | tf.feature = SETFEATURES_XFER; | |
2280 | qc->tf.command = ATA_CMD_SET_FEATURES; | 2345 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
2281 | qc->tf.feature = SETFEATURES_XFER; | 2346 | tf.protocol = ATA_PROT_NODATA; |
2282 | qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | 2347 | tf.nsect = dev->xfer_mode; |
2283 | qc->tf.protocol = ATA_PROT_NODATA; | ||
2284 | qc->tf.nsect = dev->xfer_mode; | ||
2285 | |||
2286 | qc->waiting = &wait; | ||
2287 | qc->complete_fn = ata_qc_complete_noop; | ||
2288 | |||
2289 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
2290 | rc = ata_qc_issue(qc); | ||
2291 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
2292 | 2348 | ||
2293 | if (rc) | 2349 | if (ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0)) { |
2350 | printk(KERN_ERR "ata%u: failed to set xfermode, disabled\n", | ||
2351 | ap->id); | ||
2294 | ata_port_disable(ap); | 2352 | ata_port_disable(ap); |
2295 | else | 2353 | } |
2296 | ata_qc_wait_err(qc, &wait); | ||
2297 | 2354 | ||
2298 | DPRINTK("EXIT\n"); | 2355 | DPRINTK("EXIT\n"); |
2299 | } | 2356 | } |
@@ -2308,41 +2365,25 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) | |||
2308 | 2365 | ||
2309 | static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev) | 2366 | static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev) |
2310 | { | 2367 | { |
2311 | DECLARE_COMPLETION(wait); | 2368 | struct ata_taskfile tf; |
2312 | struct ata_queued_cmd *qc; | ||
2313 | unsigned long flags; | ||
2314 | int rc; | ||
2315 | |||
2316 | qc = ata_qc_new_init(ap, dev); | ||
2317 | BUG_ON(qc == NULL); | ||
2318 | 2369 | ||
2319 | ata_sg_init_one(qc, dev->id, sizeof(dev->id)); | 2370 | ata_tf_init(ap, &tf, dev->devno); |
2320 | qc->dma_dir = DMA_FROM_DEVICE; | ||
2321 | 2371 | ||
2322 | if (dev->class == ATA_DEV_ATA) { | 2372 | if (dev->class == ATA_DEV_ATA) { |
2323 | qc->tf.command = ATA_CMD_ID_ATA; | 2373 | tf.command = ATA_CMD_ID_ATA; |
2324 | DPRINTK("do ATA identify\n"); | 2374 | DPRINTK("do ATA identify\n"); |
2325 | } else { | 2375 | } else { |
2326 | qc->tf.command = ATA_CMD_ID_ATAPI; | 2376 | tf.command = ATA_CMD_ID_ATAPI; |
2327 | DPRINTK("do ATAPI identify\n"); | 2377 | DPRINTK("do ATAPI identify\n"); |
2328 | } | 2378 | } |
2329 | 2379 | ||
2330 | qc->tf.flags |= ATA_TFLAG_DEVICE; | 2380 | tf.flags |= ATA_TFLAG_DEVICE; |
2331 | qc->tf.protocol = ATA_PROT_PIO; | 2381 | tf.protocol = ATA_PROT_PIO; |
2332 | qc->nsect = 1; | ||
2333 | |||
2334 | qc->waiting = &wait; | ||
2335 | qc->complete_fn = ata_qc_complete_noop; | ||
2336 | |||
2337 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
2338 | rc = ata_qc_issue(qc); | ||
2339 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
2340 | 2382 | ||
2341 | if (rc) | 2383 | if (ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, |
2384 | dev->id, sizeof(dev->id))) | ||
2342 | goto err_out; | 2385 | goto err_out; |
2343 | 2386 | ||
2344 | ata_qc_wait_err(qc, &wait); | ||
2345 | |||
2346 | swap_buf_le16(dev->id, ATA_ID_WORDS); | 2387 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
2347 | 2388 | ||
2348 | ata_dump_id(dev); | 2389 | ata_dump_id(dev); |
@@ -2351,6 +2392,7 @@ static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev) | |||
2351 | 2392 | ||
2352 | return; | 2393 | return; |
2353 | err_out: | 2394 | err_out: |
2395 | printk(KERN_ERR "ata%u: failed to reread ID, disabled\n", ap->id); | ||
2354 | ata_port_disable(ap); | 2396 | ata_port_disable(ap); |
2355 | } | 2397 | } |
2356 | 2398 | ||
@@ -2364,10 +2406,7 @@ err_out: | |||
2364 | 2406 | ||
2365 | static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev) | 2407 | static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev) |
2366 | { | 2408 | { |
2367 | DECLARE_COMPLETION(wait); | 2409 | struct ata_taskfile tf; |
2368 | struct ata_queued_cmd *qc; | ||
2369 | int rc; | ||
2370 | unsigned long flags; | ||
2371 | u16 sectors = dev->id[6]; | 2410 | u16 sectors = dev->id[6]; |
2372 | u16 heads = dev->id[3]; | 2411 | u16 heads = dev->id[3]; |
2373 | 2412 | ||
@@ -2378,26 +2417,18 @@ static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev) | |||
2378 | /* set up init dev params taskfile */ | 2417 | /* set up init dev params taskfile */ |
2379 | DPRINTK("init dev params \n"); | 2418 | DPRINTK("init dev params \n"); |
2380 | 2419 | ||
2381 | qc = ata_qc_new_init(ap, dev); | 2420 | ata_tf_init(ap, &tf, dev->devno); |
2382 | BUG_ON(qc == NULL); | 2421 | tf.command = ATA_CMD_INIT_DEV_PARAMS; |
2383 | 2422 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | |
2384 | qc->tf.command = ATA_CMD_INIT_DEV_PARAMS; | 2423 | tf.protocol = ATA_PROT_NODATA; |
2385 | qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | 2424 | tf.nsect = sectors; |
2386 | qc->tf.protocol = ATA_PROT_NODATA; | 2425 | tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ |
2387 | qc->tf.nsect = sectors; | ||
2388 | qc->tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ | ||
2389 | |||
2390 | qc->waiting = &wait; | ||
2391 | qc->complete_fn = ata_qc_complete_noop; | ||
2392 | |||
2393 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
2394 | rc = ata_qc_issue(qc); | ||
2395 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
2396 | 2426 | ||
2397 | if (rc) | 2427 | if (ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0)) { |
2428 | printk(KERN_ERR "ata%u: failed to init parameters, disabled\n", | ||
2429 | ap->id); | ||
2398 | ata_port_disable(ap); | 2430 | ata_port_disable(ap); |
2399 | else | 2431 | } |
2400 | ata_qc_wait_err(qc, &wait); | ||
2401 | 2432 | ||
2402 | DPRINTK("EXIT\n"); | 2433 | DPRINTK("EXIT\n"); |
2403 | } | 2434 | } |
@@ -2765,7 +2796,7 @@ skip_map: | |||
2765 | * None. (grabs host lock) | 2796 | * None. (grabs host lock) |
2766 | */ | 2797 | */ |
2767 | 2798 | ||
2768 | void ata_poll_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask) | 2799 | void ata_poll_qc_complete(struct ata_queued_cmd *qc) |
2769 | { | 2800 | { |
2770 | struct ata_port *ap = qc->ap; | 2801 | struct ata_port *ap = qc->ap; |
2771 | unsigned long flags; | 2802 | unsigned long flags; |
@@ -2773,7 +2804,7 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask) | |||
2773 | spin_lock_irqsave(&ap->host_set->lock, flags); | 2804 | spin_lock_irqsave(&ap->host_set->lock, flags); |
2774 | ap->flags &= ~ATA_FLAG_NOINTR; | 2805 | ap->flags &= ~ATA_FLAG_NOINTR; |
2775 | ata_irq_on(ap); | 2806 | ata_irq_on(ap); |
2776 | ata_qc_complete(qc, err_mask); | 2807 | ata_qc_complete(qc); |
2777 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | 2808 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
2778 | } | 2809 | } |
2779 | 2810 | ||
@@ -2790,10 +2821,14 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask) | |||
2790 | 2821 | ||
2791 | static unsigned long ata_pio_poll(struct ata_port *ap) | 2822 | static unsigned long ata_pio_poll(struct ata_port *ap) |
2792 | { | 2823 | { |
2824 | struct ata_queued_cmd *qc; | ||
2793 | u8 status; | 2825 | u8 status; |
2794 | unsigned int poll_state = HSM_ST_UNKNOWN; | 2826 | unsigned int poll_state = HSM_ST_UNKNOWN; |
2795 | unsigned int reg_state = HSM_ST_UNKNOWN; | 2827 | unsigned int reg_state = HSM_ST_UNKNOWN; |
2796 | 2828 | ||
2829 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
2830 | assert(qc != NULL); | ||
2831 | |||
2797 | switch (ap->hsm_task_state) { | 2832 | switch (ap->hsm_task_state) { |
2798 | case HSM_ST: | 2833 | case HSM_ST: |
2799 | case HSM_ST_POLL: | 2834 | case HSM_ST_POLL: |
@@ -2813,6 +2848,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap) | |||
2813 | status = ata_chk_status(ap); | 2848 | status = ata_chk_status(ap); |
2814 | if (status & ATA_BUSY) { | 2849 | if (status & ATA_BUSY) { |
2815 | if (time_after(jiffies, ap->pio_task_timeout)) { | 2850 | if (time_after(jiffies, ap->pio_task_timeout)) { |
2851 | qc->err_mask |= AC_ERR_ATA_BUS; | ||
2816 | ap->hsm_task_state = HSM_ST_TMOUT; | 2852 | ap->hsm_task_state = HSM_ST_TMOUT; |
2817 | return 0; | 2853 | return 0; |
2818 | } | 2854 | } |
@@ -2847,29 +2883,31 @@ static int ata_pio_complete (struct ata_port *ap) | |||
2847 | * msecs, then chk-status again. If still busy, fall back to | 2883 | * msecs, then chk-status again. If still busy, fall back to |
2848 | * HSM_ST_POLL state. | 2884 | * HSM_ST_POLL state. |
2849 | */ | 2885 | */ |
2850 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); | 2886 | drv_stat = ata_busy_wait(ap, ATA_BUSY, 10); |
2851 | if (drv_stat & (ATA_BUSY | ATA_DRQ)) { | 2887 | if (drv_stat & ATA_BUSY) { |
2852 | msleep(2); | 2888 | msleep(2); |
2853 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); | 2889 | drv_stat = ata_busy_wait(ap, ATA_BUSY, 10); |
2854 | if (drv_stat & (ATA_BUSY | ATA_DRQ)) { | 2890 | if (drv_stat & ATA_BUSY) { |
2855 | ap->hsm_task_state = HSM_ST_LAST_POLL; | 2891 | ap->hsm_task_state = HSM_ST_LAST_POLL; |
2856 | ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; | 2892 | ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; |
2857 | return 0; | 2893 | return 0; |
2858 | } | 2894 | } |
2859 | } | 2895 | } |
2860 | 2896 | ||
2897 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
2898 | assert(qc != NULL); | ||
2899 | |||
2861 | drv_stat = ata_wait_idle(ap); | 2900 | drv_stat = ata_wait_idle(ap); |
2862 | if (!ata_ok(drv_stat)) { | 2901 | if (!ata_ok(drv_stat)) { |
2902 | qc->err_mask |= __ac_err_mask(drv_stat); | ||
2863 | ap->hsm_task_state = HSM_ST_ERR; | 2903 | ap->hsm_task_state = HSM_ST_ERR; |
2864 | return 0; | 2904 | return 0; |
2865 | } | 2905 | } |
2866 | 2906 | ||
2867 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
2868 | assert(qc != NULL); | ||
2869 | |||
2870 | ap->hsm_task_state = HSM_ST_IDLE; | 2907 | ap->hsm_task_state = HSM_ST_IDLE; |
2871 | 2908 | ||
2872 | ata_poll_qc_complete(qc, 0); | 2909 | assert(qc->err_mask == 0); |
2910 | ata_poll_qc_complete(qc); | ||
2873 | 2911 | ||
2874 | /* another command may start at this point */ | 2912 | /* another command may start at this point */ |
2875 | 2913 | ||
@@ -3177,6 +3215,7 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc) | |||
3177 | err_out: | 3215 | err_out: |
3178 | printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", | 3216 | printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", |
3179 | ap->id, dev->devno); | 3217 | ap->id, dev->devno); |
3218 | qc->err_mask |= AC_ERR_ATA_BUS; | ||
3180 | ap->hsm_task_state = HSM_ST_ERR; | 3219 | ap->hsm_task_state = HSM_ST_ERR; |
3181 | } | 3220 | } |
3182 | 3221 | ||
@@ -3215,8 +3254,16 @@ static void ata_pio_block(struct ata_port *ap) | |||
3215 | qc = ata_qc_from_tag(ap, ap->active_tag); | 3254 | qc = ata_qc_from_tag(ap, ap->active_tag); |
3216 | assert(qc != NULL); | 3255 | assert(qc != NULL); |
3217 | 3256 | ||
3257 | /* check error */ | ||
3258 | if (status & (ATA_ERR | ATA_DF)) { | ||
3259 | qc->err_mask |= AC_ERR_DEV; | ||
3260 | ap->hsm_task_state = HSM_ST_ERR; | ||
3261 | return; | ||
3262 | } | ||
3263 | |||
3264 | /* transfer data if any */ | ||
3218 | if (is_atapi_taskfile(&qc->tf)) { | 3265 | if (is_atapi_taskfile(&qc->tf)) { |
3219 | /* no more data to transfer or unsupported ATAPI command */ | 3266 | /* DRQ=0 means no more data to transfer */ |
3220 | if ((status & ATA_DRQ) == 0) { | 3267 | if ((status & ATA_DRQ) == 0) { |
3221 | ap->hsm_task_state = HSM_ST_LAST; | 3268 | ap->hsm_task_state = HSM_ST_LAST; |
3222 | return; | 3269 | return; |
@@ -3226,6 +3273,7 @@ static void ata_pio_block(struct ata_port *ap) | |||
3226 | } else { | 3273 | } else { |
3227 | /* handle BSY=0, DRQ=0 as error */ | 3274 | /* handle BSY=0, DRQ=0 as error */ |
3228 | if ((status & ATA_DRQ) == 0) { | 3275 | if ((status & ATA_DRQ) == 0) { |
3276 | qc->err_mask |= AC_ERR_ATA_BUS; | ||
3229 | ap->hsm_task_state = HSM_ST_ERR; | 3277 | ap->hsm_task_state = HSM_ST_ERR; |
3230 | return; | 3278 | return; |
3231 | } | 3279 | } |
@@ -3243,9 +3291,14 @@ static void ata_pio_error(struct ata_port *ap) | |||
3243 | qc = ata_qc_from_tag(ap, ap->active_tag); | 3291 | qc = ata_qc_from_tag(ap, ap->active_tag); |
3244 | assert(qc != NULL); | 3292 | assert(qc != NULL); |
3245 | 3293 | ||
3294 | /* make sure qc->err_mask is available to | ||
3295 | * know what's wrong and recover | ||
3296 | */ | ||
3297 | assert(qc->err_mask); | ||
3298 | |||
3246 | ap->hsm_task_state = HSM_ST_IDLE; | 3299 | ap->hsm_task_state = HSM_ST_IDLE; |
3247 | 3300 | ||
3248 | ata_poll_qc_complete(qc, AC_ERR_ATA_BUS); | 3301 | ata_poll_qc_complete(qc); |
3249 | } | 3302 | } |
3250 | 3303 | ||
3251 | static void ata_pio_task(void *_data) | 3304 | static void ata_pio_task(void *_data) |
@@ -3347,7 +3400,8 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
3347 | ap->id, qc->tf.command, drv_stat, host_stat); | 3400 | ap->id, qc->tf.command, drv_stat, host_stat); |
3348 | 3401 | ||
3349 | /* complete taskfile transaction */ | 3402 | /* complete taskfile transaction */ |
3350 | ata_qc_complete(qc, ac_err_mask(drv_stat)); | 3403 | qc->err_mask |= ac_err_mask(drv_stat); |
3404 | ata_qc_complete(qc); | ||
3351 | break; | 3405 | break; |
3352 | } | 3406 | } |
3353 | 3407 | ||
@@ -3446,15 +3500,10 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, | |||
3446 | return qc; | 3500 | return qc; |
3447 | } | 3501 | } |
3448 | 3502 | ||
3449 | int ata_qc_complete_noop(struct ata_queued_cmd *qc, unsigned int err_mask) | ||
3450 | { | ||
3451 | return 0; | ||
3452 | } | ||
3453 | |||
3454 | static void __ata_qc_complete(struct ata_queued_cmd *qc) | 3503 | static void __ata_qc_complete(struct ata_queued_cmd *qc) |
3455 | { | 3504 | { |
3456 | struct ata_port *ap = qc->ap; | 3505 | struct ata_port *ap = qc->ap; |
3457 | unsigned int tag, do_clear = 0; | 3506 | unsigned int tag; |
3458 | 3507 | ||
3459 | qc->flags = 0; | 3508 | qc->flags = 0; |
3460 | tag = qc->tag; | 3509 | tag = qc->tag; |
@@ -3462,17 +3511,8 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc) | |||
3462 | if (tag == ap->active_tag) | 3511 | if (tag == ap->active_tag) |
3463 | ap->active_tag = ATA_TAG_POISON; | 3512 | ap->active_tag = ATA_TAG_POISON; |
3464 | qc->tag = ATA_TAG_POISON; | 3513 | qc->tag = ATA_TAG_POISON; |
3465 | do_clear = 1; | ||
3466 | } | ||
3467 | |||
3468 | if (qc->waiting) { | ||
3469 | struct completion *waiting = qc->waiting; | ||
3470 | qc->waiting = NULL; | ||
3471 | complete(waiting); | ||
3472 | } | ||
3473 | |||
3474 | if (likely(do_clear)) | ||
3475 | clear_bit(tag, &ap->qactive); | 3514 | clear_bit(tag, &ap->qactive); |
3515 | } | ||
3476 | } | 3516 | } |
3477 | 3517 | ||
3478 | /** | 3518 | /** |
@@ -3488,7 +3528,6 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc) | |||
3488 | void ata_qc_free(struct ata_queued_cmd *qc) | 3528 | void ata_qc_free(struct ata_queued_cmd *qc) |
3489 | { | 3529 | { |
3490 | assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */ | 3530 | assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */ |
3491 | assert(qc->waiting == NULL); /* nothing should be waiting */ | ||
3492 | 3531 | ||
3493 | __ata_qc_complete(qc); | 3532 | __ata_qc_complete(qc); |
3494 | } | 3533 | } |
@@ -3505,7 +3544,7 @@ void ata_qc_free(struct ata_queued_cmd *qc) | |||
3505 | * spin_lock_irqsave(host_set lock) | 3544 | * spin_lock_irqsave(host_set lock) |
3506 | */ | 3545 | */ |
3507 | 3546 | ||
3508 | void ata_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask) | 3547 | void ata_qc_complete(struct ata_queued_cmd *qc) |
3509 | { | 3548 | { |
3510 | int rc; | 3549 | int rc; |
3511 | 3550 | ||
@@ -3522,7 +3561,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask) | |||
3522 | qc->flags &= ~ATA_QCFLAG_ACTIVE; | 3561 | qc->flags &= ~ATA_QCFLAG_ACTIVE; |
3523 | 3562 | ||
3524 | /* call completion callback */ | 3563 | /* call completion callback */ |
3525 | rc = qc->complete_fn(qc, err_mask); | 3564 | rc = qc->complete_fn(qc); |
3526 | 3565 | ||
3527 | /* if callback indicates not to complete command (non-zero), | 3566 | /* if callback indicates not to complete command (non-zero), |
3528 | * return immediately | 3567 | * return immediately |
@@ -3960,7 +3999,8 @@ inline unsigned int ata_host_intr (struct ata_port *ap, | |||
3960 | ap->ops->irq_clear(ap); | 3999 | ap->ops->irq_clear(ap); |
3961 | 4000 | ||
3962 | /* complete taskfile transaction */ | 4001 | /* complete taskfile transaction */ |
3963 | ata_qc_complete(qc, ac_err_mask(status)); | 4002 | qc->err_mask |= ac_err_mask(status); |
4003 | ata_qc_complete(qc); | ||
3964 | break; | 4004 | break; |
3965 | 4005 | ||
3966 | default: | 4006 | default: |
@@ -4054,13 +4094,17 @@ static void atapi_packet_task(void *_data) | |||
4054 | 4094 | ||
4055 | /* sleep-wait for BSY to clear */ | 4095 | /* sleep-wait for BSY to clear */ |
4056 | DPRINTK("busy wait\n"); | 4096 | DPRINTK("busy wait\n"); |
4057 | if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) | 4097 | if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) { |
4058 | goto err_out_status; | 4098 | qc->err_mask |= AC_ERR_ATA_BUS; |
4099 | goto err_out; | ||
4100 | } | ||
4059 | 4101 | ||
4060 | /* make sure DRQ is set */ | 4102 | /* make sure DRQ is set */ |
4061 | status = ata_chk_status(ap); | 4103 | status = ata_chk_status(ap); |
4062 | if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) | 4104 | if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) { |
4105 | qc->err_mask |= AC_ERR_ATA_BUS; | ||
4063 | goto err_out; | 4106 | goto err_out; |
4107 | } | ||
4064 | 4108 | ||
4065 | /* send SCSI cdb */ | 4109 | /* send SCSI cdb */ |
4066 | DPRINTK("send cdb\n"); | 4110 | DPRINTK("send cdb\n"); |
@@ -4092,10 +4136,8 @@ static void atapi_packet_task(void *_data) | |||
4092 | 4136 | ||
4093 | return; | 4137 | return; |
4094 | 4138 | ||
4095 | err_out_status: | ||
4096 | status = ata_chk_status(ap); | ||
4097 | err_out: | 4139 | err_out: |
4098 | ata_poll_qc_complete(qc, __ac_err_mask(status)); | 4140 | ata_poll_qc_complete(qc); |
4099 | } | 4141 | } |
4100 | 4142 | ||
4101 | 4143 | ||