Skip to contentSkip to conversation

PATA port on SATA controllers

PATCH/RFC Erik Benada 3 participants 3 messages Oct 3, 2004 – Nov 15, 2004

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

Hi Jeff,

this is the first attempt to properly support SATA and PATA ports on the same controller. Patch is against 2.6.9-rc3.

Changes:
- ata_probe_ent: multiple ata_port_operations, per port flags
- libata-core.c: changes for new ata_probe_ent + minor cleanups (mostly in comments)
- sata_promise.c: PATA port support using new infrastructure

Tested on my PDC20378.

Any suggestions, comments?

Questions:
-----------
1. In your e-mail outlining steps required to properly support PATA port on SATA controller you mentioned ata_host_set structure. Why do we need multiple ata_port_operations in there? I couldn't find any code that uses anything but irq_handler, irq_clear and host_stop.

2. Would it make sense to create ata_host_ops structure to move host related operations (like irq_handler, irq_clear, host_stop) from ata_port_operations and replace ata_host_set->ops with it?

3. ata_port_info structure - is it intended to describe just 1 port or should it now support multiple ports (by adding n_ports and multiple ata_port_operations)?

Thanks,

Erik

 drivers/scsi/libata-core.c  |   33 ++++++-----
 drivers/scsi/sata_promise.c |  124 +++++++++++++++++++++++++++++++++++---------
 include/linux/libata.h      |    3 -
 3 files changed, 121 insertions(+), 39 deletions(-)

diff -uprN -X dontdiff linux-2.6.9-rc3/drivers/scsi/libata-core.c linux-pata/drivers/scsi/libata-core.c

drivers/scsi/libata-core.c +19 -14
@@ -191,11 +191,11 @@ void ata_tf_load(struct ata_port *ap, st
 }
 
 /**
- *	ata_exec_command - issue ATA command to host controller
+ *	ata_exec_command_pio - issue ATA command to host controller
  *	@ap: port to which command is being issued
  *	@tf: ATA taskfile register set
  *
- *	Issues PIO/MMIO write to ATA command register, with proper
+ *	Issues PIO write to ATA command register, with proper
  *	synchronization with interrupt handler / other threads.
  *
  *	LOCKING:
@@ -271,7 +271,7 @@ static inline void ata_exec(struct ata_p
  *	other threads.
  *
  *	LOCKING:
- *	Obtains host_set lock.
+ *	FIXME: Obtains host_set lock.
  */
 
 static void ata_tf_to_host(struct ata_port *ap, struct ata_taskfile *tf)
