Skip to contentSkip to conversation

libata: kill qc->nsect and cursect

PATCH In review Tejun Heo 2 participants 5 messages Dec 16, 2006 libata

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/3 libata: kill qc->nsect and cursect

libata used two separate sets of variables to record request size and current offset for ATA and ATAPI. This is confusing and fragile. This patch replaces qc->nsect/cursect with qc->nbytes/curbytes and kills them. Also, ata_pio_sector() is updated to use bytes for qc->cursg_ofs instead of sectors. The field used to be used in bytes for ATAPI and in sectors for ATA.

---
 drivers/ata/libata-core.c       |   15 ++++++++-------
 drivers/ata/libata-eh.c         |    7 +------
 drivers/ata/libata-scsi.c       |    4 ++--
 drivers/ata/pata_pdc202xx_old.c |    5 +----
 drivers/ata/sata_qstor.c        |    2 +-
 include/linux/libata.h          |    6 +-----
 6 files changed, 14 insertions(+), 25 deletions(-)
drivers/ata/libata-core.c +8 -7
index fd20e7a..2a496d0 100644
@@ -1249,7 +1249,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
 			buflen += sg[i].length;
 
 		ata_sg_init(qc, sg, n_elem);
-		qc->nsect = buflen / ATA_SECT_SIZE;
+		qc->nbytes = buflen;
 	}
 
 	qc->private_data = &wait;
@@ -4031,11 +4031,11 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
 	unsigned int offset;
 	unsigned char *buf;
 
-	if (qc->cursect == (qc->nsect - 1))
+	if (qc->curbytes == qc->nbytes - ATA_SECT_SIZE)
 		ap->hsm_task_state = HSM_ST_LAST;
 
 	page = sg[qc->cursg].page;
-	offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE;
+	offset = sg[qc->cursg].offset + qc->cursg_ofs;
 
 	/* get the current page and offset */
 	page = nth_page(page, (offset >> PAGE_SHIFT));
@@ -4060,10 +4060,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
 		ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write);
 	}
 
-	qc->cursect++;
-	qc->cursg_ofs++;
+	qc->curbytes += ATA_SECT_SIZE;
+	qc->cursg_ofs += ATA_SECT_SIZE;
 
-	if ((qc->cursg_ofs * ATA_SECT_SIZE) == (&sg[qc->cursg])->length) {
+	if (qc->cursg_ofs == (&sg[qc->cursg])->length) {
 		qc->cursg++;
 		qc->cursg_ofs = 0;
 	}
@@ -4088,7 +4088,8 @@ static void ata_pio_sectors(struct ata_queued_cmd *qc)
 
 		WARN_ON(qc->dev->multi_count == 0);
 
-		nsect = min(qc->nsect - qc->cursect, qc->dev->multi_count);
+		nsect = min((qc->nbytes - qc->curbytes) / ATA_SECT_SIZE,
+			    qc->dev->multi_count);
 		while (nsect--)
 			ata_pio_sector(qc);
 	} else
drivers/ata/libata-eh.c +1 -6
index 08ad44b..dee403c 100644
@@ -1443,15 +1443,10 @@ static void ata_eh_report(struct ata_port *ap)
 		};
 		struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
 		struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf;
-		unsigned int nbytes;
 
 		if (!(qc->flags & ATA_QCFLAG_FAILED) || !qc->err_mask)
 			continue;
 
-		nbytes = qc->nbytes;
-		if (!nbytes)
-			nbytes = qc->nsect << 9;
-
 		ata_dev_printk(qc->dev, KERN_ERR,
 			"cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
 			"tag %d cdb 0x%x data %u %s\n         "
@@ -1461,7 +1456,7 @@ static void ata_eh_report(struct ata_port *ap)
 			cmd->lbal, cmd->lbam, cmd->lbah,
 			cmd->hob_feature, cmd->hob_nsect,
 			cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah,
-			cmd->device, qc->tag, qc->cdb[0], nbytes,
+			cmd->device, qc->tag, qc->cdb[0], qc->nbytes,
 			dma_str[qc->dma_dir],
 			res->command, res->feature, res->nsect,
 			res->lbal, res->lbam, res->lbah,
drivers/ata/libata-scsi.c +2 -2
index f82871c..e8a352d 100644
@@ -1323,7 +1323,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
 		goto nothing_to_do;
 
 	qc->flags |= ATA_QCFLAG_IO;
-	qc->nsect = n_block;
+	qc->nbytes = n_block * ATA_SECT_SIZE;
 
 	rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags,
 			     qc->tag);
@@ -2626,7 +2626,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc)
 	 * TODO: find out if we need to do more here to
 	 *       cover scatter/gather case.
 	 */
