aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r--drivers/ata/libata-core.c536
1 files changed, 426 insertions, 110 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 915a55a6cc1..f8ec3896b79 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -199,7 +199,8 @@ static const u8 ata_rw_cmds[] = {
199 199
200/** 200/**
201 * ata_rwcmd_protocol - set taskfile r/w commands and protocol 201 * ata_rwcmd_protocol - set taskfile r/w commands and protocol
202 * @qc: command to examine and configure 202 * @tf: command to examine and configure
203 * @dev: device tf belongs to
203 * 204 *
204 * Examine the device configuration and tf->flags to calculate 205 * Examine the device configuration and tf->flags to calculate
205 * the proper read/write commands and protocol to use. 206 * the proper read/write commands and protocol to use.
@@ -207,10 +208,8 @@ static const u8 ata_rw_cmds[] = {
207 * LOCKING: 208 * LOCKING:
208 * caller. 209 * caller.
209 */ 210 */
210int ata_rwcmd_protocol(struct ata_queued_cmd *qc) 211static int ata_rwcmd_protocol(struct ata_taskfile *tf, struct ata_device *dev)
211{ 212{
212 struct ata_taskfile *tf = &qc->tf;
213 struct ata_device *dev = qc->dev;
214 u8 cmd; 213 u8 cmd;
215 214
216 int index, fua, lba48, write; 215 int index, fua, lba48, write;
@@ -222,7 +221,7 @@ int ata_rwcmd_protocol(struct ata_queued_cmd *qc)
222 if (dev->flags & ATA_DFLAG_PIO) { 221 if (dev->flags & ATA_DFLAG_PIO) {
223 tf->protocol = ATA_PROT_PIO; 222 tf->protocol = ATA_PROT_PIO;
224 index = dev->multi_count ? 0 : 8; 223 index = dev->multi_count ? 0 : 8;
225 } else if (lba48 && (qc->ap->flags & ATA_FLAG_PIO_LBA48)) { 224 } else if (lba48 && (dev->ap->flags & ATA_FLAG_PIO_LBA48)) {
226 /* Unable to use DMA due to host limitation */ 225 /* Unable to use DMA due to host limitation */
227 tf->protocol = ATA_PROT_PIO; 226 tf->protocol = ATA_PROT_PIO;
228 index = dev->multi_count ? 0 : 8; 227 index = dev->multi_count ? 0 : 8;
@@ -240,6 +239,174 @@ int ata_rwcmd_protocol(struct ata_queued_cmd *qc)
240} 239}
241 240
242/** 241/**
242 * ata_tf_read_block - Read block address from ATA taskfile
243 * @tf: ATA taskfile of interest
244 * @dev: ATA device @tf belongs to
245 *
246 * LOCKING:
247 * None.
248 *
249 * Read block address from @tf. This function can handle all
250 * three address formats - LBA, LBA48 and CHS. tf->protocol and
251 * flags select the address format to use.
252 *
253 * RETURNS:
254 * Block address read from @tf.
255 */
256u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
257{
258 u64 block = 0;
259
260 if (tf->flags & ATA_TFLAG_LBA) {
261 if (tf->flags & ATA_TFLAG_LBA48) {
262 block |= (u64)tf->hob_lbah << 40;
263 block |= (u64)tf->hob_lbam << 32;
264 block |= tf->hob_lbal << 24;
265 } else
266 block |= (tf->device & 0xf) << 24;
267
268 block |= tf->lbah << 16;
269 block |= tf->lbam << 8;
270 block |= tf->lbal;
271 } else {
272 u32 cyl, head, sect;
273
274 cyl = tf->lbam | (tf->lbah << 8);
275 head = tf->device & 0xf;
276 sect = tf->lbal;
277
278 block = (cyl * dev->heads + head) * dev->sectors + sect;
279 }
280
281 return block;
282}
283
284/**
285 * ata_build_rw_tf - Build ATA taskfile for given read/write request
286 * @tf: Target ATA taskfile
287 * @dev: ATA device @tf belongs to
288 * @block: Block address
289 * @n_block: Number of blocks
290 * @tf_flags: RW/FUA etc...
291 * @tag: tag
292 *
293 * LOCKING:
294 * None.
295 *
296 * Build ATA taskfile @tf for read/write request described by
297 * @block, @n_block, @tf_flags and @tag on @dev.
298 *
299 * RETURNS:
300 *
301 * 0 on success, -ERANGE if the request is too large for @dev,
302 * -EINVAL if the request is invalid.
303 */
304int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
305 u64 block, u32 n_block, unsigned int tf_flags,
306 unsigned int tag)
307{
308 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
309 tf->flags |= tf_flags;
310
311 if ((dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF |
312 ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ &&
313 likely(tag != ATA_TAG_INTERNAL)) {
314 /* yay, NCQ */
315 if (!lba_48_ok(block, n_block))
316 return -ERANGE;
317
318 tf->protocol = ATA_PROT_NCQ;
319 tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
320
321 if (tf->flags & ATA_TFLAG_WRITE)
322 tf->command = ATA_CMD_FPDMA_WRITE;
323 else
324 tf->command = ATA_CMD_FPDMA_READ;
325
326 tf->nsect = tag << 3;
327 tf->hob_feature = (n_block >> 8) & 0xff;
328 tf->feature = n_block & 0xff;
329
330 tf->hob_lbah = (block >> 40) & 0xff;
331 tf->hob_lbam = (block >> 32) & 0xff;
332 tf->hob_lbal = (block >> 24) & 0xff;
333 tf->lbah = (block >> 16) & 0xff;
334 tf->lbam = (block >> 8) & 0xff;
335 tf->lbal = block & 0xff;
336
337 tf->device = 1 << 6;
338 if (tf->flags & ATA_TFLAG_FUA)
339 tf->device |= 1 << 7;
340 } else if (dev->flags & ATA_DFLAG_LBA) {
341 tf->flags |= ATA_TFLAG_LBA;
342
343 if (lba_28_ok(block, n_block)) {
344 /* use LBA28 */
345 tf->device |= (block >> 24) & 0xf;
346 } else if (lba_48_ok(block, n_block)) {
347 if (!(dev->flags & ATA_DFLAG_LBA48))
348 return -ERANGE;
349
350 /* use LBA48 */
351 tf->flags |= ATA_TFLAG_LBA48;
352
353 tf->hob_nsect = (n_block >> 8) & 0xff;
354
355 tf->hob_lbah = (block >> 40) & 0xff;
356 tf->hob_lbam = (block >> 32) & 0xff;
357 tf->hob_lbal = (block >> 24) & 0xff;
358 } else
359 /* request too large even for LBA48 */
360 return -ERANGE;
361
362 if (unlikely(ata_rwcmd_protocol(tf, dev) < 0))
363 return -EINVAL;
364
365 tf->nsect = n_block & 0xff;
366
367 tf->lbah = (block >> 16) & 0xff;
368 tf->lbam = (block >> 8) & 0xff;
369 tf->lbal = block & 0xff;
370
371 tf->device |= ATA_LBA;
372 } else {
373 /* CHS */
374 u32 sect, head, cyl, track;
375
376 /* The request -may- be too large for CHS addressing. */
377 if (!lba_28_ok(block, n_block))
378 return -ERANGE;
379
380 if (unlikely(ata_rwcmd_protocol(tf, dev) < 0))
381 return -EINVAL;
382
383 /* Convert LBA to CHS */
384 track = (u32)block / dev->sectors;
385 cyl = track / dev->heads;
386 head = track % dev->heads;
387 sect = (u32)block % dev->sectors + 1;
388
389 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
390 (u32)block, track, cyl, head, sect);
391
392 /* Check whether the converted CHS can fit.
393 Cylinder: 0-65535
394 Head: 0-15
395 Sector: 1-255*/
396 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect))
397 return -ERANGE;
398
399 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
400 tf->lbal = sect;
401 tf->lbam = cyl;
402 tf->lbah = cyl >> 8;
403 tf->device |= head;
404 }
405
406 return 0;
407}
408
409/**
243 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask 410 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask
244 * @pio_mask: pio_mask 411 * @pio_mask: pio_mask
245 * @mwdma_mask: mwdma_mask 412 * @mwdma_mask: mwdma_mask
@@ -999,13 +1166,13 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc)
999} 1166}
1000 1167
1001/** 1168/**
1002 * ata_exec_internal - execute libata internal command 1169 * ata_exec_internal_sg - execute libata internal command
1003 * @dev: Device to which the command is sent 1170 * @dev: Device to which the command is sent
1004 * @tf: Taskfile registers for the command and the result 1171 * @tf: Taskfile registers for the command and the result
1005 * @cdb: CDB for packet command 1172 * @cdb: CDB for packet command
1006 * @dma_dir: Data tranfer direction of the command 1173 * @dma_dir: Data tranfer direction of the command
1007 * @buf: Data buffer of the command 1174 * @sg: sg list for the data buffer of the command
1008 * @buflen: Length of data buffer 1175 * @n_elem: Number of sg entries
1009 * 1176 *
1010 * Executes libata internal command with timeout. @tf contains 1177 * Executes libata internal command with timeout. @tf contains
1011 * command on entry and result on return. Timeout and error 1178 * command on entry and result on return. Timeout and error
@@ -1019,9 +1186,10 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc)
1019 * RETURNS: 1186 * RETURNS:
1020 * Zero on success, AC_ERR_* mask on failure 1187 * Zero on success, AC_ERR_* mask on failure
1021 */ 1188 */
1022unsigned ata_exec_internal(struct ata_device *dev, 1189unsigned ata_exec_internal_sg(struct ata_device *dev,
1023 struct ata_taskfile *tf, const u8 *cdb, 1190 struct ata_taskfile *tf, const u8 *cdb,
1024 int dma_dir, void *buf, unsigned int buflen) 1191 int dma_dir, struct scatterlist *sg,
1192 unsigned int n_elem)
1025{ 1193{
1026 struct ata_port *ap = dev->ap; 1194 struct ata_port *ap = dev->ap;
1027 u8 command = tf->command; 1195 u8 command = tf->command;
@@ -1077,7 +1245,12 @@ unsigned ata_exec_internal(struct ata_device *dev,
1077 qc->flags |= ATA_QCFLAG_RESULT_TF; 1245 qc->flags |= ATA_QCFLAG_RESULT_TF;
1078 qc->dma_dir = dma_dir; 1246 qc->dma_dir = dma_dir;
1079 if (dma_dir != DMA_NONE) { 1247 if (dma_dir != DMA_NONE) {
1080 ata_sg_init_one(qc, buf, buflen); 1248 unsigned int i, buflen = 0;
1249
1250 for (i = 0; i < n_elem; i++)
1251 buflen += sg[i].length;
1252
1253 ata_sg_init(qc, sg, n_elem);
1081 qc->nsect = buflen / ATA_SECT_SIZE; 1254 qc->nsect = buflen / ATA_SECT_SIZE;
1082 } 1255 }
1083 1256
@@ -1161,6 +1334,35 @@ unsigned ata_exec_internal(struct ata_device *dev,
1161} 1334}
1162 1335
1163/** 1336/**
1337 * ata_exec_internal_sg - execute libata internal command
1338 * @dev: Device to which the command is sent
1339 * @tf: Taskfile registers for the command and the result
1340 * @cdb: CDB for packet command
1341 * @dma_dir: Data tranfer direction of the command
1342 * @buf: Data buffer of the command
1343 * @buflen: Length of data buffer
1344 *
1345 * Wrapper around ata_exec_internal_sg() which takes simple
1346 * buffer instead of sg list.
1347 *
1348 * LOCKING:
1349 * None. Should be called with kernel context, might sleep.
1350 *
1351 * RETURNS:
1352 * Zero on success, AC_ERR_* mask on failure
1353 */
1354unsigned ata_exec_internal(struct ata_device *dev,
1355 struct ata_taskfile *tf, const u8 *cdb,
1356 int dma_dir, void *buf, unsigned int buflen)
1357{
1358 struct scatterlist sg;
1359
1360 sg_init_one(&sg, buf, buflen);
1361
1362 return ata_exec_internal_sg(dev, tf, cdb, dma_dir, &sg, 1);
1363}
1364
1365/**
1164 * ata_do_simple_cmd - execute simple internal command 1366 * ata_do_simple_cmd - execute simple internal command
1165 * @dev: Device to which the command is sent 1367 * @dev: Device to which the command is sent
1166 * @cmd: Opcode to execute 1368 * @cmd: Opcode to execute
@@ -1224,7 +1426,7 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1224 * ata_dev_read_id - Read ID data from the specified device 1426 * ata_dev_read_id - Read ID data from the specified device
1225 * @dev: target device 1427 * @dev: target device
1226 * @p_class: pointer to class of the target device (may be changed) 1428 * @p_class: pointer to class of the target device (may be changed)
1227 * @post_reset: is this read ID post-reset? 1429 * @flags: ATA_READID_* flags
1228 * @id: buffer to read IDENTIFY data into 1430 * @id: buffer to read IDENTIFY data into
1229 * 1431 *
1230 * Read ID data from the specified device. ATA_CMD_ID_ATA is 1432 * Read ID data from the specified device. ATA_CMD_ID_ATA is
@@ -1239,7 +1441,7 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1239 * 0 on success, -errno otherwise. 1441 * 0 on success, -errno otherwise.
1240 */ 1442 */
1241int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class, 1443int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1242 int post_reset, u16 *id) 1444 unsigned int flags, u16 *id)
1243{ 1445{
1244 struct ata_port *ap = dev->ap; 1446 struct ata_port *ap = dev->ap;
1245 unsigned int class = *p_class; 1447 unsigned int class = *p_class;
@@ -1271,10 +1473,17 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1271 } 1473 }
1272 1474
1273 tf.protocol = ATA_PROT_PIO; 1475 tf.protocol = ATA_PROT_PIO;
1476 tf.flags |= ATA_TFLAG_POLLING; /* for polling presence detection */
1274 1477
1275 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, 1478 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE,
1276 id, sizeof(id[0]) * ATA_ID_WORDS); 1479 id, sizeof(id[0]) * ATA_ID_WORDS);
1277 if (err_mask) { 1480 if (err_mask) {
1481 if (err_mask & AC_ERR_NODEV_HINT) {
1482 DPRINTK("ata%u.%d: NODEV after polling detection\n",
1483 ap->id, dev->devno);
1484 return -ENOENT;
1485 }
1486
1278 rc = -EIO; 1487 rc = -EIO;
1279 reason = "I/O error"; 1488 reason = "I/O error";
1280 goto err_out; 1489 goto err_out;
@@ -1294,7 +1503,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1294 goto err_out; 1503 goto err_out;
1295 } 1504 }
1296 1505
1297 if (post_reset && class == ATA_DEV_ATA) { 1506 if ((flags & ATA_READID_POSTRESET) && class == ATA_DEV_ATA) {
1298 /* 1507 /*
1299 * The exact sequence expected by certain pre-ATA4 drives is: 1508 * The exact sequence expected by certain pre-ATA4 drives is:
1300 * SRST RESET 1509 * SRST RESET
@@ -1314,7 +1523,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1314 /* current CHS translation info (id[53-58]) might be 1523 /* current CHS translation info (id[53-58]) might be
1315 * changed. reread the identify device info. 1524 * changed. reread the identify device info.
1316 */ 1525 */
1317 post_reset = 0; 1526 flags &= ~ATA_READID_POSTRESET;
1318 goto retry; 1527 goto retry;
1319 } 1528 }
1320 } 1529 }
@@ -1345,7 +1554,10 @@ static void ata_dev_config_ncq(struct ata_device *dev,
1345 desc[0] = '\0'; 1554 desc[0] = '\0';
1346 return; 1555 return;
1347 } 1556 }
1348 1557 if (ata_device_blacklisted(dev) & ATA_HORKAGE_NONCQ) {
1558 snprintf(desc, desc_sz, "NCQ (not used)");
1559 return;
1560 }
1349 if (ap->flags & ATA_FLAG_NCQ) { 1561 if (ap->flags & ATA_FLAG_NCQ) {
1350 hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1); 1562 hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1);
1351 dev->flags |= ATA_DFLAG_NCQ; 1563 dev->flags |= ATA_DFLAG_NCQ;
@@ -1374,7 +1586,6 @@ static void ata_set_port_max_cmd_len(struct ata_port *ap)
1374/** 1586/**
1375 * ata_dev_configure - Configure the specified ATA/ATAPI device 1587 * ata_dev_configure - Configure the specified ATA/ATAPI device
1376 * @dev: Target device to configure 1588 * @dev: Target device to configure
1377 * @print_info: Enable device info printout
1378 * 1589 *
1379 * Configure @dev according to @dev->id. Generic and low-level 1590 * Configure @dev according to @dev->id. Generic and low-level
1380 * driver specific fixups are also applied. 1591 * driver specific fixups are also applied.
@@ -1385,9 +1596,10 @@ static void ata_set_port_max_cmd_len(struct ata_port *ap)
1385 * RETURNS: 1596 * RETURNS:
1386 * 0 on success, -errno otherwise 1597 * 0 on success, -errno otherwise
1387 */ 1598 */
1388int ata_dev_configure(struct ata_device *dev, int print_info) 1599int ata_dev_configure(struct ata_device *dev)
1389{ 1600{
1390 struct ata_port *ap = dev->ap; 1601 struct ata_port *ap = dev->ap;
1602 int print_info = ap->eh_context.i.flags & ATA_EHI_PRINTINFO;
1391 const u16 *id = dev->id; 1603 const u16 *id = dev->id;
1392 unsigned int xfer_mask; 1604 unsigned int xfer_mask;
1393 char revbuf[7]; /* XYZ-99\0 */ 1605 char revbuf[7]; /* XYZ-99\0 */
@@ -1454,6 +1666,10 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1454 if (ata_id_has_lba48(id)) { 1666 if (ata_id_has_lba48(id)) {
1455 dev->flags |= ATA_DFLAG_LBA48; 1667 dev->flags |= ATA_DFLAG_LBA48;
1456 lba_desc = "LBA48"; 1668 lba_desc = "LBA48";
1669
1670 if (dev->n_sectors >= (1UL << 28) &&
1671 ata_id_has_flush_ext(id))
1672 dev->flags |= ATA_DFLAG_FLUSH_EXT;
1457 } 1673 }
1458 1674
1459 /* config NCQ */ 1675 /* config NCQ */
@@ -1530,6 +1746,11 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1530 cdb_intr_string); 1746 cdb_intr_string);
1531 } 1747 }
1532 1748
1749 /* determine max_sectors */
1750 dev->max_sectors = ATA_MAX_SECTORS;
1751 if (dev->flags & ATA_DFLAG_LBA48)
1752 dev->max_sectors = ATA_MAX_SECTORS_LBA48;
1753
1533 if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) { 1754 if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) {
1534 /* Let the user know. We don't want to disallow opens for 1755 /* Let the user know. We don't want to disallow opens for
1535 rescue purposes, or in case the vendor is just a blithering 1756 rescue purposes, or in case the vendor is just a blithering
@@ -1631,11 +1852,14 @@ int ata_bus_probe(struct ata_port *ap)
1631 if (!ata_dev_enabled(dev)) 1852 if (!ata_dev_enabled(dev))
1632 continue; 1853 continue;
1633 1854
1634 rc = ata_dev_read_id(dev, &dev->class, 1, dev->id); 1855 rc = ata_dev_read_id(dev, &dev->class, ATA_READID_POSTRESET,
1856 dev->id);
1635 if (rc) 1857 if (rc)
1636 goto fail; 1858 goto fail;
1637 1859
1638 rc = ata_dev_configure(dev, 1); 1860 ap->eh_context.i.flags |= ATA_EHI_PRINTINFO;
1861 rc = ata_dev_configure(dev);
1862 ap->eh_context.i.flags &= ~ATA_EHI_PRINTINFO;
1639 if (rc) 1863 if (rc)
1640 goto fail; 1864 goto fail;
1641 } 1865 }
@@ -2153,6 +2377,7 @@ int ata_down_xfermask_limit(struct ata_device *dev, int force_pio0)
2153 2377
2154static int ata_dev_set_mode(struct ata_device *dev) 2378static int ata_dev_set_mode(struct ata_device *dev)
2155{ 2379{
2380 struct ata_eh_context *ehc = &dev->ap->eh_context;
2156 unsigned int err_mask; 2381 unsigned int err_mask;
2157 int rc; 2382 int rc;
2158 2383
@@ -2167,7 +2392,9 @@ static int ata_dev_set_mode(struct ata_device *dev)
2167 return -EIO; 2392 return -EIO;
2168 } 2393 }
2169 2394
2395 ehc->i.flags |= ATA_EHI_POST_SETMODE;
2170 rc = ata_dev_revalidate(dev, 0); 2396 rc = ata_dev_revalidate(dev, 0);
2397 ehc->i.flags &= ~ATA_EHI_POST_SETMODE;
2171 if (rc) 2398 if (rc)
2172 return rc; 2399 return rc;
2173 2400
@@ -2325,11 +2552,14 @@ static inline void ata_tf_to_host(struct ata_port *ap,
2325 * Sleep until ATA Status register bit BSY clears, 2552 * Sleep until ATA Status register bit BSY clears,
2326 * or a timeout occurs. 2553 * or a timeout occurs.
2327 * 2554 *
2328 * LOCKING: None. 2555 * LOCKING:
2556 * Kernel thread context (may sleep).
2557 *
2558 * RETURNS:
2559 * 0 on success, -errno otherwise.
2329 */ 2560 */
2330 2561int ata_busy_sleep(struct ata_port *ap,
2331unsigned int ata_busy_sleep (struct ata_port *ap, 2562 unsigned long tmout_pat, unsigned long tmout)
2332 unsigned long tmout_pat, unsigned long tmout)
2333{ 2563{
2334 unsigned long timer_start, timeout; 2564 unsigned long timer_start, timeout;
2335 u8 status; 2565 u8 status;
@@ -2337,27 +2567,32 @@ unsigned int ata_busy_sleep (struct ata_port *ap,
2337 status = ata_busy_wait(ap, ATA_BUSY, 300); 2567 status = ata_busy_wait(ap, ATA_BUSY, 300);
2338 timer_start = jiffies; 2568 timer_start = jiffies;
2339 timeout = timer_start + tmout_pat; 2569 timeout = timer_start + tmout_pat;
2340 while ((status & ATA_BUSY) && (time_before(jiffies, timeout))) { 2570 while (status != 0xff && (status & ATA_BUSY) &&
2571 time_before(jiffies, timeout)) {
2341 msleep(50); 2572 msleep(50);
2342 status = ata_busy_wait(ap, ATA_BUSY, 3); 2573 status = ata_busy_wait(ap, ATA_BUSY, 3);
2343 } 2574 }
2344 2575
2345 if (status & ATA_BUSY) 2576 if (status != 0xff && (status & ATA_BUSY))
2346 ata_port_printk(ap, KERN_WARNING, 2577 ata_port_printk(ap, KERN_WARNING,
2347 "port is slow to respond, please be patient " 2578 "port is slow to respond, please be patient "
2348 "(Status 0x%x)\n", status); 2579 "(Status 0x%x)\n", status);
2349 2580
2350 timeout = timer_start + tmout; 2581 timeout = timer_start + tmout;
2351 while ((status & ATA_BUSY) && (time_before(jiffies, timeout))) { 2582 while (status != 0xff && (status & ATA_BUSY) &&
2583 time_before(jiffies, timeout)) {
2352 msleep(50); 2584 msleep(50);
2353 status = ata_chk_status(ap); 2585 status = ata_chk_status(ap);
2354 } 2586 }
2355 2587
2588 if (status == 0xff)
2589 return -ENODEV;
2590
2356 if (status & ATA_BUSY) { 2591 if (status & ATA_BUSY) {
2357 ata_port_printk(ap, KERN_ERR, "port failed to respond " 2592 ata_port_printk(ap, KERN_ERR, "port failed to respond "
2358 "(%lu secs, Status 0x%x)\n", 2593 "(%lu secs, Status 0x%x)\n",
2359 tmout / HZ, status); 2594 tmout / HZ, status);
2360 return 1; 2595 return -EBUSY;
2361 } 2596 }
2362 2597
2363 return 0; 2598 return 0;
@@ -2448,10 +2683,8 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2448 * the bus shows 0xFF because the odd clown forgets the D7 2683 * the bus shows 0xFF because the odd clown forgets the D7
2449 * pulldown resistor. 2684 * pulldown resistor.
2450 */ 2685 */
2451 if (ata_check_status(ap) == 0xFF) { 2686 if (ata_check_status(ap) == 0xFF)
2452 ata_port_printk(ap, KERN_ERR, "SRST failed (status 0xFF)\n"); 2687 return 0;
2453 return AC_ERR_OTHER;
2454 }
2455 2688
2456 ata_bus_post_reset(ap, devmask); 2689 ata_bus_post_reset(ap, devmask);
2457 2690
@@ -2777,9 +3010,9 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
2777} 3010}
2778 3011
2779/** 3012/**
2780 * sata_std_hardreset - reset host port via SATA phy reset 3013 * sata_port_hardreset - reset port via SATA phy reset
2781 * @ap: port to reset 3014 * @ap: port to reset
2782 * @class: resulting class of attached device 3015 * @timing: timing parameters { interval, duratinon, timeout } in msec
2783 * 3016 *
2784 * SATA phy-reset host port using DET bits of SControl register. 3017 * SATA phy-reset host port using DET bits of SControl register.
2785 * 3018 *
@@ -2789,10 +3022,8 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
2789 * RETURNS: 3022 * RETURNS:
2790 * 0 on success, -errno otherwise. 3023 * 0 on success, -errno otherwise.
2791 */ 3024 */
2792int sata_std_hardreset(struct ata_port *ap, unsigned int *class) 3025int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing)
2793{ 3026{
2794 struct ata_eh_context *ehc = &ap->eh_context;
2795 const unsigned long *timing = sata_ehc_deb_timing(ehc);
2796 u32 scontrol; 3027 u32 scontrol;
2797 int rc; 3028 int rc;
2798 3029
@@ -2805,24 +3036,24 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2805 * and Sil3124. 3036 * and Sil3124.
2806 */ 3037 */
2807 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 3038 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
2808 return rc; 3039 goto out;
2809 3040
2810 scontrol = (scontrol & 0x0f0) | 0x304; 3041 scontrol = (scontrol & 0x0f0) | 0x304;
2811 3042
2812 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol))) 3043 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol)))
2813 return rc; 3044 goto out;
2814 3045
2815 sata_set_spd(ap); 3046 sata_set_spd(ap);
2816 } 3047 }
2817 3048
2818 /* issue phy wake/reset */ 3049 /* issue phy wake/reset */
2819 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 3050 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
2820 return rc; 3051 goto out;
2821 3052
2822 scontrol = (scontrol & 0x0f0) | 0x301; 3053 scontrol = (scontrol & 0x0f0) | 0x301;
2823 3054
2824 if ((rc = sata_scr_write_flush(ap, SCR_CONTROL, scontrol))) 3055 if ((rc = sata_scr_write_flush(ap, SCR_CONTROL, scontrol)))
2825 return rc; 3056 goto out;
2826 3057
2827 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 3058 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
2828 * 10.4.2 says at least 1 ms. 3059 * 10.4.2 says at least 1 ms.
@@ -2830,7 +3061,40 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2830 msleep(1); 3061 msleep(1);
2831 3062
2832 /* bring phy back */ 3063 /* bring phy back */
2833 sata_phy_resume(ap, timing); 3064 rc = sata_phy_resume(ap, timing);
3065 out:
3066 DPRINTK("EXIT, rc=%d\n", rc);
3067 return rc;
3068}
3069
3070/**
3071 * sata_std_hardreset - reset host port via SATA phy reset
3072 * @ap: port to reset
3073 * @class: resulting class of attached device
3074 *
3075 * SATA phy-reset host port using DET bits of SControl register,
3076 * wait for !BSY and classify the attached device.
3077 *
3078 * LOCKING:
3079 * Kernel thread context (may sleep)
3080 *
3081 * RETURNS:
3082 * 0 on success, -errno otherwise.
3083 */
3084int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
3085{
3086 const unsigned long *timing = sata_ehc_deb_timing(&ap->eh_context);
3087 int rc;
3088
3089 DPRINTK("ENTER\n");
3090
3091 /* do hardreset */
3092 rc = sata_port_hardreset(ap, timing);
3093 if (rc) {
3094 ata_port_printk(ap, KERN_ERR,
3095 "COMRESET failed (errno=%d)\n", rc);
3096 return rc;
3097 }
2834 3098
2835 /* TODO: phy layer with polling, timeouts, etc. */ 3099 /* TODO: phy layer with polling, timeouts, etc. */
2836 if (ata_port_offline(ap)) { 3100 if (ata_port_offline(ap)) {
@@ -2969,7 +3233,7 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
2969/** 3233/**
2970 * ata_dev_revalidate - Revalidate ATA device 3234 * ata_dev_revalidate - Revalidate ATA device
2971 * @dev: device to revalidate 3235 * @dev: device to revalidate
2972 * @post_reset: is this revalidation after reset? 3236 * @readid_flags: read ID flags
2973 * 3237 *
2974 * Re-read IDENTIFY page and make sure @dev is still attached to 3238 * Re-read IDENTIFY page and make sure @dev is still attached to
2975 * the port. 3239 * the port.
@@ -2980,7 +3244,7 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
2980 * RETURNS: 3244 * RETURNS:
2981 * 0 on success, negative errno otherwise 3245 * 0 on success, negative errno otherwise
2982 */ 3246 */
2983int ata_dev_revalidate(struct ata_device *dev, int post_reset) 3247int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags)
2984{ 3248{
2985 unsigned int class = dev->class; 3249 unsigned int class = dev->class;
2986 u16 *id = (void *)dev->ap->sector_buf; 3250 u16 *id = (void *)dev->ap->sector_buf;
@@ -2992,7 +3256,7 @@ int ata_dev_revalidate(struct ata_device *dev, int post_reset)
2992 } 3256 }
2993 3257
2994 /* read ID data */ 3258 /* read ID data */
2995 rc = ata_dev_read_id(dev, &class, post_reset, id); 3259 rc = ata_dev_read_id(dev, &class, readid_flags, id);
2996 if (rc) 3260 if (rc)
2997 goto fail; 3261 goto fail;
2998 3262
@@ -3005,7 +3269,7 @@ int ata_dev_revalidate(struct ata_device *dev, int post_reset)
3005 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); 3269 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS);
3006 3270
3007 /* configure device according to the new ID */ 3271 /* configure device according to the new ID */
3008 rc = ata_dev_configure(dev, 0); 3272 rc = ata_dev_configure(dev);
3009 if (rc == 0) 3273 if (rc == 0)
3010 return 0; 3274 return 0;
3011 3275
@@ -3014,37 +3278,55 @@ int ata_dev_revalidate(struct ata_device *dev, int post_reset)
3014 return rc; 3278 return rc;
3015} 3279}
3016 3280
3017static const char * const ata_dma_blacklist [] = { 3281struct ata_blacklist_entry {
3018 "WDC AC11000H", NULL, 3282 const char *model_num;
3019 "WDC AC22100H", NULL, 3283 const char *model_rev;
3020 "WDC AC32500H", NULL, 3284 unsigned long horkage;
3021 "WDC AC33100H", NULL, 3285};
3022 "WDC AC31600H", NULL, 3286
3023 "WDC AC32100H", "24.09P07", 3287static const struct ata_blacklist_entry ata_device_blacklist [] = {
3024 "WDC AC23200L", "21.10N21", 3288 /* Devices with DMA related problems under Linux */
3025 "Compaq CRD-8241B", NULL, 3289 { "WDC AC11000H", NULL, ATA_HORKAGE_NODMA },
3026 "CRD-8400B", NULL, 3290 { "WDC AC22100H", NULL, ATA_HORKAGE_NODMA },
3027 "CRD-8480B", NULL, 3291 { "WDC AC32500H", NULL, ATA_HORKAGE_NODMA },
3028 "CRD-8482B", NULL, 3292 { "WDC AC33100H", NULL, ATA_HORKAGE_NODMA },
3029 "CRD-84", NULL, 3293 { "WDC AC31600H", NULL, ATA_HORKAGE_NODMA },
3030 "SanDisk SDP3B", NULL, 3294 { "WDC AC32100H", "24.09P07", ATA_HORKAGE_NODMA },
3031 "SanDisk SDP3B-64", NULL, 3295 { "WDC AC23200L", "21.10N21", ATA_HORKAGE_NODMA },
3032 "SANYO CD-ROM CRD", NULL, 3296 { "Compaq CRD-8241B", NULL, ATA_HORKAGE_NODMA },
3033 "HITACHI CDR-8", NULL, 3297 { "CRD-8400B", NULL, ATA_HORKAGE_NODMA },
3034 "HITACHI CDR-8335", NULL, 3298 { "CRD-8480B", NULL, ATA_HORKAGE_NODMA },
3035 "HITACHI CDR-8435", NULL, 3299 { "CRD-8482B", NULL, ATA_HORKAGE_NODMA },
3036 "Toshiba CD-ROM XM-6202B", NULL, 3300 { "CRD-84", NULL, ATA_HORKAGE_NODMA },
3037 "TOSHIBA CD-ROM XM-1702BC", NULL, 3301 { "SanDisk SDP3B", NULL, ATA_HORKAGE_NODMA },
3038 "CD-532E-A", NULL, 3302 { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA },
3039 "E-IDE CD-ROM CR-840", NULL, 3303 { "SANYO CD-ROM CRD", NULL, ATA_HORKAGE_NODMA },
3040 "CD-ROM Drive/F5A", NULL, 3304 { "HITACHI CDR-8", NULL, ATA_HORKAGE_NODMA },
3041 "WPI CDD-820", NULL, 3305 { "HITACHI CDR-8335", NULL, ATA_HORKAGE_NODMA },
3042 "SAMSUNG CD-ROM SC-148C", NULL, 3306 { "HITACHI CDR-8435", NULL, ATA_HORKAGE_NODMA },
3043 "SAMSUNG CD-ROM SC", NULL, 3307 { "Toshiba CD-ROM XM-6202B", NULL, ATA_HORKAGE_NODMA },
3044 "SanDisk SDP3B-64", NULL, 3308 { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_HORKAGE_NODMA },
3045 "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL, 3309 { "CD-532E-A", NULL, ATA_HORKAGE_NODMA },
3046 "_NEC DV5800A", NULL, 3310 { "E-IDE CD-ROM CR-840",NULL, ATA_HORKAGE_NODMA },
3047 "SAMSUNG CD-ROM SN-124", "N001" 3311 { "CD-ROM Drive/F5A", NULL, ATA_HORKAGE_NODMA },
3312 { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA },
3313 { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA },
3314 { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA },
3315 { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA },
3316 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA },
3317 { "_NEC DV5800A", NULL, ATA_HORKAGE_NODMA },
3318 { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA },
3319
3320 /* Devices we expect to fail diagnostics */
3321
3322 /* Devices where NCQ should be avoided */
3323 /* NCQ is slow */
3324 { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ },
3325
3326 /* Devices with NCQ limits */
3327
3328 /* End Marker */
3329 { }
3048}; 3330};
3049 3331
3050static int ata_strim(char *s, size_t len) 3332static int ata_strim(char *s, size_t len)
@@ -3059,20 +3341,12 @@ static int ata_strim(char *s, size_t len)
3059 return len; 3341 return len;
3060} 3342}
3061 3343
3062static int ata_dma_blacklisted(const struct ata_device *dev) 3344unsigned long ata_device_blacklisted(const struct ata_device *dev)
3063{ 3345{
3064 unsigned char model_num[40]; 3346 unsigned char model_num[40];
3065 unsigned char model_rev[16]; 3347 unsigned char model_rev[16];
3066 unsigned int nlen, rlen; 3348 unsigned int nlen, rlen;
3067 int i; 3349 const struct ata_blacklist_entry *ad = ata_device_blacklist;
3068
3069 /* We don't support polling DMA.
3070 * DMA blacklist those ATAPI devices with CDB-intr (and use PIO)
3071 * if the LLDD handles only interrupts in the HSM_ST_LAST state.
3072 */
3073 if ((dev->ap->flags & ATA_FLAG_PIO_POLLING) &&
3074 (dev->flags & ATA_DFLAG_CDB_INTR))
3075 return 1;
3076 3350
3077 ata_id_string(dev->id, model_num, ATA_ID_PROD_OFS, 3351 ata_id_string(dev->id, model_num, ATA_ID_PROD_OFS,
3078 sizeof(model_num)); 3352 sizeof(model_num));
@@ -3081,17 +3355,30 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
3081 nlen = ata_strim(model_num, sizeof(model_num)); 3355 nlen = ata_strim(model_num, sizeof(model_num));
3082 rlen = ata_strim(model_rev, sizeof(model_rev)); 3356 rlen = ata_strim(model_rev, sizeof(model_rev));
3083 3357
3084 for (i = 0; i < ARRAY_SIZE(ata_dma_blacklist); i += 2) { 3358 while (ad->model_num) {
3085 if (!strncmp(ata_dma_blacklist[i], model_num, nlen)) { 3359 if (!strncmp(ad->model_num, model_num, nlen)) {
3086 if (ata_dma_blacklist[i+1] == NULL) 3360 if (ad->model_rev == NULL)
3087 return 1; 3361 return ad->horkage;
3088 if (!strncmp(ata_dma_blacklist[i], model_rev, rlen)) 3362 if (!strncmp(ad->model_rev, model_rev, rlen))
3089 return 1; 3363 return ad->horkage;
3090 } 3364 }
3365 ad++;
3091 } 3366 }
3092 return 0; 3367 return 0;
3093} 3368}
3094 3369
3370static int ata_dma_blacklisted(const struct ata_device *dev)
3371{
3372 /* We don't support polling DMA.
3373 * DMA blacklist those ATAPI devices with CDB-intr (and use PIO)
3374 * if the LLDD handles only interrupts in the HSM_ST_LAST state.
3375 */
3376 if ((dev->ap->flags & ATA_FLAG_PIO_POLLING) &&
3377 (dev->flags & ATA_DFLAG_CDB_INTR))
3378 return 1;
3379 return (ata_device_blacklisted(dev) & ATA_HORKAGE_NODMA) ? 1 : 0;
3380}
3381
3095/** 3382/**
3096 * ata_dev_xfermask - Compute supported xfermask of the given device 3383 * ata_dev_xfermask - Compute supported xfermask of the given device
3097 * @dev: Device to compute xfermask for 3384 * @dev: Device to compute xfermask for
@@ -3119,6 +3406,13 @@ static void ata_dev_xfermask(struct ata_device *dev)
3119 */ 3406 */
3120 if (ap->cbl == ATA_CBL_PATA40) 3407 if (ap->cbl == ATA_CBL_PATA40)
3121 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA); 3408 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
3409 /* Apply drive side cable rule. Unknown or 80 pin cables reported
3410 * host side are checked drive side as well. Cases where we know a
3411 * 40wire cable is used safely for 80 are not checked here.
3412 */
3413 if (ata_drive_40wire(dev->id) && (ap->cbl == ATA_CBL_PATA_UNK || ap->cbl == ATA_CBL_PATA80))
3414 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
3415
3122 3416
3123 xfer_mask &= ata_pack_xfermask(dev->pio_mask, 3417 xfer_mask &= ata_pack_xfermask(dev->pio_mask,
3124 dev->mwdma_mask, dev->udma_mask); 3418 dev->mwdma_mask, dev->udma_mask);
@@ -3236,8 +3530,7 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
3236 * LOCKING: 3530 * LOCKING:
3237 * spin_lock_irqsave(host lock) 3531 * spin_lock_irqsave(host lock)
3238 */ 3532 */
3239 3533void ata_sg_clean(struct ata_queued_cmd *qc)
3240static void ata_sg_clean(struct ata_queued_cmd *qc)
3241{ 3534{
3242 struct ata_port *ap = qc->ap; 3535 struct ata_port *ap = qc->ap;
3243 struct scatterlist *sg = qc->__sg; 3536 struct scatterlist *sg = qc->__sg;
@@ -3395,19 +3688,15 @@ void ata_noop_qc_prep(struct ata_queued_cmd *qc) { }
3395 3688
3396void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) 3689void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
3397{ 3690{
3398 struct scatterlist *sg;
3399
3400 qc->flags |= ATA_QCFLAG_SINGLE; 3691 qc->flags |= ATA_QCFLAG_SINGLE;
3401 3692
3402 memset(&qc->sgent, 0, sizeof(qc->sgent));
3403 qc->__sg = &qc->sgent; 3693 qc->__sg = &qc->sgent;
3404 qc->n_elem = 1; 3694 qc->n_elem = 1;
3405 qc->orig_n_elem = 1; 3695 qc->orig_n_elem = 1;
3406 qc->buf_virt = buf; 3696 qc->buf_virt = buf;
3407 qc->nbytes = buflen; 3697 qc->nbytes = buflen;
3408 3698
3409 sg = qc->__sg; 3699 sg_init_one(&qc->sgent, buf, buflen);
3410 sg_init_one(sg, buf, buflen);
3411} 3700}
3412 3701
3413/** 3702/**
@@ -4200,8 +4489,12 @@ fsm_start:
4200 /* device stops HSM for abort/error */ 4489 /* device stops HSM for abort/error */
4201 qc->err_mask |= AC_ERR_DEV; 4490 qc->err_mask |= AC_ERR_DEV;
4202 else 4491 else
4203 /* HSM violation. Let EH handle this */ 4492 /* HSM violation. Let EH handle this.
4204 qc->err_mask |= AC_ERR_HSM; 4493 * Phantom devices also trigger this
4494 * condition. Mark hint.
4495 */
4496 qc->err_mask |= AC_ERR_HSM |
4497 AC_ERR_NODEV_HINT;
4205 4498
4206 ap->hsm_task_state = HSM_ST_ERR; 4499 ap->hsm_task_state = HSM_ST_ERR;
4207 goto fsm_start; 4500 goto fsm_start;
@@ -4440,6 +4733,14 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
4440 qc->complete_fn(qc); 4733 qc->complete_fn(qc);
4441} 4734}
4442 4735
4736static void fill_result_tf(struct ata_queued_cmd *qc)
4737{
4738 struct ata_port *ap = qc->ap;
4739
4740 ap->ops->tf_read(ap, &qc->result_tf);
4741 qc->result_tf.flags = qc->tf.flags;
4742}
4743
4443/** 4744/**
4444 * ata_qc_complete - Complete an active ATA command 4745 * ata_qc_complete - Complete an active ATA command
4445 * @qc: Command to complete 4746 * @qc: Command to complete
@@ -4477,7 +4778,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
4477 if (unlikely(qc->flags & ATA_QCFLAG_FAILED)) { 4778 if (unlikely(qc->flags & ATA_QCFLAG_FAILED)) {
4478 if (!ata_tag_internal(qc->tag)) { 4779 if (!ata_tag_internal(qc->tag)) {
4479 /* always fill result TF for failed qc */ 4780 /* always fill result TF for failed qc */
4480 ap->ops->tf_read(ap, &qc->result_tf); 4781 fill_result_tf(qc);
4481 ata_qc_schedule_eh(qc); 4782 ata_qc_schedule_eh(qc);
4482 return; 4783 return;
4483 } 4784 }
@@ -4485,7 +4786,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
4485 4786
4486 /* read result TF if requested */ 4787 /* read result TF if requested */
4487 if (qc->flags & ATA_QCFLAG_RESULT_TF) 4788 if (qc->flags & ATA_QCFLAG_RESULT_TF)
4488 ap->ops->tf_read(ap, &qc->result_tf); 4789 fill_result_tf(qc);
4489 4790
4490 __ata_qc_complete(qc); 4791 __ata_qc_complete(qc);
4491 } else { 4792 } else {
@@ -4494,7 +4795,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
4494 4795
4495 /* read result TF if failed or requested */ 4796 /* read result TF if failed or requested */
4496 if (qc->err_mask || qc->flags & ATA_QCFLAG_RESULT_TF) 4797 if (qc->err_mask || qc->flags & ATA_QCFLAG_RESULT_TF)
4497 ap->ops->tf_read(ap, &qc->result_tf); 4798 fill_result_tf(qc);
4498 4799
4499 __ata_qc_complete(qc); 4800 __ata_qc_complete(qc);
4500 } 4801 }
@@ -4674,6 +4975,14 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
4674 } 4975 }
4675 } 4976 }
4676 4977
4978 /* Some controllers show flaky interrupt behavior after
4979 * setting xfer mode. Use polling instead.
4980 */
4981 if (unlikely(qc->tf.command == ATA_CMD_SET_FEATURES &&
4982 qc->tf.feature == SETFEATURES_XFER) &&
4983 (ap->flags & ATA_FLAG_SETXFER_POLLING))
4984 qc->tf.flags |= ATA_TFLAG_POLLING;
4985
4677 /* select the device */ 4986 /* select the device */
4678 ata_dev_select(ap, qc->dev->devno, 1, 0); 4987 ata_dev_select(ap, qc->dev->devno, 1, 0);
4679 4988
@@ -4782,6 +5091,7 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
4782inline unsigned int ata_host_intr (struct ata_port *ap, 5091inline unsigned int ata_host_intr (struct ata_port *ap,
4783 struct ata_queued_cmd *qc) 5092 struct ata_queued_cmd *qc)
4784{ 5093{
5094 struct ata_eh_info *ehi = &ap->eh_info;
4785 u8 status, host_stat = 0; 5095 u8 status, host_stat = 0;
4786 5096
4787 VPRINTK("ata%u: protocol %d task_state %d\n", 5097 VPRINTK("ata%u: protocol %d task_state %d\n",
@@ -4842,6 +5152,11 @@ inline unsigned int ata_host_intr (struct ata_port *ap,
4842 ap->ops->irq_clear(ap); 5152 ap->ops->irq_clear(ap);
4843 5153
4844 ata_hsm_move(ap, qc, status, 0); 5154 ata_hsm_move(ap, qc, status, 0);
5155
5156 if (unlikely(qc->err_mask) && (qc->tf.protocol == ATA_PROT_DMA ||
5157 qc->tf.protocol == ATA_PROT_ATAPI_DMA))
5158 ata_ehi_push_desc(ehi, "BMDMA stat 0x%x", host_stat);
5159
4845 return 1; /* irq handled */ 5160 return 1; /* irq handled */
4846 5161
4847idle_irq: 5162idle_irq:
@@ -5048,7 +5363,7 @@ int ata_flush_cache(struct ata_device *dev)
5048 if (!ata_try_flush_cache(dev)) 5363 if (!ata_try_flush_cache(dev))
5049 return 0; 5364 return 0;
5050 5365
5051 if (ata_id_has_flush_ext(dev->id)) 5366 if (dev->flags & ATA_DFLAG_FLUSH_EXT)
5052 cmd = ATA_CMD_FLUSH_EXT; 5367 cmd = ATA_CMD_FLUSH_EXT;
5053 else 5368 else
5054 cmd = ATA_CMD_FLUSH; 5369 cmd = ATA_CMD_FLUSH;
@@ -5520,9 +5835,8 @@ int ata_device_add(const struct ata_probe_ent *ent)
5520 ap->ioaddr.bmdma_addr, 5835 ap->ioaddr.bmdma_addr,
5521 irq_line); 5836 irq_line);
5522 5837
5523 ata_chk_status(ap); 5838 /* freeze port before requesting IRQ */
5524 host->ops->irq_clear(ap); 5839 ata_eh_freeze_port(ap);
5525 ata_eh_freeze_port(ap); /* freeze port before requesting IRQ */
5526 } 5840 }
5527 5841
5528 /* obtain irq, that may be shared between channels */ 5842 /* obtain irq, that may be shared between channels */
@@ -6120,6 +6434,7 @@ EXPORT_SYMBOL_GPL(__sata_phy_reset);
6120EXPORT_SYMBOL_GPL(ata_bus_reset); 6434EXPORT_SYMBOL_GPL(ata_bus_reset);
6121EXPORT_SYMBOL_GPL(ata_std_prereset); 6435EXPORT_SYMBOL_GPL(ata_std_prereset);
6122EXPORT_SYMBOL_GPL(ata_std_softreset); 6436EXPORT_SYMBOL_GPL(ata_std_softreset);
6437EXPORT_SYMBOL_GPL(sata_port_hardreset);
6123EXPORT_SYMBOL_GPL(sata_std_hardreset); 6438EXPORT_SYMBOL_GPL(sata_std_hardreset);
6124EXPORT_SYMBOL_GPL(ata_std_postreset); 6439EXPORT_SYMBOL_GPL(ata_std_postreset);
6125EXPORT_SYMBOL_GPL(ata_dev_classify); 6440EXPORT_SYMBOL_GPL(ata_dev_classify);
@@ -6146,6 +6461,7 @@ EXPORT_SYMBOL_GPL(ata_host_suspend);
6146EXPORT_SYMBOL_GPL(ata_host_resume); 6461EXPORT_SYMBOL_GPL(ata_host_resume);
6147EXPORT_SYMBOL_GPL(ata_id_string); 6462EXPORT_SYMBOL_GPL(ata_id_string);
6148EXPORT_SYMBOL_GPL(ata_id_c_string); 6463EXPORT_SYMBOL_GPL(ata_id_c_string);
6464EXPORT_SYMBOL_GPL(ata_device_blacklisted);
6149EXPORT_SYMBOL_GPL(ata_scsi_simulate); 6465EXPORT_SYMBOL_GPL(ata_scsi_simulate);
6150 6466
6151EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 6467EXPORT_SYMBOL_GPL(ata_pio_need_iordy);