Skip to contentSkip to conversation

libata queue updated

PATCH In review Jeff Garzik 3 participants 10 messages Jan 28, 2006 – Jan 31, 2006

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

PATCH 1/1 libata queue updated

Testing and merge point in Tejun's flood of patches :) The patch below is against current linux-2.6.git.

The 'upstream' branch of rsync://rsync.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev.git

contains the following updates:

 drivers/scsi/ahci.c         |  108 ++++---
 drivers/scsi/ata_piix.c     |   54 ++-
 drivers/scsi/libata-core.c  |  625 +++++++++++++++++++++++++++++++++-----------
 drivers/scsi/libata-scsi.c  |  140 ++++++---
 drivers/scsi/libata.h       |    2 
 drivers/scsi/pdc_adma.c     |    4 
 drivers/scsi/sata_mv.c      |   18 -
 drivers/scsi/sata_promise.c |  120 ++++++--
 drivers/scsi/sata_qstor.c   |    4 
 drivers/scsi/sata_sil24.c   |   16 -
 drivers/scsi/sata_sx4.c     |   16 -
 drivers/scsi/scsi_error.c   |    7 
 include/linux/ata.h         |   12 
 include/linux/libata.h      |   98 +++++-
 include/scsi/scsi_eh.h      |    3 
 15 files changed, 872 insertions(+), 355 deletions(-)

