Skip to contentSkip to conversation

add pata_arasan_cf support

PATCH Superseded Viresh Kumar 3 participants 12 messages Feb 18, 2011 – Feb 22, 2011

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 2/2 pata_arasan_cf: Adding support for arasan compact flash host controller

In reply to Viresh Kumar

The Arasan CompactFlash Device Controller has three basic modes of
operation: PC card ATA using I/O mode, PC card ATA using memory mode, PC card ATA using true IDE modes.

Currently driver supports only True IDE mode.

---
 MAINTAINERS                         |    7 +
 drivers/ata/Kconfig                 |    6 +
 drivers/ata/Makefile                |    1 +
 drivers/ata/pata_arasan_cf.c        |  945 +++++++++++++++++++++++++++++++++++
 include/linux/pata_arasan_cf_data.h |   47 ++
 5 files changed, 1006 insertions(+), 0 deletions(-)
 create mode 100644 drivers/ata/pata_arasan_cf.c
 create mode 100644 include/linux/pata_arasan_cf_data.h
MAINTAINERS +7 -0
index af8f8a6..9e864e1 100644
@@ -557,6 +557,13 @@ S:	Maintained
 F:	drivers/net/appletalk/
 F:	net/appletalk/
 
+ARASAN COMPACT FLASH PATA CONTROLLER
+M:	Viresh Kumar <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	include/linux/pata_arasan_cf_data.h
+F:	drivers/ata/pata_arasan_cf.c
+
 ARC FRAMEBUFFER DRIVER
 M:	Jaya Kumar <[email protected]>
 S:	Maintained
drivers/ata/Kconfig +6 -0
index c2328ae..81eac33 100644
@@ -299,6 +299,12 @@ config PATA_AMD
 
 	  If unsure, say N.
 
+config PATA_ARASAN_CF
+	tristate "ARASAN CompactFlash PATA Controller Support"
+	select DMA_ENGINE
+	help
+	  Say Y here to support the ARASAN CompactFlash PATA controller
+
 config PATA_ARTOP
 	tristate "ARTOP 6210/6260 PATA support"
 	depends on PCI
drivers/ata/Makefile +1 -0
index 27291aa..8ac64e1 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_SATA_DWC)		+= sata_dwc_460ex.o
 
 # SFF w/ custom DMA
 obj-$(CONFIG_PDC_ADMA)		+= pdc_adma.o
+obj-$(CONFIG_PATA_ARASAN_CF)	+= pata_arasan_cf.o
 obj-$(CONFIG_PATA_OCTEON_CF)	+= pata_octeon_cf.o
 obj-$(CONFIG_SATA_QSTOR)	+= sata_qstor.o
 obj-$(CONFIG_SATA_SX4)		+= sata_sx4.o
drivers/ata/pata_arasan_cf.c new file +945 -0

945 lines not on this page · raw message

include/linux/pata_arasan_cf_data.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#0 lore raw

v2 cover add pata_arasan_cf support

This patch series adds
- ata_sff_queue_work() & ata_sff_queue_delayed_work()
- add support for arasan compact flash controller.

Changes Since V1:
- add separate patch to introduce ata_sff_queue_work & ata_sff_queue_delayed_work
- remove arasan cf drivers workqueue.
- remove drivers/ata/pata_arasan_cf.h and put register definitions in pata_arasan_cf.c
- take ap->lock and host->lock at relevant places.
- use bool for variables which can have value 0 or 1.
- remove bmdma part and override freeze, qc_issue routines.
- introduce concept of delayed_work if altstatus reg reads ATA_BUSY after DMA xfer are over.

Viresh Kumar (2):
libata-sff: add ata_sff_queue_work() & ata_sff_queue_delayed_work()
pata_arasan_cf: Adding support for arasan compact flash host
controller

 MAINTAINERS                         |    7 +
 drivers/ata/Kconfig                 |    6 +
 drivers/ata/Makefile                |    1 +
 drivers/ata/libata-sff.c            |   15 +-
 drivers/ata/pata_arasan_cf.c        |  945 +++++++++++++++++++++++++++++++++++
 include/linux/libata.h              |    3 +
 include/linux/pata_arasan_cf_data.h |   47 ++
 7 files changed, 1022 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ata/pata_arasan_cf.c
 create mode 100644 include/linux/pata_arasan_cf_data.h
Signature · 1 line
1.7.2.2
#10 lore raw

PATCH 1/2 libata-sff: add ata_sff_queue_work() & ata_sff_queue_delayed_work()

This patch adds ata_sff_queue_work() & ata_sff_queue_delayed_work() routine in libata-sff.c file. This routine can be used by ata drivers to use ata_sff_wq.

