aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2010-05-10 15:41:38 -0400
committerJeff Garzik <jgarzik@redhat.com>2010-05-19 13:35:49 -0400
commitc429137a67b82788d24682153bb9c96501a9ef34 (patch)
treeb24ed75908f08cc9cddb19efc74fcb46be75de8f /drivers/ata
parent5fe7454aa9c6ef5fcf506b0f2dfc20f696891f1a (diff)
libata-sff: port_task is SFF specific
port_task is tightly bound to the standard SFF PIO HSM implementation. Using it for any other purpose would be error-prone and there's no such user and if some drivers need such feature, it would be much better off using its own. Move it inside CONFIG_ATA_SFF and rename it to sff_pio_task. The only function which is exposed to the core layer is ata_sff_flush_pio_task() which is renamed from ata_port_flush_task() and now also takes care of resetting hsm_task_state to HSM_ST_IDLE, which is possible as it's now specific to PIO HSM. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/libata-core.c69
-rw-r--r--drivers/ata/libata-eh.c4
-rw-r--r--drivers/ata/libata-sff.c72
-rw-r--r--drivers/ata/libata.h5
-rw-r--r--drivers/ata/sata_mv.c2
5 files changed, 61 insertions, 91 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index bf6ffc1273a0..c47373f01f89 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -97,7 +97,6 @@ static void ata_dev_xfermask(struct ata_device *dev);
97static unsigned long ata_dev_blacklisted(const struct ata_device *dev); 97static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
98 98
99unsigned int ata_print_id = 1; 99unsigned int ata_print_id = 1;
100static struct workqueue_struct *ata_wq;
101 100
102struct workqueue_struct *ata_aux_wq; 101struct workqueue_struct *ata_aux_wq;
103 102
@@ -1686,52 +1685,6 @@ unsigned long ata_id_xfermask(const u16 *id)
1686 return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask); 1685 return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
1687} 1686}
1688 1687
1689/**
1690 * ata_pio_queue_task - Queue port_task
1691 * @ap: The ata_port to queue port_task for
1692 * @data: data for @fn to use
1693 * @delay: delay time in msecs for workqueue function
1694 *
1695 * Schedule @fn(@data) for execution after @delay jiffies using
1696 * port_task. There is one port_task per port and it's the
1697 * user(low level driver)'s responsibility to make sure that only
1698 * one task is active at any given time.
1699 *
1700 * libata core layer takes care of synchronization between
1701 * port_task and EH. ata_pio_queue_task() may be ignored for EH
1702 * synchronization.
1703 *
1704 * LOCKING:
1705 * Inherited from caller.
1706 */
1707void ata_pio_queue_task(struct ata_port *ap, void *data, unsigned long delay)
1708{
1709 ap->port_task_data = data;
1710
1711 /* may fail if ata_port_flush_task() in progress */
1712 queue_delayed_work(ata_wq, &ap->port_task, msecs_to_jiffies(delay));
1713}
1714
1715/**
1716 * ata_port_flush_task - Flush port_task
1717 * @ap: The ata_port to flush port_task for
1718 *
1719 * After this function completes, port_task is guranteed not to
1720 * be running or scheduled.
1721 *
1722 * LOCKING:
1723 * Kernel thread context (may sleep)
1724 */
1725void ata_port_flush_task(struct ata_port *ap)
1726{
1727 DPRINTK("ENTER\n");
1728
1729 cancel_rearming_delayed_work(&ap->port_task);
1730
1731 if (ata_msg_ctl(ap))
1732 ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __func__);
1733}
1734
1735static void ata_qc_complete_internal(struct ata_queued_cmd *qc) 1688static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
1736{ 1689{
1737 struct completion *waiting = qc->private_data; 1690 struct completion *waiting = qc->private_data;
@@ -1853,7 +1806,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1853 1806
1854 rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout)); 1807 rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout));
1855 1808
1856 ata_port_flush_task(ap); 1809 ata_sff_flush_pio_task(ap);
1857 1810
1858 if (!rc) { 1811 if (!rc) {
1859 spin_lock_irqsave(ap->lock, flags); 1812 spin_lock_irqsave(ap->lock, flags);
@@ -5646,11 +5599,6 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
5646 ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN; 5599 ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
5647#endif 5600#endif
5648 5601
5649#ifdef CONFIG_ATA_SFF
5650 INIT_DELAYED_WORK(&ap->port_task, ata_pio_task);
5651#else
5652 INIT_DELAYED_WORK(&ap->port_task, NULL);
5653#endif
5654 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); 5602 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);
5655 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); 5603 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
5656 INIT_LIST_HEAD(&ap->eh_done_q); 5604 INIT_LIST_HEAD(&ap->eh_done_q);
@@ -6588,17 +6536,6 @@ static int __init ata_init(void)
6588 6536
6589 ata_parse_force_param(); 6537 ata_parse_force_param();
6590 6538
6591 /*
6592 * FIXME: In UP case, there is only one workqueue thread and if you
6593 * have more than one PIO device, latency is bloody awful, with
6594 * occasional multi-second "hiccups" as one PIO device waits for
6595 * another. It's an ugly wart that users DO occasionally complain
6596 * about; luckily most users have at most one PIO polled device.
6597 */
6598 ata_wq = create_workqueue("ata");
6599 if (!ata_wq)
6600 goto fail;
6601
6602 ata_aux_wq = create_singlethread_workqueue("ata_aux"); 6539 ata_aux_wq = create_singlethread_workqueue("ata_aux");
6603 if (!ata_aux_wq) 6540 if (!ata_aux_wq)
6604 goto fail; 6541 goto fail;
@@ -6612,8 +6549,6 @@ static int __init ata_init(void)
6612 6549
6613fail: 6550fail:
6614 kfree(ata_force_tbl); 6551 kfree(ata_force_tbl);
6615 if (ata_wq)
6616 destroy_workqueue(ata_wq);
6617 if (ata_aux_wq) 6552 if (ata_aux_wq)
6618 destroy_workqueue(ata_aux_wq); 6553 destroy_workqueue(ata_aux_wq);
6619 return rc; 6554 return rc;
@@ -6623,7 +6558,6 @@ static void __exit ata_exit(void)
6623{ 6558{
6624 ata_sff_exit(); 6559 ata_sff_exit();
6625 kfree(ata_force_tbl); 6560 kfree(ata_force_tbl);
6626 destroy_workqueue(ata_wq);
6627 destroy_workqueue(ata_aux_wq); 6561 destroy_workqueue(ata_aux_wq);
6628} 6562}
6629 6563
@@ -6777,7 +6711,6 @@ EXPORT_SYMBOL_GPL(ata_id_c_string);
6777EXPORT_SYMBOL_GPL(ata_do_dev_read_id); 6711EXPORT_SYMBOL_GPL(ata_do_dev_read_id);
6778EXPORT_SYMBOL_GPL(ata_scsi_simulate); 6712EXPORT_SYMBOL_GPL(ata_scsi_simulate);
6779 6713
6780EXPORT_SYMBOL_GPL(ata_pio_queue_task);
6781EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 6714EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
6782EXPORT_SYMBOL_GPL(ata_timing_find_mode); 6715EXPORT_SYMBOL_GPL(ata_timing_find_mode);
6783EXPORT_SYMBOL_GPL(ata_timing_compute); 6716EXPORT_SYMBOL_GPL(ata_timing_compute);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 228740f356c9..d6e67488174c 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -550,8 +550,8 @@ void ata_scsi_error(struct Scsi_Host *host)
550 550
551 DPRINTK("ENTER\n"); 551 DPRINTK("ENTER\n");
552 552
553 /* synchronize with port task */ 553 /* make sure sff pio task is not running */
554 ata_port_flush_task(ap); 554 ata_sff_flush_pio_task(ap);
555 555
556 /* synchronize with host lock and sort out timeouts */ 556 /* synchronize with host lock and sort out timeouts */
557 557
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 8a1396f52a3a..e78ad76861f4 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -40,6 +40,8 @@
40 40
41#include "libata.h" 41#include "libata.h"
42 42
43static struct workqueue_struct *ata_sff_wq;
44
43const struct ata_port_operations ata_sff_port_ops = { 45const struct ata_port_operations ata_sff_port_ops = {
44 .inherits = &ata_base_port_ops, 46 .inherits = &ata_base_port_ops,
45 47
@@ -1293,7 +1295,7 @@ fsm_start:
1293 if (in_wq) 1295 if (in_wq)
1294 spin_unlock_irqrestore(ap->lock, flags); 1296 spin_unlock_irqrestore(ap->lock, flags);
1295 1297
1296 /* if polling, ata_pio_task() handles the rest. 1298 /* if polling, ata_sff_pio_task() handles the rest.
1297 * otherwise, interrupt handler takes over from here. 1299 * otherwise, interrupt handler takes over from here.
1298 */ 1300 */
1299 break; 1301 break;
@@ -1458,14 +1460,38 @@ fsm_start:
1458} 1460}
1459EXPORT_SYMBOL_GPL(ata_sff_hsm_move); 1461EXPORT_SYMBOL_GPL(ata_sff_hsm_move);
1460 1462
1461void ata_pio_task(struct work_struct *work) 1463void ata_sff_queue_pio_task(struct ata_port *ap, unsigned long delay)
1464{
1465 /* may fail if ata_sff_flush_pio_task() in progress */
1466 queue_delayed_work(ata_sff_wq, &ap->sff_pio_task,
1467 msecs_to_jiffies(delay));
1468}
1469EXPORT_SYMBOL_GPL(ata_sff_queue_pio_task);
1470
1471void ata_sff_flush_pio_task(struct ata_port *ap)
1472{
1473 DPRINTK("ENTER\n");
1474
1475 cancel_rearming_delayed_work(&ap->sff_pio_task);
1476 ap->hsm_task_state = HSM_ST_IDLE;
1477
1478 if (ata_msg_ctl(ap))
1479 ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __func__);
1480}
1481
1482static void ata_sff_pio_task(struct work_struct *work)
1462{ 1483{
1463 struct ata_port *ap = 1484 struct ata_port *ap =
1464 container_of(work, struct ata_port, port_task.work); 1485 container_of(work, struct ata_port, sff_pio_task.work);
1465 struct ata_queued_cmd *qc = ap->port_task_data; 1486 struct ata_queued_cmd *qc;
1466 u8 status; 1487 u8 status;
1467 int poll_next; 1488 int poll_next;
1468 1489
1490 /* qc can be NULL if timeout occurred */
1491 qc = ata_qc_from_tag(ap, ap->link.active_tag);
1492 if (!qc)
1493 return;
1494
1469fsm_start: 1495fsm_start:
1470 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE); 1496 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE);
1471 1497
@@ -1481,7 +1507,7 @@ fsm_start:
1481 msleep(2); 1507 msleep(2);
1482 status = ata_sff_busy_wait(ap, ATA_BUSY, 10); 1508 status = ata_sff_busy_wait(ap, ATA_BUSY, 10);
1483 if (status & ATA_BUSY) { 1509 if (status & ATA_BUSY) {
1484 ata_pio_queue_task(ap, qc, ATA_SHORT_PAUSE); 1510 ata_sff_queue_pio_task(ap, ATA_SHORT_PAUSE);
1485 return; 1511 return;
1486 } 1512 }
1487 } 1513 }
@@ -1551,7 +1577,7 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
1551 ap->hsm_task_state = HSM_ST_LAST; 1577 ap->hsm_task_state = HSM_ST_LAST;
1552 1578
1553 if (qc->tf.flags & ATA_TFLAG_POLLING) 1579 if (qc->tf.flags & ATA_TFLAG_POLLING)
1554 ata_pio_queue_task(ap, qc, 0); 1580 ata_sff_queue_pio_task(ap, 0);
1555 1581
1556 break; 1582 break;
1557 1583
@@ -1573,20 +1599,21 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
1573 if (qc->tf.flags & ATA_TFLAG_WRITE) { 1599 if (qc->tf.flags & ATA_TFLAG_WRITE) {
1574 /* PIO data out protocol */ 1600 /* PIO data out protocol */
1575 ap->hsm_task_state = HSM_ST_FIRST; 1601 ap->hsm_task_state = HSM_ST_FIRST;
1576 ata_pio_queue_task(ap, qc, 0); 1602 ata_sff_queue_pio_task(ap, 0);
1577 1603
1578 /* always send first data block using 1604 /* always send first data block using the
1579 * the ata_pio_task() codepath. 1605 * ata_sff_pio_task() codepath.
1580 */ 1606 */
1581 } else { 1607 } else {
1582 /* PIO data in protocol */ 1608 /* PIO data in protocol */
1583 ap->hsm_task_state = HSM_ST; 1609 ap->hsm_task_state = HSM_ST;
1584 1610
1585 if (qc->tf.flags & ATA_TFLAG_POLLING) 1611 if (qc->tf.flags & ATA_TFLAG_POLLING)
1586 ata_pio_queue_task(ap, qc, 0); 1612 ata_sff_queue_pio_task(ap, 0);
1587 1613
1588 /* if polling, ata_pio_task() handles the rest. 1614 /* if polling, ata_sff_pio_task() handles the
1589 * otherwise, interrupt handler takes over from here. 1615 * rest. otherwise, interrupt handler takes
1616 * over from here.
1590 */ 1617 */
1591 } 1618 }
1592 1619
@@ -1604,7 +1631,7 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
1604 /* send cdb by polling if no cdb interrupt */ 1631 /* send cdb by polling if no cdb interrupt */
1605 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || 1632 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) ||
1606 (qc->tf.flags & ATA_TFLAG_POLLING)) 1633 (qc->tf.flags & ATA_TFLAG_POLLING))
1607 ata_pio_queue_task(ap, qc, 0); 1634 ata_sff_queue_pio_task(ap, 0);
1608 break; 1635 break;
1609 1636
1610 case ATAPI_PROT_DMA: 1637 case ATAPI_PROT_DMA:
@@ -1616,7 +1643,7 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
1616 1643
1617 /* send cdb by polling if no cdb interrupt */ 1644 /* send cdb by polling if no cdb interrupt */
1618 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) 1645 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
1619 ata_pio_queue_task(ap, qc, 0); 1646 ata_sff_queue_pio_task(ap, 0);
1620 break; 1647 break;
1621 1648
1622 default: 1649 default:
@@ -2360,8 +2387,6 @@ void ata_sff_error_handler(struct ata_port *ap)
2360 /* reset PIO HSM and stop DMA engine */ 2387 /* reset PIO HSM and stop DMA engine */
2361 spin_lock_irqsave(ap->lock, flags); 2388 spin_lock_irqsave(ap->lock, flags);
2362 2389
2363 ap->hsm_task_state = HSM_ST_IDLE;
2364
2365 if (ap->ioaddr.bmdma_addr && 2390 if (ap->ioaddr.bmdma_addr &&
2366 qc && (qc->tf.protocol == ATA_PROT_DMA || 2391 qc && (qc->tf.protocol == ATA_PROT_DMA ||
2367 qc->tf.protocol == ATAPI_PROT_DMA)) { 2392 qc->tf.protocol == ATAPI_PROT_DMA)) {
@@ -2432,8 +2457,6 @@ void ata_sff_post_internal_cmd(struct ata_queued_cmd *qc)
2432 2457
2433 spin_lock_irqsave(ap->lock, flags); 2458 spin_lock_irqsave(ap->lock, flags);
2434 2459
2435 ap->hsm_task_state = HSM_ST_IDLE;
2436
2437 if (ap->ioaddr.bmdma_addr) 2460 if (ap->ioaddr.bmdma_addr)
2438 ap->ops->bmdma_stop(qc); 2461 ap->ops->bmdma_stop(qc);
2439 2462
@@ -3074,15 +3097,28 @@ EXPORT_SYMBOL_GPL(ata_pci_bmdma_init);
3074 */ 3097 */
3075void ata_sff_port_init(struct ata_port *ap) 3098void ata_sff_port_init(struct ata_port *ap)
3076{ 3099{
3100 INIT_DELAYED_WORK(&ap->sff_pio_task, ata_sff_pio_task);
3077 ap->ctl = ATA_DEVCTL_OBS; 3101 ap->ctl = ATA_DEVCTL_OBS;
3078 ap->last_ctl = 0xFF; 3102 ap->last_ctl = 0xFF;
3079} 3103}
3080 3104
3081int __init ata_sff_init(void) 3105int __init ata_sff_init(void)
3082{ 3106{
3107 /*
3108 * FIXME: In UP case, there is only one workqueue thread and if you
3109 * have more than one PIO device, latency is bloody awful, with
3110 * occasional multi-second "hiccups" as one PIO device waits for
3111 * another. It's an ugly wart that users DO occasionally complain
3112 * about; luckily most users have at most one PIO polled device.
3113 */
3114 ata_sff_wq = create_workqueue("ata_sff");
3115 if (!ata_sff_wq)
3116 return -ENOMEM;
3117
3083 return 0; 3118 return 0;
3084} 3119}
3085 3120
3086void __exit ata_sff_exit(void) 3121void __exit ata_sff_exit(void)
3087{ 3122{
3123 destroy_workqueue(ata_sff_wq);
3088} 3124}
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index d89502f3123a..002390cdc041 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -79,7 +79,6 @@ extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
79 u64 block, u32 n_block, unsigned int tf_flags, 79 u64 block, u32 n_block, unsigned int tf_flags,
80 unsigned int tag); 80 unsigned int tag);
81extern u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev); 81extern u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev);
82extern void ata_port_flush_task(struct ata_port *ap);
83extern unsigned ata_exec_internal(struct ata_device *dev, 82extern unsigned ata_exec_internal(struct ata_device *dev,
84 struct ata_taskfile *tf, const u8 *cdb, 83 struct ata_taskfile *tf, const u8 *cdb,
85 int dma_dir, void *buf, unsigned int buflen, 84 int dma_dir, void *buf, unsigned int buflen,
@@ -202,11 +201,13 @@ static inline int sata_pmp_attach(struct ata_device *dev)
202 201
203/* libata-sff.c */ 202/* libata-sff.c */
204#ifdef CONFIG_ATA_SFF 203#ifdef CONFIG_ATA_SFF
205extern void ata_pio_task(struct work_struct *work); 204extern void ata_sff_flush_pio_task(struct ata_port *ap);
206extern void ata_sff_port_init(struct ata_port *ap); 205extern void ata_sff_port_init(struct ata_port *ap);
207extern int ata_sff_init(void); 206extern int ata_sff_init(void);
208extern void ata_sff_exit(void); 207extern void ata_sff_exit(void);
209#else /* CONFIG_ATA_SFF */ 208#else /* CONFIG_ATA_SFF */
209static inline void ata_sff_flush_pio_task(struct ata_port *ap)
210{ }
210static inline void ata_sff_port_init(struct ata_port *ap) 211static inline void ata_sff_port_init(struct ata_port *ap)
211{ } 212{ }
212static inline int ata_sff_init(void) 213static inline int ata_sff_init(void)
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 83491861d110..fb0d2c1d8417 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -2262,7 +2262,7 @@ static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
2262 } 2262 }
2263 2263
2264 if (qc->tf.flags & ATA_TFLAG_POLLING) 2264 if (qc->tf.flags & ATA_TFLAG_POLLING)
2265 ata_pio_queue_task(ap, qc, 0); 2265 ata_sff_queue_pio_task(ap, 0);
2266 return 0; 2266 return 0;
2267} 2267}
2268 2268