Skip to contentSkip to conversation

libata: add R-Car SATA driver

PATCH In review Sergei Shtylyov 2 participants 10 messages Feb 20, 2013 – May 28, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 libata: add R-Car SATA driver

From: Vladimir Barinov <[email protected]>

Add Renesas R-Car on-chip 3Gbps SATA controller driver.

[Sergei: few bugs fixed, significant cleanup]

---
This time, I'm reposting only this patch, others haven't changed. It should apply (with offsets) to libata-dev.git, 'upstream' branch, although has been generated against another tree...

Changes since v2:
- fixed sata_rcar_interrupt() returning with spinlock held / IRQs disabled.

No changes since v1.

 drivers/ata/Kconfig     |    8 
 drivers/ata/Makefile    |    1 
 drivers/ata/sata_rcar.c |  910 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 919 insertions(+)
drivers/ata/Kconfig +8 -0
Index: renesas/drivers/ata/Kconfig
===================================================================
@@ -247,6 +247,14 @@ config SATA_PROMISE
 
 	  If unsure, say N.
 
+config SATA_RCAR
+	tristate "Renesas R-Car SATA support"
+	depends on ARCH_SHMOBILE && ARCH_R8A7779
+	help
+	  This option enables support for Renesas R-Car Serial ATA.
+
+	  If unsure, say N.
+
 config SATA_SIL
 	tristate "Silicon Image SATA support"
 	depends on PCI
drivers/ata/Makefile +1 -0
Index: renesas/drivers/ata/Makefile
===================================================================
@@ -23,6 +23,7 @@ obj-$(CONFIG_ATA_PIIX)		+= ata_piix.o
 obj-$(CONFIG_SATA_MV)		+= sata_mv.o
 obj-$(CONFIG_SATA_NV)		+= sata_nv.o
 obj-$(CONFIG_SATA_PROMISE)	+= sata_promise.o
+obj-$(CONFIG_SATA_RCAR)		+= sata_rcar.o
 obj-$(CONFIG_SATA_SIL)		+= sata_sil.o
 obj-$(CONFIG_SATA_SIS)		+= sata_sis.o
 obj-$(CONFIG_SATA_SVW)		+= sata_svw.o
drivers/ata/sata_rcar.c new file +910 -0

910 lines not on this page · raw message

#1 lore raw

Hello.

On 02/20/2013 11:10 PM, Sergei Shtylyov wrote:

Tejun, a question for you... see below.

Quoted 6 lines

From: Vladimir Barinov <[email protected]>

Add Renesas R-Car on-chip 3Gbps SATA controller driver.

[Sergei: few bugs fixed, significant cleanup]

Not all bugs turned out to be fixed... :-/

Quoted 1 line

[...]

Quoted 5 lines

Index: renesas/drivers/ata/sata_rcar.c
===================================================================

drivers/ata/sata_rcar.c new file +0 -0
@@ -0,0 +1,910 @@

[...]

Quoted 12 lines
drivers/ata/sata_rcar.c new file +12 -0
+static void sata_rcar_bmdma_fill_sg(struct ata_queued_cmd *qc)
+{
+	struct ata_port *ap = qc->ap;
+	struct ata_bmdma_prd *prd = ap->bmdma_prd;
+	struct scatterlist *sg;
+	unsigned int si, pi;
+
+	pi = 0;
+	for_each_sg(qc->sg, sg, qc->n_elem, si) {
+		u32 addr, sg_len, len;
+
+		/*

drivers/ata/sata_rcar.c line 492

Quoted 10 lines
drivers/ata/sata_rcar.c new file +10 -0
+		 * Note: h/w doesn't support 64-bit, so we unconditionally
+		 * truncate dma_addr_t to u32.
+		 */
+		addr = (u32)sg_dma_address(sg);
+		sg_len = sg_dma_len(sg);
+
+		/* H/w transfer count is only 29 bits long, let's be careful */
+		while (sg_len) {
+			len = sg_len;
+			if (len > 0x1ffffffe)

This value should have been put into the 'dma_boundary' field of the
'struct scsi_host_template', IIUC. Tejun, if I do it, do I need this check at all?

Quoted 15 lines
drivers/ata/sata_rcar.c new file +15 -0
+				len = 0x1ffffffe;
+
+			prd[pi].addr = cpu_to_le32(addr);
+			prd[pi].flags_len = cpu_to_le32(len);
+			VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len);
+
+			pi++;
+			sg_len -= len;
+			addr += len;
+		}
+	}
+
+	/* end-of-table flag */
+	prd[pi - 1].addr |= cpu_to_le32(SATA_RCAR_DTEND);
+}