---
 drivers/ata/libata-sff.c |   15 +++++++++++++--
 include/linux/libata.h   |    3 +++
 2 files changed, 16 insertions(+), 2 deletions(-)
drivers/ata/libata-sff.c +13 -2
index af6141b..a311b43 100644
@@ -1302,6 +1302,18 @@ fsm_start:
 }
 EXPORT_SYMBOL_GPL(ata_sff_hsm_move);
 
+void ata_sff_queue_work(struct work_struct *work)
+{
+	queue_work(ata_sff_wq, work);
+}
+EXPORT_SYMBOL_GPL(ata_sff_queue_work);
+
+void ata_sff_queue_delayed_work(struct delayed_work *dwork, unsigned long delay)
+{
+	queue_delayed_work(ata_sff_wq, dwork, delay);
+}
+EXPORT_SYMBOL_GPL(ata_sff_queue_delayed_work);
+
 void ata_sff_queue_pio_task(struct ata_link *link, unsigned long delay)
 {
 	struct ata_port *ap = link->ap;
@@ -1311,8 +1323,7 @@ void ata_sff_queue_pio_task(struct ata_link *link, unsigned long delay)
 	ap->sff_pio_task_link = link;
 
 	/* may fail if ata_sff_flush_pio_task() in progress */
-	queue_delayed_work(ata_sff_wq, &ap->sff_pio_task,
-			   msecs_to_jiffies(delay));
+	ata_sff_queue_delayed_work(&ap->sff_pio_task, msecs_to_jiffies(delay));
 }
 EXPORT_SYMBOL_GPL(ata_sff_queue_pio_task);
 
include/linux/libata.h +3 -0
index c9c5d7a..d506bc4 100644
@@ -1613,6 +1613,9 @@ extern void ata_sff_irq_on(struct ata_port *ap);
 extern void ata_sff_irq_clear(struct ata_port *ap);
 extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
 			    u8 status, int in_wq);
+extern void ata_sff_queue_work(struct work_struct *work);
+extern void ata_sff_queue_delayed_work(struct delayed_work *dwork,
+		unsigned long delay);
 extern void ata_sff_queue_pio_task(struct ata_link *link, unsigned long delay);
 extern unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc);
 extern bool ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
Signature · 1 line
1.7.2.2
Acked-by on v1 1/2
#11 lore raw

Re: [PATCH V1 1/2] libata-sff: add ata_sff_queue_work() & ata_sff_queue_delayed_work()

Quoted 4 lines · Viresh Kumar

This patch adds ata_sff_queue_work() & ata_sff_queue_delayed_work() routine in libata-sff.c file. This routine can be used by ata drivers to use ata_sff_wq.

Thanks.

Signature · 1 line
tejun
#2 lore raw

Re: [PATCH V2 2/2] pata_arasan_cf: Adding support for arasan compact flash host controller

In reply to Viresh Kumar

Hello,

drivers/ata/pata_arasan_cf.c line 223

Quoted 3 lines · Viresh Kumar
drivers/ata/pata_arasan_cf.c new file +3 -0
+static struct scsi_host_template arasan_cf_sht = {
+	ATA_PIO_SHT(DRIVER_NAME),
+};

Hmmm... You probably have different requirements for .sg_tablesize and .dma_boundary, likely to be more lax.

drivers/ata/pata_arasan_cf.c line 279

Quoted 7 lines
drivers/ata/pata_arasan_cf.c new file +7 -0
+static inline void cf_ctrl_reset(struct arasan_cf_dev *acdev)
+{
+	writel(readl(acdev->vbase + OP_MODE) & ~CFHOST_ENB, acdev->vbase +
+			OP_MODE);
+	writel(readl(acdev->vbase + OP_MODE) | CFHOST_ENB, acdev->vbase +
+			OP_MODE);
+}

No big deal but I think the following is more preferrable.

	writel(readl(acdev->vbase + OP_MODE) & ~CFHOST_ENB,
	       acdev->vbase + OP_MODE);

Applies to other similar line breaks too.

drivers/ata/pata_arasan_cf.c line 370

Quoted 11 lines
drivers/ata/pata_arasan_cf.c new file +11 -0
+static inline void dma_complete(struct arasan_cf_dev *acdev)
+{
+	struct ata_queued_cmd *qc = acdev->qc;
+
+	acdev->qc = NULL;
+	ata_sff_interrupt(acdev->irq, acdev->host);
+
+	if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol))
+		ata_ehi_push_desc(&qc->ap->link.eh_info, "DMA stat 0x%x",
+				ATA_DMA_INTR | ATA_DMA_ERR);
+}

Those are BMDMA status bits, right? Why not just print out string describing what's going on?

drivers/ata/pata_arasan_cf.c line 379