@@ -306,7 +306,7 @@ void ata_tf_to_host_nolock(struct ata_po
  *	@tf: ATA taskfile register set for storing input
  *
  *	Reads ATA taskfile registers for currently-selected device
- *	into @tf.
+ *	into @tf via PIO.
  *
  *	LOCKING:
  *	Inherited from caller.
@@ -377,7 +377,7 @@ void ata_tf_read(struct ata_port *ap, st
  *	@ap: port where the device is
  *
  *	Reads ATA taskfile status register for currently-selected device
- *	and return it's value. This also clears pending interrupts
+ *	via PIO and return it's value. This also clears pending interrupts
  *      from this device
  *
  *	LOCKING:
@@ -486,7 +486,7 @@ void ata_tf_from_fis(u8 *fis, struct ata
 /**
  *	ata_prot_to_cmd - determine which read/write opcodes to use
  *	@protocol: ATA_PROT_xxx taskfile protocol
- *	@lba48: true is lba48 is present
+ *	@lba48: true if lba48 is present
  *
  *	Given necessary input, determine which read/write commands
  *	to use to transfer data.
@@ -1265,7 +1265,7 @@ void __sata_phy_reset(struct ata_port *a
 }
 
 /**
- *	__sata_phy_reset -
+ *	sata_phy_reset -
  *	@ap:
  *
  *	LOCKING:
@@ -1426,7 +1426,7 @@ static void ata_set_mode(struct ata_port
 	if (ap->ops->post_set_mode)
 		ap->ops->post_set_mode(ap);
 
-	for (i = 0; i < 2; i++) {
+	for (i = 0; i < ATA_MAX_DEVICES; i++) {
 		struct ata_device *dev = &ap->device[i];
 		ata_dev_set_protocol(dev);
 	}
@@ -2235,7 +2235,7 @@ err_out:
 }
 
 /**
- *	ata_pio_sector -
+ *	ata_pio_block -
  *	@ap:
  *
  *	LOCKING:
@@ -3036,7 +3036,8 @@ static void ata_host_init(struct ata_por
 	ap->mwdma_mask = ent->mwdma_mask;
 	ap->udma_mask = ent->udma_mask;
 	ap->flags |= ent->host_flags;
-	ap->ops = ent->port_ops;
+	ap->flags |= ent->port_flags[port_no];
+	ap->ops = ent->port_ops[port_no];
 	ap->cbl = ATA_CBL_NONE;
 	ap->active_tag = ATA_TAG_POISON;
 	ap->last_ctl = 0xFF;
@@ -3125,7 +3126,8 @@ int ata_device_add(struct ata_probe_ent 
 	host_set->irq = ent->irq;
 	host_set->mmio_base = ent->mmio_base;
 	host_set->private_data = ent->private_data;
-	host_set->ops = ent->port_ops;
+	/* FIXME: should we have separate ata_host_ops structure ? */
+	host_set->ops = ent->port_ops[0];
 
 	/* register each port bound to this device */
 	for (i = 0; i < ent->n_ports; i++) {
@@ -3153,7 +3155,7 @@ int ata_device_add(struct ata_probe_ent 
 	       		ent->irq);
 
 		ata_chk_status(ap);
-		host_set->ops->irq_clear(ap);
+		ap->ops->irq_clear(ap);
 		count++;
 	}
 
@@ -3163,7 +3165,7 @@ int ata_device_add(struct ata_probe_ent 
 	}
 
 	/* obtain irq, that is shared between channels */
-	if (request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags,
+	if (request_irq(ent->irq, ent->port_ops[0]->irq_handler, ent->irq_flags,
 			DRV_NAME, host_set))
 		goto err_out;
 
@@ -3292,7 +3294,6 @@ ata_probe_ent_alloc(int n, struct pci_de
 		probe_ent[i].pio_mask = port[i]->pio_mask;
 		probe_ent[i].mwdma_mask = port[i]->mwdma_mask;
 		probe_ent[i].udma_mask = port[i]->udma_mask;
-		probe_ent[i].port_ops = port[i]->port_ops;
 
 	}
 
@@ -3315,12 +3316,14 @@ ata_pci_init_native_mode(struct pci_dev 
 	probe_ent->port[0].ctl_addr =
 		pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS;
 	probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4);
+	probe_ent->port_ops[0] = port[0]->port_ops;
 
 	probe_ent->port[1].cmd_addr = pci_resource_start(pdev, 2);
 	probe_ent->port[1].altstatus_addr =
 	probe_ent->port[1].ctl_addr =
 		pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS;
 	probe_ent->port[1].bmdma_addr = pci_resource_start(pdev, 4) + 8;
+	probe_ent->port_ops[1] = port[0]->port_ops;
 
 	ata_std_ports(&probe_ent->port[0]);
 	ata_std_ports(&probe_ent->port[1]);
@@ -3345,11 +3348,13 @@ ata_pci_init_legacy_mode(struct pci_dev 
 	probe_ent[0].port[0].altstatus_addr =
 	probe_ent[0].port[0].ctl_addr = 0x3f6;
 	probe_ent[0].port[0].bmdma_addr = pci_resource_start(pdev, 4);
+	probe_ent[0].port_ops[0] = port[0]->port_ops;
 
 	probe_ent[1].port[0].cmd_addr = 0x170;
 	probe_ent[1].port[0].altstatus_addr =
 	probe_ent[1].port[0].ctl_addr = 0x376;
 	probe_ent[1].port[0].bmdma_addr = pci_resource_start(pdev, 4)+8;
+	probe_ent[1].port_ops[0] = port[1]->port_ops;
 
 	ata_std_ports(&probe_ent[0].port[0]);
 	ata_std_ports(&probe_ent[1].port[0]);

diff -uprN -X dontdiff linux-2.6.9-rc3/drivers/scsi/sata_promise.c linux-pata/drivers/scsi/sata_promise.c

drivers/scsi/sata_promise.c +100 -24

194 lines not on this page · raw message

include/linux/libata.h +2 -1
diff -uprN -X dontdiff linux-2.6.9-rc3/include/linux/libata.h linux-pata/include/linux/libata.h
@@ -185,7 +185,7 @@ struct ata_ioports {
 struct ata_probe_ent {
 	struct list_head	node;
 	struct pci_dev		*pdev;
-	struct ata_port_operations	*port_ops;
+	struct ata_port_operations	*port_ops[ATA_MAX_PORTS];
 	Scsi_Host_Template	*sht;
 	struct ata_ioports	port[ATA_MAX_PORTS];
 	unsigned int		n_ports;
@@ -196,6 +196,7 @@ struct ata_probe_ent {
 	unsigned long		irq;
 	unsigned int		irq_flags;
 	unsigned long		host_flags;
+	unsigned long		port_flags[ATA_MAX_PORTS];
 	void __iomem		*mmio_base;
 	void			*private_data;
 };

______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca

#1 lore raw
Quoted 5 lines · Erik Benada

Hi Jeff,

this is the first attempt to properly support SATA and PATA ports on the same controller. Patch is against 2.6.9-rc3.

Quoted 7 lines

Changes:
- ata_probe_ent: multiple ata_port_operations, per port flags
- libata-core.c: changes for new ata_probe_ent + minor cleanups (mostly in comments)
- sata_promise.c: PATA port support using new infrastructure

Tested on my PDC20378.

Works on my PDC20376.

Jesse

Signature · 1 line
Jesse Stockall <[email protected]>
#2 lore raw
In reply to Erik Benada
Quoted 5 lines · Erik Benada

Hi Jeff,

this is the first attempt to properly support SATA and PATA ports on the same controller. Patch is against 2.6.9-rc3.

Quoted 8 lines

Changes:
- ata_probe_ent: multiple ata_port_operations, per port flags
- libata-core.c: changes for new ata_probe_ent + minor cleanups (mostly in comments)
- sata_promise.c: PATA port support using new infrastructure

Tested on my PDC20378.

Any suggestions, comments?

Sorry it took so long to comment, I was pondering the best way things should look.

Quoted 8 lines

Questions:
-----------
1. In your e-mail outlining steps required to properly support PATA port on SATA controller you mentioned ata_host_set structure. Why do we need multiple ata_port_operations in there? I couldn't find any code that uses anything but irq_handler, irq_clear and host_stop.

2. Would it make sense to create ata_host_ops structure to move host related operations (like irq_handler, irq_clear, host_stop) from ata_port_operations and replace ata_host_set->ops with it?

Yes, and this sorta answers questions #1 as well. irq_handler/etc. are host-granularity not port-granularity, and so would be more appropriate to have a separate host_ops rather than referencing port_ops[0]->foo().

Quoted 2 lines

3. ata_port_info structure - is it intended to describe just 1 port or should it now support multiple ports (by adding n_ports and multiple ata_port_operations)?

ata_port_info was intended to describe a single controller, so it's a bit misnamed per the current scheme.

Quoted 48 lines
drivers/scsi/sata_promise.c +27 -17
@@ -104,35 +109,55 @@ static Scsi_Host_Template pdc_sata_sht =
 	.bios_param		= ata_std_bios_param,
 };
 
-static struct ata_port_operations pdc_sata_ops = {
-	.port_disable		= ata_port_disable,
-	.tf_load		= pdc_tf_load_mmio,
-	.tf_read		= ata_tf_read,
-	.check_status		= ata_check_status,
-	.exec_command		= pdc_exec_command_mmio,
-	.dev_select		= ata_std_dev_select,
-	.phy_reset		= pdc_phy_reset,
-	.qc_prep		= pdc_qc_prep,
-	.qc_issue		= pdc_qc_issue_prot,
-	.eng_timeout		= pdc_eng_timeout,
-	.irq_handler		= pdc_interrupt,
-	.irq_clear		= pdc_irq_clear,
-	.scr_read		= pdc_sata_scr_read,
-	.scr_write		= pdc_sata_scr_write,
-	.port_start		= pdc_port_start,
-	.port_stop		= pdc_port_stop,
+static struct ata_port_operations pdc_port_ops[] = {
+	{	/* SATA port operations */
+		.port_disable		= ata_port_disable,
+		.tf_load		= pdc_tf_load_mmio,
+		.tf_read		= ata_tf_read,
+		.check_status		= ata_check_status,
+		.exec_command		= pdc_exec_command_mmio,
+		.dev_select		= ata_std_dev_select,
+		.phy_reset		= pdc_sata_phy_reset,
+		.qc_prep		= pdc_qc_prep,
+		.qc_issue		= pdc_qc_issue_prot,
+		.eng_timeout		= pdc_eng_timeout,
+		.irq_handler		= pdc_interrupt,
+		.irq_clear		= pdc_irq_clear,
+		.scr_read		= pdc_sata_scr_read,
+		.scr_write		= pdc_sata_scr_write,
+		.port_start		= pdc_port_start,
+		.port_stop		= pdc_port_stop,
+	},
+	{	/* PATA port operations */
+		.port_disable		= ata_port_disable,
+		.tf_load		= pdc_tf_load_mmio,
+		.tf_read		= ata_tf_read,
+		.check_status		= ata_check_status,
+		.exec_command		= pdc_exec_command_mmio,
+		.dev_select		= ata_std_dev_select,
+		.phy_reset		= pdc_pata_phy_reset,

drivers/scsi/sata_promise.c static Scsi_Host_Template pdc_sata_sht = · line 148

Quoted 10 lines
drivers/scsi/sata_promise.c +10 -0
+		.qc_prep		= pdc_qc_prep,
+		.qc_issue		= pdc_qc_issue_prot,
+		.eng_timeout		= pdc_eng_timeout,
+		.irq_handler		= pdc_interrupt,
+		.irq_clear		= pdc_irq_clear,
+		.scr_read		= pdc_sata_scr_read,
+		.scr_write		= pdc_sata_scr_write,
+		.port_start		= pdc_port_start,
+		.port_stop		= pdc_port_stop,
+	},

I would prefer two named variables, to a single array.

Jeff