[...]

drivers/ata/sata_rcar.c line 590

Quoted 3 lines
drivers/ata/sata_rcar.c new file +3 -0
+static struct scsi_host_template sata_rcar_sht = {
+	ATA_BMDMA_SHT(DRV_NAME),
+};

This should have been ATA_BASE_SHT() and the proepr values
specified for
the 'sg_tablesize' and 'dma_boundary' fields. R-Car SATA descriptors are not the same as SFF-8038i, they allow up to 512 megs of data to be specified in one descriptor and don't care about 64KiB boundaries.

WBR, Sergei

#2 lore raw

Hello.

Quoted 37 lines · Sergei Shtylyov

Tejun, a question for you... see below.

Quoted 6 lines

From: Vladimir Barinov <[email protected]>

Add Renesas R-Car on-chip 3Gbps SATA controller driver.

[Sergei: few bugs fixed, significant cleanup]

Not all bugs turned out to be fixed... :-/

Quoted 1 line

[...]

Quoted 5 lines

Index: renesas/drivers/ata/sata_rcar.c
===================================================================

drivers/ata/sata_rcar.c new file +0 -0
@@ -0,0 +1,910 @@

[...]

Quoted 17 lines
drivers/ata/sata_rcar.c new file +17 -0
+static void sata_rcar_bmdma_fill_sg(struct ata_queued_cmd *qc)
+{
+    struct ata_port *ap = qc->ap;
+    struct ata_bmdma_prd *prd = ap->bmdma_prd;
+    struct scatterlist *sg;
+    unsigned int si, pi;
+
+    pi = 0;
+    for_each_sg(qc->sg, sg, qc->n_elem, si) {
+        u32 addr, sg_len, len;
+
+        /*
+         * Note: h/w doesn't support 64-bit, so we unconditionally
+         * truncate dma_addr_t to u32.
+         */
+        addr = (u32)sg_dma_address(sg);
+        sg_len = sg_dma_len(sg);
Quoted 8 lines

drivers/ata/sata_rcar.c line 492

Quoted 5 lines
drivers/ata/sata_rcar.c new file +5 -0
+
+        /* H/w transfer count is only 29 bits long, let's be careful */
+        while (sg_len) {
+            len = sg_len;
+            if (len > 0x1ffffffe)

This value should have been put into the 'dma_boundary' field of the
'struct scsi_host_template', IIUC. Tejun, if I do it, do I need this check at all?

You haven't replied, so I went and searched an answer myself. Indeed,
it's enough to specify the right 'dma_boundary' and stop bothering about it. Expect two patches to the driver. I think the correct branch for them will be 'for-3.11'.

WBR, Sergei

#3 lore raw

Hey,

Quoted 9 lines · Sergei Shtylyov
Quoted 3 lines

This value should have been put into the 'dma_boundary' field of the
'struct scsi_host_template', IIUC. Tejun, if I do it, do I need this check at all?

You haven't replied, so I went and searched an answer myself. Indeed,
it's enough to specify the right 'dma_boundary' and stop bothering about it. Expect two patches to the driver. I think the correct branch for them will be
'for-3.11'.

I was just about to reply. Yes, it should be enough. Both block layer and the dma machniery honors the DMA boundary and segment size, which are configured from __scsi_alloc_queue().

Thanks!

Signature · 1 line
tejun
#4 lore raw
Quoted 13 lines · Tejun Heo

Hey,

Quoted 9 lines · Sergei Shtylyov
Quoted 3 lines

This value should have been put into the 'dma_boundary' field of the
'struct scsi_host_template', IIUC. Tejun, if I do it, do I need this check at all?

You haven't replied, so I went and searched an answer myself. Indeed,
it's enough to specify the right 'dma_boundary' and stop bothering about it. Expect two patches to the driver. I think the correct branch for them will be
'for-3.11'.

Quoted 3 lines

I was just about to reply. Yes, it should be enough. Both block layer and the dma machniery honors the DMA boundary and segment size, which are configured from __scsi_alloc_queue().

But I'm a bit confused about ata_bmdma_fill_sg(). ATA_BMDMA_SHT sets the DMA boundary to 0xffff, so I have no idea why it's explicitly checking the DMA boundary in the function again. What am I missing?

Signature · 1 line
tejun
#5 lore raw
Quoted 12 lines · Tejun Heo
Quoted 11 lines · Tejun Heo

Hey,

Quoted 8 lines · Sergei Shtylyov
Quoted 3 lines

This value should have been put into the 'dma_boundary' field of the
'struct scsi_host_template', IIUC. Tejun, if I do it, do I need this check at all?

You haven't replied, so I went and searched an answer myself. Indeed,
it's enough to specify the right 'dma_boundary' and stop bothering about it. Expect two patches to the driver. I think the correct branch for them will be
'for-3.11'.

Quoted 6 lines
Quoted 3 lines

I was just about to reply. Yes, it should be enough. Both block layer and the dma machniery honors the DMA boundary and segment size, which are configured from __scsi_alloc_queue().

But I'm a bit confused about ata_bmdma_fill_sg(). ATA_BMDMA_SHT sets the DMA boundary to 0xffff, so I have no idea why it's explicitly checking the DMA boundary in the function again. What am I missing?

Because with SFF-8038i (BMIDE) controllers transfer can't cross
64KiB address boundaries. This function has to break up those S/G entries that do cross them. I.e. the PRD length is actually additionally limited by an offset of its start within 64KiB memory segment. Does this make sense? Or does the block layer already care about this? Hm, I'm not confident now, should revisit this after some sleep.

WBR, Sergei

#6 lore raw

Hello, Sergei.

Quoted 6 lines · Sergei Shtylyov

Because with SFF-8038i (BMIDE) controllers transfer can't cross
64KiB address boundaries. This function has to break up those S/G entries that do cross them. I.e. the PRD length is actually additionally limited by an offset of its start within 64KiB memory segment. Does this make sense? Or does the block layer already care about this? Hm, I'm not confident now, should revisit this after some sleep.

Yeah, that's exactly where I'm confused. ATA_DMA_BOUNDARY is 64k which becomes both queue_segment_boundary and dma seg_boundary. AFAICS, both __blk_segment_map_sg() and dma mapping won't merge across seg_boundary and as each bvec is a single page at most, we shouldn't need to worry about getting sg's which cross 64k boundaries in bmdma controllers. Hmmmmm...... I gotta be missing something. What am I missing here?

Thanks.

Signature · 1 line
tejun
#7 lore raw

Hello.

Quoted 7 lines · Tejun Heo
Quoted 7 lines

Because with SFF-8038i (BMIDE) controllers transfer can't cross
64KiB address boundaries. This function has to break up those S/G entries that do cross them. I.e. the PRD length is actually additionally limited by an offset of its start within 64KiB memory segment. Does this make sense? Or does the block layer already care about this? Hm, I'm not confident now, should revisit this after some sleep.

Quoted 7 lines

Yeah, that's exactly where I'm confused. ATA_DMA_BOUNDARY is 64k which becomes both queue_segment_boundary and dma seg_boundary. AFAICS, both __blk_segment_map_sg() and dma mapping won't merge across seg_boundary and as each bvec is a single page at most, we shouldn't need to worry about getting sg's which cross 64k boundaries in bmdma controllers. Hmmmmm...... I gotta be missing something. What am I missing here?

Probably nothing... maybe Jeff just copied that from ATADRVR
(which was his inspiration IIRC).
BTW, I've just done some experimentation with my R-Car target
and ATA_DEBUG/ATA_VERBOSE_DEBUG #define'd and it turned out that block layer didn't merge any segments at all... :-/

Quoted 2 lines

Thanks.

WBR, Sergei

#8 lore raw

Hello, Sergei.

Quoted 10 lines · Sergei Shtylyov
Quoted 7 lines

Yeah, that's exactly where I'm confused. ATA_DMA_BOUNDARY is 64k which becomes both queue_segment_boundary and dma seg_boundary. AFAICS, both __blk_segment_map_sg() and dma mapping won't merge across seg_boundary and as each bvec is a single page at most, we shouldn't need to worry about getting sg's which cross 64k boundaries in bmdma controllers. Hmmmmm...... I gotta be missing something. What am I missing here?

Probably nothing... maybe Jeff just copied that from ATADRVR
(which was his inspiration IIRC).

Yeah, maybe. I can't find any reason why ata_bmdma_fill_sg() would need to worry about 64k boundary. The dumb variant is putting an extra restriction on it but the plain one doesn't seem to be adding anything. Would you be interested in submitting a patch to remove those?

Quoted 3 lines

BTW, I've just done some experimentation with my R-Car target
and ATA_DEBUG/ATA_VERBOSE_DEBUG #define'd and it turned out that block layer didn't merge any segments at all... :-/

Even the ones with contiguous physical addresses? It could just be that the physical pages are disjoint as we don't really do anything to allocate pages contiguously and iommus don't kick in / merge unless necessary (it's not like modern hardware struggle with sglists anyway), so it could just be that there's nothing to merge.

Thanks.

Signature · 1 line
tejun
#9 lore raw
Quoted 10 lines · Tejun Heo
Quoted 10 lines
Quoted 7 lines

Yeah, that's exactly where I'm confused. ATA_DMA_BOUNDARY is 64k which becomes both queue_segment_boundary and dma seg_boundary. AFAICS, both __blk_segment_map_sg() and dma mapping won't merge across seg_boundary and as each bvec is a single page at most, we shouldn't need to worry about getting sg's which cross 64k boundaries in bmdma controllers. Hmmmmm...... I gotta be missing something. What am I missing here?

Probably nothing... maybe Jeff just copied that from ATADRVR
(which was his inspiration IIRC).

Maybe we should ask him instead of guessing. :-)

Quoted 5 lines

Yeah, maybe. I can't find any reason why ata_bmdma_fill_sg() would need to worry about 64k boundary. The dumb variant is putting an extra restriction on it but the plain one doesn't seem to be adding anything. Would you be interested in submitting a patch to remove those?

Hm, at least not right now. I'm too busy.

Quoted 5 lines
Quoted 3 lines

BTW, I've just done some experimentation with my R-Car target
and ATA_DEBUG/ATA_VERBOSE_DEBUG #define'd and it turned out that block layer didn't merge any segments at all... :-/

Even the ones with contiguous physical addresses?

Exactly. All DMA segments were 4K in size, regardless of whether
the addresses were adjacent or not.

Quoted 5 lines

It could just be
that the physical pages are disjoint as we don't really do anything to allocate pages contiguously and iommus don't kick in / merge unless necessary (it's not like modern hardware struggle with sglists anyway), so it could just be that there's nothing to merge.

There were mergeable segments, for sure.

Quoted 1 line

Thanks.

MBR, Sergei