Quoted 8 lines
drivers/ata/pata_arasan_cf.c new file +8 -0
+static inline int wait4buf(struct arasan_cf_dev *acdev)
+{
+	if (!wait_for_completion_timeout(&acdev->cf_completion, TIMEOUT)) {
+		u32 rw = acdev->qc->tf.flags & ATA_TFLAG_WRITE;
+
+		dev_err(acdev->host->dev, "%s TimeOut", rw ? "write" : "read");
+		return -ETIMEDOUT;
+	}

Like here.

Hmmm... so, now there's a work item which requeues itself. That can't be reliably stopped from freeze() as it's called with host lock held without process context. I think you should override ->error_handler() which looks like the following,

arsan_error_handler(...)

{
	cancel_work_sync(...);
	cancel_delayed_work_sync(...);

	return ata_sff_error_handler(xxx);
}

Thanks.

Signature · 1 line
tejun
#3 lore raw

Re: [PATCH V2 2/2] pata_arasan_cf: Adding support for arasan compact flash host controller

Quoted 8 lines · Tejun Heo

drivers/ata/pata_arasan_cf.c line 223

Quoted 3 lines · Viresh Kumar
drivers/ata/pata_arasan_cf.c new file +3 -0
+static struct scsi_host_template arasan_cf_sht = {
+	ATA_PIO_SHT(DRIVER_NAME),
+};

Hmmm... You probably have different requirements for .sg_tablesize and .dma_boundary, likely to be more lax.

I will recheck this structure.

Quoted 10 lines

drivers/ata/pata_arasan_cf.c line 279

Quoted 7 lines
drivers/ata/pata_arasan_cf.c new file +7 -0
+static inline void cf_ctrl_reset(struct arasan_cf_dev *acdev)
+{
+	writel(readl(acdev->vbase + OP_MODE) & ~CFHOST_ENB, acdev->vbase +
+			OP_MODE);
+	writel(readl(acdev->vbase + OP_MODE) | CFHOST_ENB, acdev->vbase +
+			OP_MODE);
+}

No big deal but I think the following is more preferrable.

Quoted 5 lines
	writel(readl(acdev->vbase + OP_MODE) & ~CFHOST_ENB,
	       acdev->vbase + OP_MODE);

Applies to other similar line breaks too.

Ok

Quoted 6 lines
Quoted 6 lines
drivers/ata/pata_arasan_cf.c new file +6 -0
+static inline void dma_complete(struct arasan_cf_dev *acdev)
+{
+	struct ata_queued_cmd *qc = acdev->qc;
+
+	acdev->qc = NULL;
+	ata_sff_interrupt(acdev->irq, acdev->host);
Quoted 9 lines

drivers/ata/pata_arasan_cf.c line 370

Quoted 5 lines
drivers/ata/pata_arasan_cf.c new file +5 -0
+
+	if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol))
+		ata_ehi_push_desc(&qc->ap->link.eh_info, "DMA stat 0x%x",
+				ATA_DMA_INTR | ATA_DMA_ERR);
+}

Those are BMDMA status bits, right? Why not just print out string describing what's going on?

Ok.

Quoted 11 lines

drivers/ata/pata_arasan_cf.c line 379