Albert Lee:
libata CHS: LBA28/LBA48 optimization (revise #6)

Jeff Garzik:
[libata ata_piix] Fix ICH6/7 map value interpretation

Luke Kosewski:
[libata sata_promise] add correct read/write of hotplug registers for SATAII devices

Randy Dunlap:

Various libata documentation updates.

Tejun Heo:
libata: separate out ata_sata_print_link_status
ahci: separate out ahci_stop/start_engine
ahci: separate out ahci_dev_classify
ata_piix: fix MAP VALUE interpretation for for ICH6/7
libata: fold __ata_qc_complete() into ata_qc_free()
libata: make the owner of a qc responsible for freeing it
libata: fix ata_qc_issue() error handling
ahci: fix err_mask setting in ahci_host_intr
libata: add detailed AC_ERR_* flags
libata: return AC_ERR_* from issue functions
SCSI: export scsi_eh_finish_cmd() and scsi_eh_flush_done_q()
libata: implement and apply ata_eh_qc_complete/retry()
libata: create pio/atapi task queueing wrappers
ahci: stop engine during hard reset
ahci: add constants for SRST
libata: export ata_busy_sleep
libata: modify ata_dev_try_classify
libata: new ->probe_reset operation
libata: implement ata_drive_probe_reset()
libata: implement standard reset component operations and ->probe_reset

drivers/scsi/ahci.c +68 -40
index 19bd346..5caf6de 100644
@@ -66,6 +66,8 @@ enum {
 	AHCI_IRQ_ON_SG		= (1 << 31),
 	AHCI_CMD_ATAPI		= (1 << 5),
 	AHCI_CMD_WRITE		= (1 << 6),
+	AHCI_CMD_RESET		= (1 << 8),
+	AHCI_CMD_CLR_BUSY	= (1 << 10),
 
 	RX_FIS_D2H_REG		= 0x40,	/* offset of D2H Register FIS data */
 
@@ -85,6 +87,7 @@ enum {
 
 	/* HOST_CAP bits */
 	HOST_CAP_64		= (1 << 31), /* PCI DAC (64-bit DMA) support */
+	HOST_CAP_CLO		= (1 << 24), /* Command List Override support */
 
 	/* registers for each SATA port */
 	PORT_LST_ADDR		= 0x00, /* command list DMA addr */
@@ -138,6 +141,7 @@ enum {
 	PORT_CMD_LIST_ON	= (1 << 15), /* cmd list DMA engine running */
 	PORT_CMD_FIS_ON		= (1 << 14), /* FIS DMA engine running */
 	PORT_CMD_FIS_RX		= (1 << 4), /* Enable FIS receive DMA engine */
+	PORT_CMD_CLO		= (1 << 3), /* Command list override */
 	PORT_CMD_POWER_ON	= (1 << 2), /* Power up device */
 	PORT_CMD_SPIN_UP	= (1 << 1), /* Spin up device */
 	PORT_CMD_START		= (1 << 0), /* Enable port DMA engine */
@@ -184,7 +188,7 @@ struct ahci_port_priv {
 static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg);
 static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
 static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
-static int ahci_qc_issue(struct ata_queued_cmd *qc);
+static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
 static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
 static void ahci_phy_reset(struct ata_port *ap);
 static void ahci_irq_clear(struct ata_port *ap);
@@ -446,25 +450,72 @@ static void ahci_scr_write (struct ata_p
 	writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
 }
 
-static void ahci_phy_reset(struct ata_port *ap)
+static int ahci_stop_engine(struct ata_port *ap)
+{
+	void __iomem *mmio = ap->host_set->mmio_base;
+	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
+	int work;
+	u32 tmp;
+
+	tmp = readl(port_mmio + PORT_CMD);
+	tmp &= ~PORT_CMD_START;
+	writel(tmp, port_mmio + PORT_CMD);
+
+	/* wait for engine to stop.  TODO: this could be
+	 * as long as 500 msec
+	 */
+	work = 1000;
+	while (work-- > 0) {
+		tmp = readl(port_mmio + PORT_CMD);
+		if ((tmp & PORT_CMD_LIST_ON) == 0)
+			return 0;
+		udelay(10);
+	}
+
+	return -EIO;
+}
+
+static void ahci_start_engine(struct ata_port *ap)
+{
+	void __iomem *mmio = ap->host_set->mmio_base;
+	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
+	u32 tmp;
+
+	tmp = readl(port_mmio + PORT_CMD);
+	tmp |= PORT_CMD_START;
+	writel(tmp, port_mmio + PORT_CMD);
+	readl(port_mmio + PORT_CMD); /* flush */
+}
+
+static unsigned int ahci_dev_classify(struct ata_port *ap)
 {
 	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
 	struct ata_taskfile tf;
+	u32 tmp;
+
+	tmp = readl(port_mmio + PORT_SIG);
+	tf.lbah		= (tmp >> 24)	& 0xff;
+	tf.lbam		= (tmp >> 16)	& 0xff;
+	tf.lbal		= (tmp >> 8)	& 0xff;
+	tf.nsect	= (tmp)		& 0xff;
+
+	return ata_dev_classify(&tf);
+}
+
+static void ahci_phy_reset(struct ata_port *ap)
+{
+	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
 	struct ata_device *dev = &ap->device[0];
 	u32 new_tmp, tmp;
 
+	ahci_stop_engine(ap);
 	__sata_phy_reset(ap);
+	ahci_start_engine(ap);
 
 	if (ap->flags & ATA_FLAG_PORT_DISABLED)
 		return;
 
-	tmp = readl(port_mmio + PORT_SIG);
-	tf.lbah		= (tmp >> 24)	& 0xff;
-	tf.lbam		= (tmp >> 16)	& 0xff;
-	tf.lbal		= (tmp >> 8)	& 0xff;
-	tf.nsect	= (tmp)		& 0xff;
-
-	dev->class = ata_dev_classify(&tf);
+	dev->class = ahci_dev_classify(ap);
 	if (!ata_dev_present(dev)) {
 		ata_port_disable(ap);
 		return;
@@ -572,7 +623,6 @@ static void ahci_restart_port(struct ata
 	void __iomem *mmio = ap->host_set->mmio_base;
 	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
 	u32 tmp;
-	int work;
 
 	if ((ap->device[0].class != ATA_DEV_ATAPI) ||
 	    ((irq_stat & PORT_IRQ_TF_ERR) == 0))
@@ -588,20 +638,7 @@ static void ahci_restart_port(struct ata
 			readl(port_mmio + PORT_SCR_ERR));
 
 	/* stop DMA */
-	tmp = readl(port_mmio + PORT_CMD);
-	tmp &= ~PORT_CMD_START;
-	writel(tmp, port_mmio + PORT_CMD);
-
-	/* wait for engine to stop.  TODO: this could be
-	 * as long as 500 msec
-	 */
-	work = 1000;
-	while (work-- > 0) {
-		tmp = readl(port_mmio + PORT_CMD);
-		if ((tmp & PORT_CMD_LIST_ON) == 0)
-			break;
-		udelay(10);
-	}
+	ahci_stop_engine(ap);
 
 	/* clear SATA phy error, if any */
 	tmp = readl(port_mmio + PORT_SCR_ERR);
@@ -620,10 +657,7 @@ static void ahci_restart_port(struct ata
 	}
 
 	/* re-start DMA */
-	tmp = readl(port_mmio + PORT_CMD);
-	tmp |= PORT_CMD_START;
-	writel(tmp, port_mmio + PORT_CMD);
-	readl(port_mmio + PORT_CMD); /* flush */
+	ahci_start_engine(ap);
 }
 
 static void ahci_eng_timeout(struct ata_port *ap)
@@ -644,19 +678,13 @@ static void ahci_eng_timeout(struct ata_
 		       ap->id);
 	} else {
 		ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT));
-
-		/* hack alert!  We cannot use the supplied completion
-	 	 * function from inside the ->eh_strategy_handler() thread.
-	 	 * libata is the only user of ->eh_strategy_handler() in
-	 	 * any kernel, so the default scsi_done() assumes it is
-	 	 * not being called from the SCSI EH.
-	 	 */
-		qc->scsidone = scsi_finish_command;
-		qc->err_mask |= AC_ERR_OTHER;
-		ata_qc_complete(qc);
+		qc->err_mask |= AC_ERR_TIMEOUT;
 	}
 
 	spin_unlock_irqrestore(&host_set->lock, flags);
+
+	if (qc)
+		ata_eh_qc_complete(qc);
 }
 
 static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
@@ -693,7 +721,7 @@ static inline int ahci_host_intr(struct 
 		ahci_restart_port(ap, status);
 
 		if (qc) {
-			qc->err_mask |= AC_ERR_OTHER;
+			qc->err_mask |= err_mask;
 			ata_qc_complete(qc);
 		}
 	}
@@ -772,7 +800,7 @@ static irqreturn_t ahci_interrupt (int i
 	return IRQ_RETVAL(handled);
 }
 
-static int ahci_qc_issue(struct ata_queued_cmd *qc)
+static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
 {
 	struct ata_port *ap = qc->ap;
 	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
drivers/scsi/ata_piix.c +40 -14

107 lines not on this page · raw message

drivers/scsi/libata-core.c +471 -154

986 lines not on this page · raw message

drivers/scsi/libata-scsi.c +91 -49

264 lines not on this page · raw message

drivers/scsi/libata.h +1 -1
index e03ce48..9d76923 100644
@@ -45,7 +45,7 @@ extern struct ata_queued_cmd *ata_qc_new
 				      struct ata_device *dev);
 extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc);
 extern void ata_qc_free(struct ata_queued_cmd *qc);
-extern int ata_qc_issue(struct ata_queued_cmd *qc);
+extern unsigned int ata_qc_issue(struct ata_queued_cmd *qc);
 extern int ata_check_atapi_dma(struct ata_queued_cmd *qc);
 extern void ata_dev_select(struct ata_port *ap, unsigned int device,
                            unsigned int wait, unsigned int can_sleep);
drivers/scsi/pdc_adma.c +2 -2
index e8df0c9..3a6bf58 100644
@@ -131,7 +131,7 @@ static void adma_host_stop(struct ata_ho
 static void adma_port_stop(struct ata_port *ap);
 static void adma_phy_reset(struct ata_port *ap);
 static void adma_qc_prep(struct ata_queued_cmd *qc);
-static int adma_qc_issue(struct ata_queued_cmd *qc);
+static unsigned int adma_qc_issue(struct ata_queued_cmd *qc);
 static int adma_check_atapi_dma(struct ata_queued_cmd *qc);
 static void adma_bmdma_stop(struct ata_queued_cmd *qc);
 static u8 adma_bmdma_status(struct ata_port *ap);
@@ -419,7 +419,7 @@ static inline void adma_packet_start(str
 	writew(aPIOMD4 | aGO, chan + ADMA_CONTROL);
 }
 
-static int adma_qc_issue(struct ata_queued_cmd *qc)
+static unsigned int adma_qc_issue(struct ata_queued_cmd *qc)
 {
 	struct adma_port_priv *pp = qc->ap->private_data;
 
drivers/scsi/sata_mv.c +4 -14
index cd54244..d9a554c 100644
@@ -328,7 +328,7 @@ static void mv_host_stop(struct ata_host
 static int mv_port_start(struct ata_port *ap);
 static void mv_port_stop(struct ata_port *ap);
 static void mv_qc_prep(struct ata_queued_cmd *qc);
-static int mv_qc_issue(struct ata_queued_cmd *qc);
+static unsigned int mv_qc_issue(struct ata_queued_cmd *qc);
 static irqreturn_t mv_interrupt(int irq, void *dev_instance,
 				struct pt_regs *regs);
 static void mv_eng_timeout(struct ata_port *ap);
@@ -1040,7 +1040,7 @@ static void mv_qc_prep(struct ata_queued
  *      LOCKING:
  *      Inherited from caller.
  */
-static int mv_qc_issue(struct ata_queued_cmd *qc)
+static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
 {
 	void __iomem *port_mmio = mv_ap_base(qc->ap);
 	struct mv_port_priv *pp = qc->ap->private_data;
@@ -1839,7 +1839,6 @@ static void mv_phy_reset(struct ata_port
 static void mv_eng_timeout(struct ata_port *ap)
 {
 	struct ata_queued_cmd *qc;
-	unsigned long flags;
 
 	printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id);
 	DPRINTK("All regs @ start of eng_timeout\n");
@@ -1858,17 +1857,8 @@ static void mv_eng_timeout(struct ata_po
 		printk(KERN_ERR "ata%u: BUG: timeout without command\n",
 		       ap->id);
 	} else {
-		/* hack alert!  We cannot use the supplied completion
-	 	 * function from inside the ->eh_strategy_handler() thread.
-	 	 * libata is the only user of ->eh_strategy_handler() in
-	 	 * any kernel, so the default scsi_done() assumes it is
-	 	 * not being called from the SCSI EH.
-	 	 */
-		spin_lock_irqsave(&ap->host_set->lock, flags);
-		qc->scsidone = scsi_finish_command;
-		qc->err_mask |= AC_ERR_OTHER;
-		ata_qc_complete(qc);
-		spin_unlock_irqrestore(&ap->host_set->lock, flags);
+		qc->err_mask |= AC_ERR_TIMEOUT;
+		ata_eh_qc_complete(qc);
 	}
 }
 
drivers/scsi/sata_promise.c +86 -34

301 lines not on this page · raw message

drivers/scsi/sata_qstor.c +2 -2
index de05e28..2afbeb7 100644
@@ -120,7 +120,7 @@ static void qs_host_stop(struct ata_host
 static void qs_port_stop(struct ata_port *ap);
 static void qs_phy_reset(struct ata_port *ap);
 static void qs_qc_prep(struct ata_queued_cmd *qc);
-static int qs_qc_issue(struct ata_queued_cmd *qc);
+static unsigned int qs_qc_issue(struct ata_queued_cmd *qc);
 static int qs_check_atapi_dma(struct ata_queued_cmd *qc);
 static void qs_bmdma_stop(struct ata_queued_cmd *qc);
 static u8 qs_bmdma_status(struct ata_port *ap);
@@ -352,7 +352,7 @@ static inline void qs_packet_start(struc
 	readl(chan + QS_CCT_CFF);          /* flush */
 }
 
-static int qs_qc_issue(struct ata_queued_cmd *qc)
+static unsigned int qs_qc_issue(struct ata_queued_cmd *qc)
 {
 	struct qs_port_priv *pp = qc->ap->private_data;
 
drivers/scsi/sata_sil24.c +4 -12
index 9231301..7222fc7 100644
@@ -251,7 +251,7 @@ static void sil24_scr_write(struct ata_p
 static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
 static void sil24_phy_reset(struct ata_port *ap);
 static void sil24_qc_prep(struct ata_queued_cmd *qc);
-static int sil24_qc_issue(struct ata_queued_cmd *qc);
+static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc);
 static void sil24_irq_clear(struct ata_port *ap);
 static void sil24_eng_timeout(struct ata_port *ap);
 static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
@@ -557,7 +557,7 @@ static void sil24_qc_prep(struct ata_que
 		sil24_fill_sg(qc, sge);
 }
 
-static int sil24_qc_issue(struct ata_queued_cmd *qc)
+static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc)
 {
 	struct ata_port *ap = qc->ap;
 	void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
@@ -644,17 +644,9 @@ static void sil24_eng_timeout(struct ata
 		return;
 	}
 
-	/*
-	 * hack alert!  We cannot use the supplied completion
-	 * function from inside the ->eh_strategy_handler() thread.
-	 * libata is the only user of ->eh_strategy_handler() in
-	 * any kernel, so the default scsi_done() assumes it is
-	 * not being called from the SCSI EH.
-	 */
 	printk(KERN_ERR "ata%u: command timeout\n", ap->id);
-	qc->scsidone = scsi_finish_command;
-	qc->err_mask |= AC_ERR_OTHER;
-	ata_qc_complete(qc);
+	qc->err_mask |= AC_ERR_TIMEOUT;
+	ata_eh_qc_complete(qc);
 
 	sil24_reset_controller(ap);
 }
drivers/scsi/sata_sx4.c +4 -12
index bc87c16..9f992fb 100644
@@ -174,7 +174,7 @@ static void pdc20621_get_from_dimm(struc
 static void pdc20621_put_to_dimm(struct ata_probe_ent *pe,
 				 void *psource, u32 offset, u32 size);
 static void pdc20621_irq_clear(struct ata_port *ap);
-static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc);
+static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc);
 
 
 static struct scsi_host_template pdc_sata_sht = {
@@ -678,7 +678,7 @@ static void pdc20621_packet_start(struct
 	}
 }
 
-static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc)
+static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc)
 {
 	switch (qc->tf.protocol) {
 	case ATA_PROT_DMA:
@@ -872,20 +872,11 @@ static void pdc_eng_timeout(struct ata_p
 		goto out;
 	}
 
-	/* hack alert!  We cannot use the supplied completion
-	 * function from inside the ->eh_strategy_handler() thread.
-	 * libata is the only user of ->eh_strategy_handler() in
-	 * any kernel, so the default scsi_done() assumes it is
-	 * not being called from the SCSI EH.
-	 */
-	qc->scsidone = scsi_finish_command;
-
 	switch (qc->tf.protocol) {
 	case ATA_PROT_DMA:
 	case ATA_PROT_NODATA:
 		printk(KERN_ERR "ata%u: command timeout\n", ap->id);
 		qc->err_mask |= __ac_err_mask(ata_wait_idle(ap));
-		ata_qc_complete(qc);
 		break;
 
 	default:
@@ -895,12 +886,13 @@ static void pdc_eng_timeout(struct ata_p
 		       ap->id, qc->tf.command, drv_stat);
 
 		qc->err_mask |= ac_err_mask(drv_stat);
-		ata_qc_complete(qc);
 		break;
 	}
 
 out:
 	spin_unlock_irqrestore(&host_set->lock, flags);
+	if (qc)
+		ata_eh_qc_complete(qc);
 	DPRINTK("EXIT\n");
 }
 
drivers/scsi/scsi_error.c +4 -3
index a2333d2..6bac3d2 100644
@@ -584,8 +584,7 @@ static int scsi_request_sense(struct scs
  *    keep a list of pending commands for final completion, and once we
  *    are ready to leave error handling we handle completion for real.
  **/
-static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
-			       struct list_head *done_q)
+void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q)
 {
 	scmd->device->host->host_failed--;
 	scmd->eh_eflags = 0;
@@ -597,6 +596,7 @@ static void scsi_eh_finish_cmd(struct sc
 	scsi_setup_cmd_retry(scmd);
 	list_move_tail(&scmd->eh_entry, done_q);
 }
+EXPORT_SYMBOL(scsi_eh_finish_cmd);
 
 /**
  * scsi_eh_get_sense - Get device sense data.
@@ -1425,7 +1425,7 @@ static void scsi_eh_ready_devs(struct Sc
  * @done_q:	list_head of processed commands.
  *
  **/
-static void scsi_eh_flush_done_q(struct list_head *done_q)
+void scsi_eh_flush_done_q(struct list_head *done_q)
 {
 	struct scsi_cmnd *scmd, *next;
 
@@ -1454,6 +1454,7 @@ static void scsi_eh_flush_done_q(struct 
 		}
 	}
 }
+EXPORT_SYMBOL(scsi_eh_flush_done_q);
 
 /**
  * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
include/linux/ata.h +12 -0
index 94f77cc..a8155ca 100644
@@ -302,4 +302,16 @@ static inline int ata_ok(u8 status)
 			== ATA_DRDY);
 }
 
+static inline int lba_28_ok(u64 block, u32 n_block)
+{
+	/* check the ending block number */
+	return ((block + n_block - 1) < ((u64)1 << 28)) && (n_block <= 256);
+}
+
+static inline int lba_48_ok(u64 block, u32 n_block)
+{
+	/* check the ending block number */
+	return ((block + n_block - 1) < ((u64)1 << 48)) && (n_block <= 65536);
+}
+
 #endif /* __LINUX_ATA_H__ */
include/linux/libata.h +80 -18

200 lines not on this page · raw message

include/scsi/scsi_eh.h +3 -0
index fabd879..d160880 100644
@@ -35,6 +35,9 @@ static inline int scsi_sense_valid(struc
 }
 
 
+extern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
+			       struct list_head *done_q);
+extern void scsi_eh_flush_done_q(struct list_head *done_q);
 extern void scsi_report_bus_reset(struct Scsi_Host *, int);
 extern void scsi_report_device_reset(struct Scsi_Host *, int, int);
 extern int scsi_block_when_processing_errors(struct scsi_device *);
#1 lore raw

Hi Jeff,

Quoted 2 lines · Jeff Garzik

Testing and merge point in Tejun's flood of patches :) The patch below is against current linux-2.6.git.

These "function(unsigned int *classes)" style functions in "libata-core.c" worry me somewhat. Esp. that sometimes you have one class, sometimes two.
This looks like a bug waiting to happen for me.

Could we somehow get a

struct ata_classes {
	unsigned int master;
	unsigned int slave;
}

here (or similiar), before this is in used everywhere?

Usage would be function(struct ata_classes *classes) then.

Thanks & Regards

Ingo Oeser

#2 lore raw
Quoted 13 lines · Ingo Oeser

Hi Jeff,

Quoted 2 lines · Jeff Garzik

Testing and merge point in Tejun's flood of patches :) The patch below is against current linux-2.6.git.

These "function(unsigned int *classes)" style functions in "libata-core.c" worry me somewhat. Esp. that sometimes you have one class, sometimes two.
This looks like a bug waiting to happen for me.

Could we somehow get a

Quoted 9 lines
struct ata_classes {
	unsigned int master;
	unsigned int slave;
}

here (or similiar), before this is in used everywhere?

Usage would be function(struct ata_classes *classes) then.

Hello,

I object. Using array is intentional. Slave aware controllers (PATA / ata_piix) will use [0..1], most SATA controllers will use only [0], and PM aware ones will use [0..15]. The intention was requiring low level drivers of only what they know and normalize them in the core layer.

eg. Current std SATA reset routines consider the argument as *class (a single class value) and it's intentional. As long as a lldd is aware of only one device per port, it's allowed/recommeded to consider the passed classes argument as a pointer to single class value. The rest is upto the core libata layer.

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

I object. Using array is intentional. Slave aware controllers (PATA / ata_piix) will use [0..1], most SATA controllers will use only [0], and PM aware ones will use [0..15]. The intention was requiring low level drivers of only what they know and normalize them in the core layer.

eg. Current std SATA reset routines consider the argument as *class (a single class value) and it's intentional. As long as a lldd is aware of only one device per port, it's allowed/recommeded to consider the passed classes argument as a pointer to single class value. The rest is upto the core libata layer.

But what you pass along is basically an unbounded array, which is a bug waiting to happen.

So please let the core layer pass a bounded array here or provide a function from core layer to set that and check the index.

Thanks & Regards

Ingo Oeser

#4 lore raw
Quoted 7 lines · Ingo Oeser
Quoted 3 lines · Tejun Heo

I object. Using array is intentional. Slave aware controllers (PATA / ata_piix) will use [0..1], most SATA controllers will use only [0], and PM aware ones will use [0..15]. The intention was requiring low level drivers of only what they know and normalize them in the core layer.

eg. Current std SATA reset routines consider the argument as *class (a single class value) and it's intentional. As long as a lldd is aware of only one device per port, it's allowed/recommeded to consider the passed classes argument as a pointer to single class value. The rest is upto the core libata layer.

But what you pass along is basically an unbounded array, which is a bug waiting to happen.

Hello, again.

I'm a little bit lost here.

So, are you saying....

struct ata_classes {
	unsigned int classes[2];

|;

is safer than

unsigned int *class;

?

Quoted 4 lines

So please let the core layer pass a bounded array here or provide a function from core layer to set that and check the index.

Can you show me what you have in mind as code?

Signature · 1 line
tejun
#5 lore raw

Hi,

Quoted 11 lines · Tejun Heo

So, are you saying....

struct ata_classes {
	unsigned int classes[2];

|;

is safer than

unsigned int *class;

?

No, but with a little bit of additional code it CAN be safer.

Or maybe, we can store the classification in a different way.

What about putting the information directly into "ap->device[INDEX].class" in the sole caller (ata_drive_probe_reset) so far?

Quoted 5 lines
Quoted 3 lines

So please let the core layer pass a bounded array here or provide a function from core layer to set that and check the index.

Can you show me what you have in mind as code?

/* Define this to 15, if you need to */
#define ATA_MAX_CLASSES 2

struct ata_set {
        unsigned int class[ATA_MAX_CLASSES];
};

void set_ata_class(struct ata_set *cls, unsigned int idx, unsigned int what)

{
        BUG_ON(idx >= ARRAY_SIZE(cls->class);
        cls->class[idx] = what;
}

set_ata_class(&myclass, 0, what);

You can enforce that even better by making "what" a typedef like we do it with pte/pmd/pud/pgd in the VM.

But I prefer not passing this class stuff around, which would even safe arguments and thus reduce code size.

Maybe we should even have a classify ata port operation instead?

Regards

Ingo Oeser

#6 lore raw
Quoted 14 lines · Ingo Oeser

Hi,

Quoted 10 lines · Tejun Heo

So, are you saying....

struct ata_classes {
	unsigned int classes[2];

|;

is safer than

unsigned int *class;

Quoted 9 lines
Quoted 1 line

?

No, but with a little bit of additional code it CAN be safer.

Or maybe, we can store the classification in a different way.

What about putting the information directly into "ap->device[INDEX].class" in the sole caller (ata_drive_probe_reset) so far?

Not altering ->class directly in lldd driver is one major point of this whole patchset such that higher level driving logic has a say on whether a device is online or not, not the low level driver. Primarily this is useful for sharing low-level codes with hot plugging / EH but it's also possible to retry some of the operations during probing in limited cases.

Quoted 15 lines
Quoted 6 lines
Quoted 4 lines

So please let the core layer pass a bounded array here or provide a function from core layer to set that and check the index.

Can you show me what you have in mind as code?

/* Define this to 15, if you need to */
#define ATA_MAX_CLASSES 2

struct ata_set {
        unsigned int class[ATA_MAX_CLASSES];
};

void set_ata_class(struct ata_set *cls, unsigned int idx, unsigned int what)

Quoted 8 lines
{
        BUG_ON(idx >= ARRAY_SIZE(cls->class);
        cls->class[idx] = what;
}

set_ata_class(&myclass, 0, what);

You can enforce that even better by making "what" a typedef like we do it with pte/pmd/pud/pgd in the VM.

First of all, I'm not a big fan of safety through typedef/structure kind of stuff. For VM, I think it's justifiable, but this class thing doesn't involve any complex operation around it. Drivers just do what they do and record the result into the @classes array. I mean, how/why a driver would touch classes[1] when it can recognize only one device. It's dictated by the hardware spec and reflected in the driver code. If a driver doesn't get this right, things wouldn't work at all. @classes safety is a minor issue at that point.

Quoted 2 lines

But I prefer not passing this class stuff around, which would even safe arguments and thus reduce code size.

No boudnary check is done for accessing ap->device[i] and this is really not a place to worry about code size, IMHO.

Quoted 1 line

Maybe we should even have a classify ata port operation instead?

In ATA, probe and reset are closely related. There's only one way to get class code without resetting - EDD, and it doesn't always work well.
That's why the callback is named ->probe_reset. ATA devices are
designed to be classfied by resetting them.

Signature · 1 line
tejun
#7 lore raw

Hi Tejun,

Quoted 10 lines · Tejun
Quoted 3 lines · Ingo Oeser

What about putting the information directly into "ap->device[INDEX].class" in the sole caller (ata_drive_probe_reset) so far?

Not altering ->class directly in lldd driver is one major point of this whole patchset such that higher level driving logic has a say on whether a device is online or not, not the low level driver. Primarily this is useful for sharing low-level codes with hot plugging / EH but it's also possible to retry some of the operations during probing in limited cases.

Ok, with this argument, I finally get it. Now I know why you do it this way. You let the lld driver suggest a class for it's devices and verify these suggestions by high level code.

The only way to get to this classification data is by resetting the ATA device.

It might be technically possible to set ->class directly and fix it up in high level logic, as needed.

Your explicit design decision was NOT to do this but to put this suggestions from low level driver into a temporary on stack structure from the higher level API.

And since the maintainer is happy already, I couldn't care less.

Thanks for your patience :-)

Regards

Ingo Oeser

#8 lore raw

Hello, Ingo.

Quoted 12 lines · Ingo Oeser

Hi Tejun,

Quoted 6 lines · Tejun
Quoted 2 lines · Ingo Oeser

What about putting the information directly into "ap->device[INDEX].class" in the sole caller (ata_drive_probe_reset) so far?

Not altering ->class directly in lldd driver is one major point of this whole patchset such that higher level driving logic has a say on whether a device is online or not, not the low level driver. Primarily this is useful for sharing low-level codes with hot plugging / EH but it's also possible to retry some of the operations during probing in limited cases.

Quoted 8 lines

Ok, with this argument, I finally get it. Now I know why you do it this way. You let the lld driver suggest a class for it's devices and verify these suggestions by high level code.

The only way to get to this classification data is by resetting the ATA device.

It might be technically possible to set ->class directly and fix it up in high level logic, as needed.

Yeap, that's right. I actually considered that too but it was kind of messy that way - storing the current value, invoke callbacks, restoring values if something doesn't look right. Just using temporary variable is much more straight-forward, it seemed.

Quoted 8 lines

Your explicit design decision was NOT to do this but to put this suggestions from low level driver into a temporary on stack structure from the higher level API.

And since the maintainer is happy already, I couldn't care less.

Thanks for your patience :-)

Great that we could reach an agreement.

Thanks. :-)

Signature · 1 line
tejun
#9 lore raw
In reply to Tejun Heo
Quoted 21 lines · Tejun Heo
Quoted 19 lines · Ingo Oeser

Hi Jeff,

Quoted 2 lines · Jeff Garzik

Testing and merge point in Tejun's flood of patches :) The patch below is against current linux-2.6.git.

These "function(unsigned int *classes)" style functions in "libata-core.c" worry me somewhat. Esp. that sometimes you have one class, sometimes two.
This looks like a bug waiting to happen for me.

Could we somehow get a

struct ata_classes {
    unsigned int master;
    unsigned int slave;
}
Quoted 8 lines
Quoted 4 lines

here (or similiar), before this is in used everywhere?

Usage would be function(struct ata_classes *classes) then.

Hello,

I object. Using array is intentional. Slave aware controllers (PATA / ata_piix) will use [0..1], most SATA controllers will use only [0], and PM aware ones will use [0..15]. The intention was requiring low level drivers of only what they know and normalize them in the core layer.

Yep, that's fine.

We don't need to be writing code for the case where somebody doesn't know the C language.

Jeff