-	qc->nsect = scmd->request_bufflen / ATA_SECT_SIZE;
+	qc->nbytes = scmd->request_bufflen;
 
 	/* request result TF */
 	qc->flags |= ATA_QCFLAG_RESULT_TF;
drivers/ata/pata_pdc202xx_old.c +1 -4
index ad691b9..ba982ba 100644
@@ -189,10 +189,7 @@ static void pdc2026x_bmdma_start(struct ata_queued_cmd *qc)
 	/* Cases the state machine will not complete correctly without help */
 	if ((tf->flags & ATA_TFLAG_LBA48) ||  tf->protocol == ATA_PROT_ATAPI_DMA)
 	{
-		if (tf->flags & ATA_TFLAG_LBA48)
-			len = qc->nsect * 512;
-		else
-			len = qc->nbytes;
+		len = qc->nbytes;
 
 		if (tf->flags & ATA_TFLAG_WRITE)
 			len |= 0x06000000;
drivers/ata/sata_qstor.c +1 -1
index 710909d..0292a79 100644
@@ -325,7 +325,7 @@ static void qs_qc_prep(struct ata_queued_cmd *qc)
 	/* host control block (HCB) */
 	buf[ 0] = QS_HCB_HDR;
 	buf[ 1] = hflags;
-	*(__le32 *)(&buf[ 4]) = cpu_to_le32(qc->nsect * ATA_SECT_SIZE);
+	*(__le32 *)(&buf[ 4]) = cpu_to_le32(qc->nbytes);
 	*(__le32 *)(&buf[ 8]) = cpu_to_le32(nelem);
 	addr = ((u64)pp->pkt_dma) + QS_CPB_BYTES;
 	*(__le64 *)(&buf[16]) = cpu_to_le64(addr);
include/linux/libata.h +1 -5
index 9356322..b7c86b4 100644
@@ -430,9 +430,6 @@ struct ata_queued_cmd {
 
 	unsigned int		pad_len;
 
-	unsigned int		nsect;
-	unsigned int		cursect;
-
 	unsigned int		nbytes;
 	unsigned int		curbytes;
 
@@ -1145,8 +1142,7 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
 {
 	qc->__sg = NULL;
 	qc->flags = 0;
-	qc->cursect = qc->cursg = qc->cursg_ofs = 0;
-	qc->nsect = 0;
+	qc->cursg = qc->cursg_ofs = 0;
 	qc->nbytes = qc->curbytes = 0;
 	qc->err_mask = 0;
 
Signature · 1 line
1.4.4.2
author
#1 lore raw

PATCH 2/3 libata: implement max_segment_size

libata depeneded on sht->dma_boundary for demtermining maximum segment size. This is good enough for most controllers but inic1622 just had to be different and it locks up if segement size is 65536 while dma_boundary is 0xffff.

This patch implements ap->max_segment_size which can be initialized via probe_ent (or port_info) and used in ->slave_config to configure maximum segment size. LLDs without braindamage can leave this alone.

---
 drivers/ata/libata-core.c |    3 +++
 drivers/ata/libata-scsi.c |    9 +++++++++
 include/linux/libata.h    |    3 +++
 3 files changed, 15 insertions(+), 0 deletions(-)
drivers/ata/libata-core.c +3 -0
index 2a496d0..b28a313 100644
@@ -5620,12 +5620,14 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
 		ap->pio_mask = ent->pinfo2->pio_mask;
 		ap->mwdma_mask = ent->pinfo2->mwdma_mask;
 		ap->udma_mask = ent->pinfo2->udma_mask;
+		ap->max_segment_size = ent->max_segment_size;
 		ap->flags |= ent->pinfo2->flags;
 		ap->ops = ent->pinfo2->port_ops;
 	} else {
 		ap->pio_mask = ent->pio_mask;
 		ap->mwdma_mask = ent->mwdma_mask;
 		ap->udma_mask = ent->udma_mask;
+		ap->max_segment_size = ent->max_segment_size;
 		ap->flags |= ent->port_flags;
 		ap->ops = ent->port_ops;
 	}
@@ -6110,6 +6112,7 @@ ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
 	probe_ent->pio_mask = port->pio_mask;
 	probe_ent->mwdma_mask = port->mwdma_mask;
 	probe_ent->udma_mask = port->udma_mask;
+	probe_ent->max_segment_size = port->max_segment_size;
 	probe_ent->port_ops = port->port_ops;
 	probe_ent->private_data = port->private_data;
 
drivers/ata/libata-scsi.c +9 -0
index e8a352d..f817d13 100644
@@ -823,6 +823,15 @@ static void ata_scsi_dev_config(struct scsi_device *sdev,
 		depth = min(ATA_MAX_QUEUE - 1, depth);
 		scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth);
 	}
+
+	/* max_segment_size setting is usually not necessary as it's
+	 * automatically determined from sht->dma_boundary, but some
+	 * controllers need smaller max_segement_size than the value
+	 * determined by sht->dma_boundary.
+	 */
+	if (dev->ap->max_segment_size)
+		blk_queue_max_segment_size(sdev->request_queue,
+					   dev->ap->max_segment_size);
 }
 
 /**
include/linux/libata.h +3 -0
index b7c86b4..bdf7fc5 100644
@@ -379,6 +379,7 @@ struct ata_probe_ent {
 	unsigned int		pio_mask;
 	unsigned int		mwdma_mask;
 	unsigned int		udma_mask;
+	size_t			max_segment_size;	/* optional */
 	unsigned long		irq;
 	unsigned long		irq2;
 	unsigned int		irq_flags;