Quoted 8 lines
drivers/ata/pata_arasan_cf.c new file +8 -0
+static inline int wait4buf(struct arasan_cf_dev *acdev)
+{
+	if (!wait_for_completion_timeout(&acdev->cf_completion, TIMEOUT)) {
+		u32 rw = acdev->qc->tf.flags & ATA_TFLAG_WRITE;
+
+		dev_err(acdev->host->dev, "%s TimeOut", rw ? "write" : "read");
+		return -ETIMEDOUT;
+	}

Like here.

Quoted 5 lines

Hmmm... so, now there's a work item which requeues itself. That can't be reliably stopped from freeze() as it's called with host lock held without process context. I think you should override ->error_handler() which looks like the following,

actually i am disabling controller in freeze. After which we will surely get timeout here and
so finally we will get an error in this work. Wouldn't that be enough?

Quoted 8 lines

arsan_error_handler(...)

{
	cancel_work_sync(...);
	cancel_delayed_work_sync(...);

	return ata_sff_error_handler(xxx);
}

thanks for your time & feedback.

--
viresh

#4 lore raw

Re: [PATCH V2 2/2] pata_arasan_cf: Adding support for arasan compact flash host controller

Hello,

Quoted 8 lines · viresh kumar
Quoted 4 lines

Hmmm... so, now there's a work item which requeues itself. That can't be reliably stopped from freeze() as it's called with host lock held without process context. I think you should override ->error_handler() which looks like the following,

actually i am disabling controller in freeze. After which we will surely get timeout here and
so finally we will get an error in this work. Wouldn't that be enough?

Hmmm... libata usually invokes EH right away after freeze(). It'll abort everything in flight and wake up the EH. freeze()'s job is to _try_ to quiesce the controller until reset and used when libata isn't sure which state the port is in, so I think you would still need to kill the work items on entry to EH. BTW, have you tested the EH paths? Inducing fake failures from interrupt handler and let things just slide so that timeout happens should do the trick.

Thanks.

Signature · 1 line
tejun
#5 lore raw

Re: [PATCH V2 2/2] pata_arasan_cf: Adding support for arasan compact flash host controller

Quoted 10 lines · Tejun Heo
Quoted 8 lines · viresh kumar
Quoted 4 lines

Hmmm... so, now there's a work item which requeues itself. That can't be reliably stopped from freeze() as it's called with host lock held without process context. I think you should override ->error_handler() which looks like the following,

actually i am disabling controller in freeze. After which we will surely get timeout here and
so finally we will get an error in this work. Wouldn't that be enough?

Quoted 8 lines

Hmmm... libata usually invokes EH right away after freeze(). It'll abort everything in flight and wake up the EH. freeze()'s job is to _try_ to quiesce the controller until reset and used when libata isn't sure which state the port is in, so I think you would still need to kill the work items on entry to EH. BTW, have you tested the EH paths? Inducing fake failures from interrupt handler and let things just slide so that timeout happens should do the trick.

I haven't done any such testing yet. What should i call for fake failures from interrupt handler. freeze()?? or As i am doing in dma_xfer for real
failures?

#6 lore raw

Re: [PATCH V2 2/2] pata_arasan_cf: Adding support for arasan compact flash host controller

Hello,

Quoted 3 lines · viresh kumar

I haven't done any such testing yet. What should i call for fake failures from interrupt handler. freeze()?? or As i am doing in dma_xfer for real failures?

Yeap, what the driver would do on actual failures and making sure things actually work as expected.

Thanks.

Signature · 1 line
tejun
#7 lore raw

Re: [PATCH V2 2/2] pata_arasan_cf: Adding support for arasan compact flash host controller

In reply to Tejun Heo
Quoted 7 lines · Tejun Heo
Quoted 3 lines · Viresh Kumar

drivers/ata/pata_arasan_cf.c line 223

Quoted 3 lines
drivers/ata/pata_arasan_cf.c new file +3 -0
+static struct scsi_host_template arasan_cf_sht = {
+	ATA_PIO_SHT(DRIVER_NAME),
+};

Hmmm... You probably have different requirements for .sg_tablesize and .dma_boundary, likely to be more lax.

Tejun,

Actually, we really don't have scatter-gather in our controller. We have to read/write to the same FIFO address for every 512 bytes, after which we get buf_avail interrupt. And Controller can do a maximum transfer of 256 KB after which it gives transfer complete interrupt.

So all sg has to be handled in software, framework or driver.

Also, we will always read/write from/to FIFO. And the external DMA controller doesn't have any limitation of this dma_boudary.

So i feel i should keep
.sg_tablesize = SG_ALL,
.dma_boundary = 0xFFFFFFFF,

Please correct me if i am wrong.

Signature · 1 line
viresh
#9 lore raw

Re: [PATCH V2 2/2] pata_arasan_cf: Adding support for arasan compact flash host controller

In reply to Tejun Heo
Quoted 5 lines · Tejun Heo

Hmmm... so, now there's a work item which requeues itself. That can't be reliably stopped from freeze() as it's called with host lock held without process context. I think you should override ->error_handler() which looks like the following,

Quoted 7 lines

arsan_error_handler(...)

{
	cancel_work_sync(...);
	cancel_delayed_work_sync(...);

	return ata_sff_error_handler(xxx);
}

Thanks for this. I implemented drivers error_handler and error cases are working fine now.

Signature · 1 line
viresh
#8 lore raw

Re: [PATCH V2 2/2] pata_arasan_cf: Adding support for arasan compact flash host controller

In reply to viresh kumar

Hello,

Quoted 6 lines · viresh kumar

Actually, we really don't have scatter-gather in our controller. We have to read/write to the same FIFO address for every 512 bytes, after which we get buf_avail interrupt. And Controller can do a maximum transfer of 256 KB after which it gives transfer complete interrupt.

So all sg has to be handled in software, framework or driver.

Yeap, so you don't need to follow the silly BMDMA restrictions.

Quoted 8 lines

Also, we will always read/write from/to FIFO. And the external DMA controller doesn't have any limitation of this dma_boudary.

So i feel i should keep
.sg_tablesize = SG_ALL,
.dma_boundary = 0xFFFFFFFF,

Please correct me if i am wrong.

Looks good to me.

Thanks.

Signature · 1 line
tejun