@@ -550,6 +551,7 @@ struct ata_port {
 	unsigned int		pio_mask;
 	unsigned int		mwdma_mask;
 	unsigned int		udma_mask;
+	size_t			max_segment_size; /* optional */
 	unsigned int		cbl;	/* cable type; ATA_CBL_xxx */
 	unsigned int		hw_sata_spd_limit;
 	unsigned int		sata_spd_limit;	/* SATA PHY speed limit */
@@ -658,6 +660,7 @@ struct ata_port_info {
 	unsigned long		pio_mask;
 	unsigned long		mwdma_mask;
 	unsigned long		udma_mask;
+	size_t			max_segment_size;	/* optional */
 	const struct ata_port_operations *port_ops;
 	void 			*private_data;
 };
Signature · 1 line
1.4.4.2
author
#2 lore raw

PATCH 3/3 sata_inic162x: finally, driver for initio 162x SATA controllers

Driver for Initio 162x SATA controllers. ATA r/w, ATAPI r, hotplug and suspend/resume work. ATAPI w (recording, that is) broken. Feel free to fix it, but be warned, this controller is weird.

---
 drivers/ata/Kconfig         |    6 +
 drivers/ata/Makefile        |    1 +
 drivers/ata/sata_inic162x.c |  793 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 800 insertions(+), 0 deletions(-)
drivers/ata/Kconfig +6 -0
index fb1de86..95df246 100644
@@ -143,6 +143,12 @@ config SATA_VITESSE
 
 	  If unsure, say N.
 
+config SATA_INIC162X
+	tristate "Initio 162x SATA support"
+	depends on PCI
+	help
+	  This option enables support for Initio 162x Serial ATA.
+
 config SATA_INTEL_COMBINED
 	bool
 	depends on IDE=y && !BLK_DEV_IDE_SATA && (SATA_AHCI || ATA_PIIX)
drivers/ata/Makefile +1 -0
index a0df15d..cd096f0 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_SATA_SX4)		+= sata_sx4.o
 obj-$(CONFIG_SATA_NV)		+= sata_nv.o
 obj-$(CONFIG_SATA_ULI)		+= sata_uli.o
 obj-$(CONFIG_SATA_MV)		+= sata_mv.o
+obj-$(CONFIG_SATA_INIC162X)	+= sata_inic162x.o
 obj-$(CONFIG_PDC_ADMA)		+= pdc_adma.o
 
 obj-$(CONFIG_PATA_ALI)		+= pata_ali.o
drivers/ata/sata_inic162x.c new file +793 -0

793 lines not on this page · raw message

Signature · 1 line
1.4.4.2
#3 lore raw

Re: [PATCH 2/3] libata: implement max_segment_size

In reply to Tejun Heo
Quoted 10 lines · Tejun Heo

libata depeneded on sht->dma_boundary for demtermining maximum segment size. This is good enough for most controllers but inic1622 just had to be different and it locks up if segement size is 65536 while dma_boundary is 0xffff.

This patch implements ap->max_segment_size which can be initialized via probe_ent (or port_info) and used in ->slave_config to configure maximum segment size. LLDs without braindamage can leave this alone.

Just implement a custom ->slave_config in the driver. There is no need to add anything to probe_ent, port, and port_info.

Jeff

author
#4 lore raw

Okay, ppl. Here's driver for inic162x.

In reply to Tejun Heo

These three patches implement sata_inic162x. As usual, the patches are against the current libata-dev#upstream (b6c0159899e9742f5462ae3ee19e6573aa47b5d8).

It seems to run pretty stable on my machine but I'm the developer and no one should trust my testing. So, knock yourself out. Remember, this is still in alpha stage. Put your precious xxx collection somewhere else.

Anyone interested in patch against 2.6.19? If there's enough need I can make one to accelerate testing.

Signature · 1 line
tejun