Skip to contentSkip to conversation

Q40 IDE fixes

PATCH Superseded Michael Schmitz 5 participants 19 messages Aug 17, 2023 – Aug 22, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Q40 IDE fixes

The pata_falcon IDE driver for m68k Q40 has been broken since Q40 was converted to use pata_falcon in preparation for removal of the legacy IDE core in v5.14. A bug has only recently been reported.

This patch series to fix the bug has seen some discussion and review on linux-m68k in the past week. It's also been tested on both Q40 and Atari.

The bug reporter has since found that he can use pata_legacy for his Q40, but that is solely due to his disk written in the default IDE byte order. Other users of Q40 will have data on disk in big-endian order, and will have to use the pata_falcon driver which does not attempt byte swapping to host byte order in its data_xfer() function.

Patch 1 fixes the bug introduced in v5.14. That one ought not to be controversial (I hope).

Patch 2 adds a module parameter to select drives to have byte swapping to host byte order applied (useful for connecting drives in IDE default byte order to Q40 and Atari for interoperability).

Patch 3 changes the Atari Falcon IDE platform device to use a device ID compatible with the byte swapping scheme. This patch should go through the m68k tree, not IDE.

Feedback welcome!

Cheers,

Michael

#1 lore raw

PATCH 1/3 m68k/q40: fix IO base selection for Q40 in pata_falcon.c

With commit 44b1fbc0f5f3 ("m68k/q40: Replace q40ide driver with pata_falcon and falconide"), the Q40 IDE driver was replaced by pata_falcon.c.

Both IO and memory resources were defined for the Q40 IDE platform device, but definition of the IDE register addresses was modeled after the Falcon case, both in use of the memory resources and in including register scale and byte vs. word offset in the address.

This was correct for the Falcon case, which does not apply any address translation to the register addresses. In the Q40 case, all of device base address, byte access offset and register scaling is included in the platform specific ISA access translation (in asm/mm_io.h).

As a consequence, such address translation gets applied twice, and register addresses are mangled.

Use the device base address from the platform IO resource, and use standard register offsets from that base in order to calculate register addresses (the IO address translation will then apply the correct ISA window base and scaling).

Encode PIO_OFFSET into IO port addresses for all registers except the data transfer register. Encode the MMIO offset there (pata_falcon_data_xfer() directly uses raw IO with no address translation).

---

Changes from RFC v3:

- split off byte swap option into separate patch

Geert Uytterhoeven:
- review comments

Changes from RFC v2:
- add driver parameter 'data_swap' as bit mask for drives to swap

Changes from RFC v1:

Finn Thain:
- take care to supply IO address suitable for ioread8/iowrite8
- use MMIO address for data transfer

---
 drivers/ata/pata_falcon.c | 55 ++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 21 deletions(-)
drivers/ata/pata_falcon.c +34 -21
index 996516e64f13..346259e3bbc8 100644
@@ -123,8 +123,8 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
-	void __iomem *base;
-	int irq = 0;
+	void __iomem *base, *ctl_base;
+	int irq = 0, io_offset = 1, reg_scale = 4;
 
 	dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
 
@@ -165,26 +165,39 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
-	base = (void __iomem *)base_mem_res->start;
 	/* N.B. this assumes data_addr will be used for word-sized I/O only */
-	ap->ioaddr.data_addr		= base + 0 + 0 * 4;
-	ap->ioaddr.error_addr		= base + 1 + 1 * 4;
-	ap->ioaddr.feature_addr		= base + 1 + 1 * 4;
-	ap->ioaddr.nsect_addr		= base + 1 + 2 * 4;
-	ap->ioaddr.lbal_addr		= base + 1 + 3 * 4;
-	ap->ioaddr.lbam_addr		= base + 1 + 4 * 4;
-	ap->ioaddr.lbah_addr		= base + 1 + 5 * 4;
-	ap->ioaddr.device_addr		= base + 1 + 6 * 4;
-	ap->ioaddr.status_addr		= base + 1 + 7 * 4;
-	ap->ioaddr.command_addr		= base + 1 + 7 * 4;
-
-	base = (void __iomem *)ctl_mem_res->start;
-	ap->ioaddr.altstatus_addr	= base + 1;
-	ap->ioaddr.ctl_addr		= base + 1;
-
-	ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx",
-		      (unsigned long)base_mem_res->start,
-		      (unsigned long)ctl_mem_res->start);
+	ap->ioaddr.data_addr = (void __iomem *)base_mem_res->start;
+
+	if (base_res) {		/* only Q40 has IO resources */
+		io_offset = 0x10000;
+		reg_scale = 1;
+		base = (void __iomem *)base_res->start;
+		ctl_base = (void __iomem *)ctl_res->start;
+
+		ata_port_desc(ap, "cmd %pa ctl %pa",
+			      &base_res->start,
+			      &ctl_res->start);
+	} else {
+		base = (void __iomem *)base_mem_res->start;
+		ctl_base = (void __iomem *)ctl_mem_res->start;
+
+		ata_port_desc(ap, "cmd %pa ctl %pa",
+			      &base_mem_res->start,
+			      &ctl_mem_res->start);
+	}
+
+	ap->ioaddr.error_addr	= base + io_offset + 1 * reg_scale;
+	ap->ioaddr.feature_addr	= base + io_offset + 1 * reg_scale;
+	ap->ioaddr.nsect_addr	= base + io_offset + 2 * reg_scale;
+	ap->ioaddr.lbal_addr	= base + io_offset + 3 * reg_scale;
+	ap->ioaddr.lbam_addr	= base + io_offset + 4 * reg_scale;
+	ap->ioaddr.lbah_addr	= base + io_offset + 5 * reg_scale;
+	ap->ioaddr.device_addr	= base + io_offset + 6 * reg_scale;
+	ap->ioaddr.status_addr	= base + io_offset + 7 * reg_scale;
+	ap->ioaddr.command_addr	= base + io_offset + 7 * reg_scale;
+
+	ap->ioaddr.altstatus_addr	= ctl_base + io_offset;
+	ap->ioaddr.ctl_addr		= ctl_base + io_offset;
 
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
Signature · 1 line
2.17.1
#8 lore raw

PATCH 2/3 m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

In reply to Michael Schmitz

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes since RFC v4:

Geert Uytterhoeven:
- don't shift static module parameter for drive 3/4 bitmask
- simplify bit mask calculation to always use pdev->id

Finn Thain:
- correct bit numbers for drive 3/4

Changes since RFC v3:

- split off this byte swap handling into separate patch

- add hint regarding third and fourth drive on Q40

Finn Thain:
- rename module parameter to 'data_swab' to better reflect its use

William Sowerbutts:
- correct IDE drive number used in data swap conditional

---
 drivers/ata/pata_falcon.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/ata/pata_falcon.c +25 -1
index 346259e3bbc8..90488f565d6f 100644
@@ -33,6 +33,16 @@
 #define DRV_NAME "pata_falcon"
 #define DRV_VERSION "0.1.0"
 
+static int pata_falcon_swap_mask;
+
+module_param_named(data_swab, pata_falcon_swap_mask, int, 0444);
+MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default==0)");
+
+struct pata_falcon_priv {
+	unsigned int swap_mask;
+	bool swap_data;
+};
+
 static const struct scsi_host_template pata_falcon_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
@@ -44,13 +54,15 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
 	struct ata_device *dev = qc->dev;
 	struct ata_port *ap = dev->link->ap;
 	void __iomem *data_addr = ap->ioaddr.data_addr;
+	struct pata_falcon_priv *priv = ap->private_data;
 	unsigned int words = buflen >> 1;
 	struct scsi_cmnd *cmd = qc->scsicmd;
+	int dev_id = dev->devno;
 	bool swap = 1;
 
 	if (dev->class == ATA_DEV_ATA && cmd &&
 	    !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
-		swap = 0;
+		swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));
 
 	/* Transfer multiple of 2 bytes */
 	if (rw == READ) {
@@ -123,6 +135,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
+	struct pata_falcon_priv *priv;
 	void __iomem *base, *ctl_base;
 	int irq = 0, io_offset = 1, reg_scale = 4;
 
@@ -165,6 +178,13 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
+	priv = devm_kzalloc(&pdev->dev,
+		sizeof(struct pata_falcon_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	ap->private_data = priv;
+
 	/* N.B. this assumes data_addr will be used for word-sized I/O only */
 	ap->ioaddr.data_addr = (void __iomem *)base_mem_res->start;
 
@@ -199,6 +219,10 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->ioaddr.altstatus_addr	= ctl_base + io_offset;
 	ap->ioaddr.ctl_addr		= ctl_base + io_offset;
 
+	priv->swap_mask = pata_falcon_swap_mask >> (2 * pdev->id);
+	if (priv->swap_mask)
+		priv->swap_data = 1;
+
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
 		irq = irq_res->start;
Signature · 1 line
2.17.1
#18 lore raw

PATCH 3/3 m68k/atari: change Falcon IDE platform device to id 0

In reply to Michael Schmitz

The pata_falcon data byte swapping patch relies on pdev->id being 0 or 1. Q40 uses these IDs, but Atari used -1. Change pdev->id to 0 for Atari Falcon IDE platform device so selection of drive to byte-swap through pata_falcon.data_swab can be used on Falcon as well.
Tested on ARAnyM so far.

---
 arch/m68k/atari/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/m68k/atari/config.c +1 -1
index 38a7c0578105..e3e437cd0f84 100644
@@ -925,7 +925,7 @@ int __init atari_platform_init(void)
 #endif
 
 	if (ATARIHW_PRESENT(IDE)) {
-		pdev = platform_device_register_simple("atari-falcon-ide", -1,
+		pdev = platform_device_register_simple("atari-falcon-ide", 0,
 			atari_falconide_rsrc, ARRAY_SIZE(atari_falconide_rsrc));
 		if (IS_ERR(pdev))
 			rv = PTR_ERR(pdev);
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 1/3] m68k/q40: fix IO base selection for Q40 in pata_falcon.c

In reply to Michael Schmitz
Quoted 3 lines · Michael Schmitz

With commit 44b1fbc0f5f3 ("m68k/q40: Replace q40ide driver with pata_falcon and falconide"), the Q40 IDE driver was replaced by pata_falcon.c.

Please change the patch title to:

ata: pata_falcon: fix IO base selection for Q40

Quoted 26 lines

Both IO and memory resources were defined for the Q40 IDE platform device, but definition of the IDE register addresses was modeled after the Falcon case, both in use of the memory resources and in including register scale and byte vs. word offset in the address.

This was correct for the Falcon case, which does not apply any address translation to the register addresses. In the Q40 case, all of device base address, byte access offset and register scaling is included in the platform specific ISA access translation (in asm/mm_io.h).

As a consequence, such address translation gets applied twice, and register addresses are mangled.

Use the device base address from the platform IO resource, and use standard register offsets from that base in order to calculate register addresses (the IO address translation will then apply the correct ISA window base and scaling).

Encode PIO_OFFSET into IO port addresses for all registers except the data transfer register. Encode the MMIO offset there (pata_falcon_data_xfer() directly uses raw IO with no address translation).

Quoted 5 lines

5.14+ ? But I do not think you need to specify anything anyway since you have the Fixes tag.

Quoted 99 lines
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes from RFC v3:

- split off byte swap option into separate patch

Geert Uytterhoeven:
- review comments

Changes from RFC v2:
- add driver parameter 'data_swap' as bit mask for drives to swap

Changes from RFC v1:

Finn Thain:
- take care to supply IO address suitable for ioread8/iowrite8
- use MMIO address for data transfer

---
 drivers/ata/pata_falcon.c | 55 ++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 21 deletions(-)
drivers/ata/pata_falcon.c +34 -21
index 996516e64f13..346259e3bbc8 100644
@@ -123,8 +123,8 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
-	void __iomem *base;
-	int irq = 0;
+	void __iomem *base, *ctl_base;
+	int irq = 0, io_offset = 1, reg_scale = 4;
 
 	dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
 
@@ -165,26 +165,39 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
-	base = (void __iomem *)base_mem_res->start;
 	/* N.B. this assumes data_addr will be used for word-sized I/O only */
-	ap->ioaddr.data_addr		= base + 0 + 0 * 4;
-	ap->ioaddr.error_addr		= base + 1 + 1 * 4;
-	ap->ioaddr.feature_addr		= base + 1 + 1 * 4;
-	ap->ioaddr.nsect_addr		= base + 1 + 2 * 4;
-	ap->ioaddr.lbal_addr		= base + 1 + 3 * 4;
-	ap->ioaddr.lbam_addr		= base + 1 + 4 * 4;
-	ap->ioaddr.lbah_addr		= base + 1 + 5 * 4;
-	ap->ioaddr.device_addr		= base + 1 + 6 * 4;
-	ap->ioaddr.status_addr		= base + 1 + 7 * 4;
-	ap->ioaddr.command_addr		= base + 1 + 7 * 4;
-
-	base = (void __iomem *)ctl_mem_res->start;
-	ap->ioaddr.altstatus_addr	= base + 1;
-	ap->ioaddr.ctl_addr		= base + 1;
-
-	ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx",
-		      (unsigned long)base_mem_res->start,
-		      (unsigned long)ctl_mem_res->start);
+	ap->ioaddr.data_addr = (void __iomem *)base_mem_res->start;
+
+	if (base_res) {		/* only Q40 has IO resources */
+		io_offset = 0x10000;
+		reg_scale = 1;
+		base = (void __iomem *)base_res->start;
+		ctl_base = (void __iomem *)ctl_res->start;
+
+		ata_port_desc(ap, "cmd %pa ctl %pa",
+			      &base_res->start,
+			      &ctl_res->start);
+	} else {
+		base = (void __iomem *)base_mem_res->start;
+		ctl_base = (void __iomem *)ctl_mem_res->start;
+
+		ata_port_desc(ap, "cmd %pa ctl %pa",
+			      &base_mem_res->start,
+			      &ctl_mem_res->start);
+	}
+
+	ap->ioaddr.error_addr	= base + io_offset + 1 * reg_scale;
+	ap->ioaddr.feature_addr	= base + io_offset + 1 * reg_scale;
+	ap->ioaddr.nsect_addr	= base + io_offset + 2 * reg_scale;
+	ap->ioaddr.lbal_addr	= base + io_offset + 3 * reg_scale;
+	ap->ioaddr.lbam_addr	= base + io_offset + 4 * reg_scale;
+	ap->ioaddr.lbah_addr	= base + io_offset + 5 * reg_scale;
+	ap->ioaddr.device_addr	= base + io_offset + 6 * reg_scale;
+	ap->ioaddr.status_addr	= base + io_offset + 7 * reg_scale;
+	ap->ioaddr.command_addr	= base + io_offset + 7 * reg_scale;
+
+	ap->ioaddr.altstatus_addr	= ctl_base + io_offset;
+	ap->ioaddr.ctl_addr		= ctl_base + io_offset;
 
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#9 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

In reply to Michael Schmitz
Quoted 107 lines · Michael Schmitz

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes since RFC v4:

Geert Uytterhoeven:
- don't shift static module parameter for drive 3/4 bitmask
- simplify bit mask calculation to always use pdev->id

Finn Thain:
- correct bit numbers for drive 3/4

Changes since RFC v3:

- split off this byte swap handling into separate patch

- add hint regarding third and fourth drive on Q40

Finn Thain:
- rename module parameter to 'data_swab' to better reflect its use

William Sowerbutts:
- correct IDE drive number used in data swap conditional

---
 drivers/ata/pata_falcon.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/ata/pata_falcon.c +21 -1
index 346259e3bbc8..90488f565d6f 100644
@@ -33,6 +33,16 @@
 #define DRV_NAME "pata_falcon"
 #define DRV_VERSION "0.1.0"
 
+static int pata_falcon_swap_mask;
+
+module_param_named(data_swab, pata_falcon_swap_mask, int, 0444);
+MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default==0)");
+
+struct pata_falcon_priv {
+	unsigned int swap_mask;
+	bool swap_data;
+};
+
 static const struct scsi_host_template pata_falcon_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
@@ -44,13 +54,15 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
 	struct ata_device *dev = qc->dev;
 	struct ata_port *ap = dev->link->ap;
 	void __iomem *data_addr = ap->ioaddr.data_addr;
+	struct pata_falcon_priv *priv = ap->private_data;
 	unsigned int words = buflen >> 1;
 	struct scsi_cmnd *cmd = qc->scsicmd;
+	int dev_id = dev->devno;
 	bool swap = 1;
 
 	if (dev->class == ATA_DEV_ATA && cmd &&
 	    !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
-		swap = 0;
+		swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));
 
 	/* Transfer multiple of 2 bytes */
 	if (rw == READ) {
@@ -123,6 +135,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
+	struct pata_falcon_priv *priv;
 	void __iomem *base, *ctl_base;
 	int irq = 0, io_offset = 1, reg_scale = 4;
 
@@ -165,6 +178,13 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
+	priv = devm_kzalloc(&pdev->dev,
+		sizeof(struct pata_falcon_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	ap->private_data = priv;
+
 	/* N.B. this assumes data_addr will be used for word-sized I/O only */
 	ap->ioaddr.data_addr = (void __iomem *)base_mem_res->start;
 

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 222

Quoted 4 lines
drivers/ata/pata_falcon.c +1 -0
@@ -199,6 +219,10 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->ioaddr.altstatus_addr	= ctl_base + io_offset;
 	ap->ioaddr.ctl_addr		= ctl_base + io_offset;
 
+	priv->swap_mask = pata_falcon_swap_mask >> (2 * pdev->id);

I do not understand the shift here. It seems that it will lead to priv->swap_mask always being 0...

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 224

Quoted 2 lines
drivers/ata/pata_falcon.c +2 -0
+	if (priv->swap_mask)
+		priv->swap_data = 1;

I do not understand why priv->swap_data is needed, given that it is set to 1 if priv->swap_mask != 0, the above:

	swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));

should be equivalent to the simpler:

	swap = priv->swap_mask & BIT(dev_id);

No ? Am I missing something ?

Quoted 4 lines
drivers/ata/pata_falcon.c +1 -0
+
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
 		irq = irq_res->start;
Signature · 2 lines
Damien Le Moal
Western Digital Research
#3 lore raw

Re: [PATCH 1/3] m68k/q40: fix IO base selection for Q40 in pata_falcon.c

In reply to Damien Le Moal

Hi Damien,

thanks for your review!

Am 18.08.2023 um 12:42 schrieb Damien Le Moal:

Quoted 8 lines · Michael Schmitz
Quoted 3 lines

With commit 44b1fbc0f5f3 ("m68k/q40: Replace q40ide driver with pata_falcon and falconide"), the Q40 IDE driver was replaced by pata_falcon.c.

Please change the patch title to:

ata: pata_falcon: fix IO base selection for Q40

Will do.

Quoted 27 lines
Quoted 27 lines

Both IO and memory resources were defined for the Q40 IDE platform device, but definition of the IDE register addresses was modeled after the Falcon case, both in use of the memory resources and in including register scale and byte vs. word offset in the address.

This was correct for the Falcon case, which does not apply any address translation to the register addresses. In the Q40 case, all of device base address, byte access offset and register scaling is included in the platform specific ISA access translation (in asm/mm_io.h).

As a consequence, such address translation gets applied twice, and register addresses are mangled.

Use the device base address from the platform IO resource, and use standard register offsets from that base in order to calculate register addresses (the IO address translation will then apply the correct ISA window base and scaling).

Encode PIO_OFFSET into IO port addresses for all registers except the data transfer register. Encode the MMIO offset there (pata_falcon_data_xfer() directly uses raw IO with no address translation).

Quoted 8 lines
Quoted 5 lines

5.14+ ? But I do not think you need to specify anything anyway since you have the Fixes tag.

5.14+ perhaps. I'll check the docs again to see whether Fixes: obsoletes the stable backport tag. I've so far used both together...

Cheers,

Michael

Quoted 101 lines
Quoted 100 lines
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes from RFC v3:

- split off byte swap option into separate patch

Geert Uytterhoeven:
- review comments

Changes from RFC v2:
- add driver parameter 'data_swap' as bit mask for drives to swap

Changes from RFC v1:

Finn Thain:
- take care to supply IO address suitable for ioread8/iowrite8
- use MMIO address for data transfer

---
 drivers/ata/pata_falcon.c | 55 ++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 21 deletions(-)
drivers/ata/pata_falcon.c +34 -21
index 996516e64f13..346259e3bbc8 100644
@@ -123,8 +123,8 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
-	void __iomem *base;
-	int irq = 0;
+	void __iomem *base, *ctl_base;
+	int irq = 0, io_offset = 1, reg_scale = 4;
 
 	dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
 
@@ -165,26 +165,39 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
-	base = (void __iomem *)base_mem_res->start;
 	/* N.B. this assumes data_addr will be used for word-sized I/O only */
-	ap->ioaddr.data_addr		= base + 0 + 0 * 4;
-	ap->ioaddr.error_addr		= base + 1 + 1 * 4;
-	ap->ioaddr.feature_addr		= base + 1 + 1 * 4;
-	ap->ioaddr.nsect_addr		= base + 1 + 2 * 4;
-	ap->ioaddr.lbal_addr		= base + 1 + 3 * 4;
-	ap->ioaddr.lbam_addr		= base + 1 + 4 * 4;
-	ap->ioaddr.lbah_addr		= base + 1 + 5 * 4;
-	ap->ioaddr.device_addr		= base + 1 + 6 * 4;
-	ap->ioaddr.status_addr		= base + 1 + 7 * 4;
-	ap->ioaddr.command_addr		= base + 1 + 7 * 4;
-
-	base = (void __iomem *)ctl_mem_res->start;
-	ap->ioaddr.altstatus_addr	= base + 1;
-	ap->ioaddr.ctl_addr		= base + 1;
-
-	ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx",
-		      (unsigned long)base_mem_res->start,
-		      (unsigned long)ctl_mem_res->start);
+	ap->ioaddr.data_addr = (void __iomem *)base_mem_res->start;
+
+	if (base_res) {		/* only Q40 has IO resources */
+		io_offset = 0x10000;
+		reg_scale = 1;
+		base = (void __iomem *)base_res->start;
+		ctl_base = (void __iomem *)ctl_res->start;
+
+		ata_port_desc(ap, "cmd %pa ctl %pa",
+			      &base_res->start,
+			      &ctl_res->start);
+	} else {
+		base = (void __iomem *)base_mem_res->start;
+		ctl_base = (void __iomem *)ctl_mem_res->start;
+
+		ata_port_desc(ap, "cmd %pa ctl %pa",
+			      &base_mem_res->start,
+			      &ctl_mem_res->start);
+	}
+
+	ap->ioaddr.error_addr	= base + io_offset + 1 * reg_scale;
+	ap->ioaddr.feature_addr	= base + io_offset + 1 * reg_scale;
+	ap->ioaddr.nsect_addr	= base + io_offset + 2 * reg_scale;
+	ap->ioaddr.lbal_addr	= base + io_offset + 3 * reg_scale;
+	ap->ioaddr.lbam_addr	= base + io_offset + 4 * reg_scale;
+	ap->ioaddr.lbah_addr	= base + io_offset + 5 * reg_scale;
+	ap->ioaddr.device_addr	= base + io_offset + 6 * reg_scale;
+	ap->ioaddr.status_addr	= base + io_offset + 7 * reg_scale;
+	ap->ioaddr.command_addr	= base + io_offset + 7 * reg_scale;
+
+	ap->ioaddr.altstatus_addr	= ctl_base + io_offset;
+	ap->ioaddr.ctl_addr		= ctl_base + io_offset;
 
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
#10 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

In reply to Damien Le Moal

Hi Damien,

thanks for the review ...

Am 18.08.2023 um 12:51 schrieb Damien Le Moal:

Quoted 107 lines · Michael Schmitz
Quoted 106 lines

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes since RFC v4:

Geert Uytterhoeven:
- don't shift static module parameter for drive 3/4 bitmask
- simplify bit mask calculation to always use pdev->id

Finn Thain:
- correct bit numbers for drive 3/4

Changes since RFC v3:

- split off this byte swap handling into separate patch

- add hint regarding third and fourth drive on Q40

Finn Thain:
- rename module parameter to 'data_swab' to better reflect its use

William Sowerbutts:
- correct IDE drive number used in data swap conditional

---
 drivers/ata/pata_falcon.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/ata/pata_falcon.c +21 -1
index 346259e3bbc8..90488f565d6f 100644
@@ -33,6 +33,16 @@
 #define DRV_NAME "pata_falcon"
 #define DRV_VERSION "0.1.0"
 
+static int pata_falcon_swap_mask;
+
+module_param_named(data_swab, pata_falcon_swap_mask, int, 0444);
+MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default==0)");
+
+struct pata_falcon_priv {
+	unsigned int swap_mask;
+	bool swap_data;
+};
+
 static const struct scsi_host_template pata_falcon_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
@@ -44,13 +54,15 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
 	struct ata_device *dev = qc->dev;
 	struct ata_port *ap = dev->link->ap;
 	void __iomem *data_addr = ap->ioaddr.data_addr;
+	struct pata_falcon_priv *priv = ap->private_data;
 	unsigned int words = buflen >> 1;
 	struct scsi_cmnd *cmd = qc->scsicmd;
+	int dev_id = dev->devno;
 	bool swap = 1;
 
 	if (dev->class == ATA_DEV_ATA && cmd &&
 	    !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
-		swap = 0;
+		swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));
 
 	/* Transfer multiple of 2 bytes */
 	if (rw == READ) {
@@ -123,6 +135,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
+	struct pata_falcon_priv *priv;
 	void __iomem *base, *ctl_base;
 	int irq = 0, io_offset = 1, reg_scale = 4;
 
@@ -165,6 +178,13 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
+	priv = devm_kzalloc(&pdev->dev,
+		sizeof(struct pata_falcon_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	ap->private_data = priv;
+
 	/* N.B. this assumes data_addr will be used for word-sized I/O only */
 	ap->ioaddr.data_addr = (void __iomem *)base_mem_res->start;
 
Quoted 8 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 222

Quoted 5 lines
drivers/ata/pata_falcon.c +1 -0
@@ -199,6 +219,10 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->ioaddr.altstatus_addr	= ctl_base + io_offset;
 	ap->ioaddr.ctl_addr		= ctl_base + io_offset;
 
+	priv->swap_mask = pata_falcon_swap_mask >> (2 * pdev->id);

I do not understand the shift here. It seems that it will lead to priv->swap_mask always being 0...

On Q40, it is possible to have two ISA IDE adapters, and two platform devices are defined (in arch/m68k/q40/config.c) One will have pdev->id==0, the other will have pdev->id==1.

In the pdev->id==0 case, there's no shift of the bit mask passed in as module parameter, so the data transfer function will examine bits 0 and 1. That case we've verified in testing. In the other case, we shift down by two bits, so the data transfer function will now examine bits 2 and 3 from the module parameter.

Quoted 7 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 224

Quoted 3 lines
drivers/ata/pata_falcon.c +2 -0
+	if (priv->swap_mask)
+		priv->swap_data = 1;

I do not understand why priv->swap_data is needed, given that it is set to 1 if priv->swap_mask != 0, the above:

Quoted 7 lines
	swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));

should be equivalent to the simpler:

	swap = priv->swap_mask & BIT(dev_id);

No ? Am I missing something ?

I had hoped to avoid the pointer dereference and bit shift in the default (and by far most common) case where none of the bits are set.

Compared to the simpler version, I actually just save the bit shift, so it's probably a pointless optimization.

Finn had suggested to simplify this even further, and use ap->private as bit mask directly (saving the kzalloc()). If you're OK with that, I'll change the code accordingly.

Cheers,

Michael

Quoted 5 lines
Quoted 4 lines
drivers/ata/pata_falcon.c +1 -0
+
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
 		irq = irq_res->start;
maintainer
#11 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

Quoted 149 lines · Michael Schmitz

Hi Damien,

thanks for the review ...

Am 18.08.2023 um 12:51 schrieb Damien Le Moal:

Quoted 107 lines · Michael Schmitz
Quoted 106 lines

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes since RFC v4:

Geert Uytterhoeven:
- don't shift static module parameter for drive 3/4 bitmask
- simplify bit mask calculation to always use pdev->id

Finn Thain:
- correct bit numbers for drive 3/4

Changes since RFC v3:

- split off this byte swap handling into separate patch

- add hint regarding third and fourth drive on Q40

Finn Thain:
- rename module parameter to 'data_swab' to better reflect its use

William Sowerbutts:
- correct IDE drive number used in data swap conditional

---
 drivers/ata/pata_falcon.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/ata/pata_falcon.c +21 -1
index 346259e3bbc8..90488f565d6f 100644
@@ -33,6 +33,16 @@
 #define DRV_NAME "pata_falcon"
 #define DRV_VERSION "0.1.0"
 
+static int pata_falcon_swap_mask;
+
+module_param_named(data_swab, pata_falcon_swap_mask, int, 0444);
+MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default==0)");
+
+struct pata_falcon_priv {
+	unsigned int swap_mask;
+	bool swap_data;
+};
+
 static const struct scsi_host_template pata_falcon_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
@@ -44,13 +54,15 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
 	struct ata_device *dev = qc->dev;
 	struct ata_port *ap = dev->link->ap;
 	void __iomem *data_addr = ap->ioaddr.data_addr;
+	struct pata_falcon_priv *priv = ap->private_data;
 	unsigned int words = buflen >> 1;
 	struct scsi_cmnd *cmd = qc->scsicmd;
+	int dev_id = dev->devno;
 	bool swap = 1;
 
 	if (dev->class == ATA_DEV_ATA && cmd &&
 	    !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
-		swap = 0;
+		swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));
 
 	/* Transfer multiple of 2 bytes */
 	if (rw == READ) {
@@ -123,6 +135,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
+	struct pata_falcon_priv *priv;
 	void __iomem *base, *ctl_base;
 	int irq = 0, io_offset = 1, reg_scale = 4;
 
@@ -165,6 +178,13 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
+	priv = devm_kzalloc(&pdev->dev,
+		sizeof(struct pata_falcon_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	ap->private_data = priv;
+
 	/* N.B. this assumes data_addr will be used for word-sized I/O only */
 	ap->ioaddr.data_addr = (void __iomem *)base_mem_res->start;
 
Quoted 8 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 222

Quoted 5 lines
drivers/ata/pata_falcon.c +1 -0
@@ -199,6 +219,10 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->ioaddr.altstatus_addr	= ctl_base + io_offset;
 	ap->ioaddr.ctl_addr		= ctl_base + io_offset;
 
+	priv->swap_mask = pata_falcon_swap_mask >> (2 * pdev->id);

I do not understand the shift here. It seems that it will lead to priv->swap_mask always being 0...

On Q40, it is possible to have two ISA IDE adapters, and two platform devices are defined (in arch/m68k/q40/config.c) One will have pdev->id==0, the other will have pdev->id==1.

In the pdev->id==0 case, there's no shift of the bit mask passed in as module parameter, so the data transfer function will examine bits 0 and
1. That case we've verified in testing.
In the other case, we shift down by two bits, so the data transfer function will now examine bits 2 and 3 from the module parameter.

Quoted 7 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 224

Quoted 3 lines
drivers/ata/pata_falcon.c +2 -0
+	if (priv->swap_mask)
+		priv->swap_data = 1;

I do not understand why priv->swap_data is needed, given that it is set to 1 if priv->swap_mask != 0, the above:

Quoted 7 lines
	swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));

should be equivalent to the simpler:

	swap = priv->swap_mask & BIT(dev_id);

No ? Am I missing something ?

I had hoped to avoid the pointer dereference and bit shift in the default (and by far most common) case where none of the bits are set.

Quoted 6 lines

Compared to the simpler version, I actually just save the bit shift, so it's probably a pointless optimization.

Finn had suggested to simplify this even further, and use ap->private as bit mask directly (saving the kzalloc()). If you're OK with that, I'll change the code accordingly.

Sounds good. And given that we are talking about old IDE devices, which are *really* slow, I would not worry too much about optimizing for pointer dereference :)

Quoted 11 lines

Cheers,

Michael

Quoted 5 lines
Quoted 4 lines
drivers/ata/pata_falcon.c +1 -0
+
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
 		irq = irq_res->start;
Signature · 2 lines
Damien Le Moal
Western Digital Research
#12 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

Hi Damien,

Am 18.08.2023 um 15:15 schrieb Damien Le Moal:

Quoted 153 lines · Michael Schmitz
Quoted 152 lines

Hi Damien,

thanks for the review ...

Am 18.08.2023 um 12:51 schrieb Damien Le Moal:

Quoted 107 lines · Michael Schmitz
Quoted 106 lines

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes since RFC v4:

Geert Uytterhoeven:
- don't shift static module parameter for drive 3/4 bitmask
- simplify bit mask calculation to always use pdev->id

Finn Thain:
- correct bit numbers for drive 3/4

Changes since RFC v3:

- split off this byte swap handling into separate patch

- add hint regarding third and fourth drive on Q40

Finn Thain:
- rename module parameter to 'data_swab' to better reflect its use

William Sowerbutts:
- correct IDE drive number used in data swap conditional

---
 drivers/ata/pata_falcon.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/ata/pata_falcon.c +21 -1
index 346259e3bbc8..90488f565d6f 100644
@@ -33,6 +33,16 @@
 #define DRV_NAME "pata_falcon"
 #define DRV_VERSION "0.1.0"
 
+static int pata_falcon_swap_mask;
+
+module_param_named(data_swab, pata_falcon_swap_mask, int, 0444);
+MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default==0)");
+
+struct pata_falcon_priv {
+	unsigned int swap_mask;
+	bool swap_data;
+};
+
 static const struct scsi_host_template pata_falcon_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
@@ -44,13 +54,15 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
 	struct ata_device *dev = qc->dev;
 	struct ata_port *ap = dev->link->ap;
 	void __iomem *data_addr = ap->ioaddr.data_addr;
+	struct pata_falcon_priv *priv = ap->private_data;
 	unsigned int words = buflen >> 1;
 	struct scsi_cmnd *cmd = qc->scsicmd;
+	int dev_id = dev->devno;
 	bool swap = 1;
 
 	if (dev->class == ATA_DEV_ATA && cmd &&
 	    !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
-		swap = 0;
+		swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));
 
 	/* Transfer multiple of 2 bytes */
 	if (rw == READ) {
@@ -123,6 +135,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
+	struct pata_falcon_priv *priv;
 	void __iomem *base, *ctl_base;
 	int irq = 0, io_offset = 1, reg_scale = 4;
 
@@ -165,6 +178,13 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
+	priv = devm_kzalloc(&pdev->dev,
+		sizeof(struct pata_falcon_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	ap->private_data = priv;
+
 	/* N.B. this assumes data_addr will be used for word-sized I/O only */
 	ap->ioaddr.data_addr = (void __iomem *)base_mem_res->start;
 
Quoted 8 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 222

Quoted 5 lines
drivers/ata/pata_falcon.c +1 -0
@@ -199,6 +219,10 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->ioaddr.altstatus_addr	= ctl_base + io_offset;
 	ap->ioaddr.ctl_addr		= ctl_base + io_offset;
 
+	priv->swap_mask = pata_falcon_swap_mask >> (2 * pdev->id);

I do not understand the shift here. It seems that it will lead to priv->swap_mask always being 0...

On Q40, it is possible to have two ISA IDE adapters, and two platform devices are defined (in arch/m68k/q40/config.c) One will have pdev->id==0, the other will have pdev->id==1.

In the pdev->id==0 case, there's no shift of the bit mask passed in as module parameter, so the data transfer function will examine bits 0 and
1. That case we've verified in testing.
In the other case, we shift down by two bits, so the data transfer function will now examine bits 2 and 3 from the module parameter.

Quoted 7 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 224

Quoted 3 lines
drivers/ata/pata_falcon.c +2 -0
+	if (priv->swap_mask)
+		priv->swap_data = 1;

I do not understand why priv->swap_data is needed, given that it is set to 1 if priv->swap_mask != 0, the above:

Quoted 7 lines
	swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));

should be equivalent to the simpler:

	swap = priv->swap_mask & BIT(dev_id);

No ? Am I missing something ?

I had hoped to avoid the pointer dereference and bit shift in the default (and by far most common) case where none of the bits are set.

Compared to the simpler version, I actually just save the bit shift, so it's probably a pointless optimization.

Quoted 7 lines
Quoted 3 lines

Finn had suggested to simplify this even further, and use ap->private as bit mask directly (saving the kzalloc()). If you're OK with that, I'll change the code accordingly.

Sounds good. And given that we are talking about old IDE devices, which are *really* slow, I would not worry too much about optimizing for pointer dereference :)

The drive's probably faster than the CPU, at least the one I'm currently using :)

Regardless, I'll change this, test and respin.

Cheers,

Michael

Quoted 13 lines
Quoted 12 lines

Cheers,

Michael

Quoted 5 lines
Quoted 4 lines
drivers/ata/pata_falcon.c +1 -0
+
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
 		irq = irq_res->start;
#4 lore raw

Re: [PATCH 1/3] m68k/q40: fix IO base selection for Q40 in pata_falcon.c

In reply to Michael Schmitz
Quoted 8 lines · Michael Schmitz
Quoted 4 lines
Quoted 1 line
Cc <[email protected]> # 5.14

5.14+ ? But I do not think you need to specify anything anyway since you have the Fixes tag.

5.14+ perhaps. I'll check the docs again to see whether Fixes: obsoletes the stable backport tag. I've so far used both together...

You'd specify a "# x.y+" limit along with a "Fixes" tag if you don't want to backport as far back as the buggy commit (because some other pre-requisite isn't present on the older branches). But that does not apply in this case.

Writing "# 5.14" is surprising because (according to www.kernel.org landing page) that branch was abandoned, and no live branch was named. But in "git log" you can see that people write this anyway.

Writing "# 5.14+" or "# 5.15+" is clear enough but is normally omitted when it can be inferred from the Fixes tag. That's been my experience, at least.

Reviewed-by on v1 1/3
#5 lore raw

Re: [PATCH 1/3] m68k/q40: fix IO base selection for Q40 in pata_falcon.c

In reply to Michael Schmitz

Hello!

Quoted 29 lines · Michael Schmitz

With commit 44b1fbc0f5f3 ("m68k/q40: Replace q40ide driver with pata_falcon and falconide"), the Q40 IDE driver was replaced by pata_falcon.c.

Both IO and memory resources were defined for the Q40 IDE platform device, but definition of the IDE register addresses was modeled after the Falcon case, both in use of the memory resources and in including register scale and byte vs. word offset in the address.

This was correct for the Falcon case, which does not apply any address translation to the register addresses. In the Q40 case, all of device base address, byte access offset and register scaling is included in the platform specific ISA access translation (in asm/mm_io.h).

As a consequence, such address translation gets applied twice, and register addresses are mangled.

Use the device base address from the platform IO resource, and use standard register offsets from that base in order to calculate register addresses (the IO address translation will then apply the correct ISA window base and scaling).

Encode PIO_OFFSET into IO port addresses for all registers except the data transfer register. Encode the MMIO offset there (pata_falcon_data_xfer() directly uses raw IO with no address translation).

Quoted 8 lines

[...]

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 127

Quoted 12 lines
drivers/ata/pata_falcon.c +2 -2
index 996516e64f13..346259e3bbc8 100644
@@ -123,8 +123,8 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct resource *base_res, *ctl_res, *irq_res;
 	struct ata_host *host;
 	struct ata_port *ap;
-	void __iomem *base;
-	int irq = 0;
+	void __iomem *base, *ctl_base;
+	int irq = 0, io_offset = 1, reg_scale = 4;

Maybe reg_step?

[...]

MBR, Sergey

#13 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

In reply to Michael Schmitz
Quoted 51 lines · Michael Schmitz

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes since RFC v4:

Geert Uytterhoeven:
- don't shift static module parameter for drive 3/4 bitmask
- simplify bit mask calculation to always use pdev->id

Finn Thain:
- correct bit numbers for drive 3/4

Changes since RFC v3:

- split off this byte swap handling into separate patch

- add hint regarding third and fourth drive on Q40

Finn Thain:
- rename module parameter to 'data_swab' to better reflect its use

William Sowerbutts:
- correct IDE drive number used in data swap conditional

---
 drivers/ata/pata_falcon.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/ata/pata_falcon.c +0 -0
index 346259e3bbc8..90488f565d6f 100644

drivers/ata/pata_falcon.c line 39

Quoted 7 lines
drivers/ata/pata_falcon.c +4 -0
@@ -33,6 +33,16 @@
 #define DRV_NAME "pata_falcon"
 #define DRV_VERSION "0.1.0"
 
+static int pata_falcon_swap_mask;
+
+module_param_named(data_swab, pata_falcon_swap_mask, int, 0444);
+MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default==0)");

Hm, Greg KH keeps saying us that the module parameters belong to '90s. :-)

[...]

drivers/ata/pata_falcon.c static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc, · line 60

Quoted 8 lines
drivers/ata/pata_falcon.c +2 -0
@@ -44,13 +54,15 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
 	struct ata_device *dev = qc->dev;
 	struct ata_port *ap = dev->link->ap;
 	void __iomem *data_addr = ap->ioaddr.data_addr;
+	struct pata_falcon_priv *priv = ap->private_data;
 	unsigned int words = buflen >> 1;
 	struct scsi_cmnd *cmd = qc->scsicmd;
+	int dev_id = dev->devno;

You hardly need this variable...

drivers/ata/pata_falcon.c static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc, · line 65

Quoted 6 lines
drivers/ata/pata_falcon.c +1 -1
 	bool swap = 1;
 
 	if (dev->class == ATA_DEV_ATA && cmd &&
 	    !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
-		swap = 0;
+		swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));

This looks convoluted -- only the 2nd subexpression should be enough...

[...]

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 182

Quoted 6 lines
drivers/ata/pata_falcon.c +2 -0
@@ -165,6 +178,13 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ap->pio_mask = ATA_PIO4;
 	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
+	priv = devm_kzalloc(&pdev->dev,
+		sizeof(struct pata_falcon_priv), GFP_KERNEL);

sizeof(*priv) is preferred IIRC...

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 186

Quoted 4 lines
drivers/ata/pata_falcon.c +4 -0
+	if (!priv)
+		return -ENOMEM;
+
+	ap->private_data = priv;

Also you hardly need a heap allocation -- encoding your couple flags
could use the ap->private_data itself...

[...]

MBR, Sergey

#6 lore raw

Re: [PATCH 1/3] m68k/q40: fix IO base selection for Q40 in pata_falcon.c

In reply to Sergey Shtylyov

Hi Sergey,

thanks for your review!

Quoted 44 lines · Sergey Shtylyov

Hello!

Quoted 29 lines · Michael Schmitz

With commit 44b1fbc0f5f3 ("m68k/q40: Replace q40ide driver with pata_falcon and falconide"), the Q40 IDE driver was replaced by pata_falcon.c.

Both IO and memory resources were defined for the Q40 IDE platform device, but definition of the IDE register addresses was modeled after the Falcon case, both in use of the memory resources and in including register scale and byte vs. word offset in the address.

This was correct for the Falcon case, which does not apply any address translation to the register addresses. In the Q40 case, all of device base address, byte access offset and register scaling is included in the platform specific ISA access translation (in asm/mm_io.h).

As a consequence, such address translation gets applied twice, and register addresses are mangled.

Use the device base address from the platform IO resource, and use standard register offsets from that base in order to calculate register addresses (the IO address translation will then apply the correct ISA window base and scaling).

Encode PIO_OFFSET into IO port addresses for all registers except the data transfer register. Encode the MMIO offset there (pata_falcon_data_xfer() directly uses raw IO with no address translation).

Quoted 8 lines

[...]

Quoted 13 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 127

Quoted 12 lines
drivers/ata/pata_falcon.c +2 -2
index 996516e64f13..346259e3bbc8 100644
@@ -123,8 +123,8 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
  	struct resource *base_res, *ctl_res, *irq_res;
  	struct ata_host *host;
  	struct ata_port *ap;
-	void __iomem *base;
-	int irq = 0;
+	void __iomem *base, *ctl_base;
+	int irq = 0, io_offset = 1, reg_scale = 4;

Maybe reg_step?

Could name it that, too. I can't recall where I picked up the term 'register scaling'...

I'll see what's the consensus (if any) in drivers/.

Cheers,

    Michael

Quoted 4 lines

[...]

MBR, Sergey

#14 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

In reply to Sergey Shtylyov

Hi Sergey,

thanks for reviewing - this has mostly been addressed in v2 or v3 (which I forgot to send to you, sorry). Damien asked for the patch title to be changed (now 'ata: pata_falcon: add data_swab option to byte-swap disk data) so you might have missed it on the list.

Quoted 56 lines · Sergey Shtylyov
Quoted 54 lines · Michael Schmitz

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---

Changes since RFC v4:

Geert Uytterhoeven:
- don't shift static module parameter for drive 3/4 bitmask
- simplify bit mask calculation to always use pdev->id

Finn Thain:
- correct bit numbers for drive 3/4

Changes since RFC v3:

- split off this byte swap handling into separate patch

- add hint regarding third and fourth drive on Q40

Finn Thain:
- rename module parameter to 'data_swab' to better reflect its use

William Sowerbutts:
- correct IDE drive number used in data swap conditional

---
  drivers/ata/pata_falcon.c | 26 +++++++++++++++++++++++++-
  1 file changed, 25 insertions(+), 1 deletion(-)
drivers/ata/pata_falcon.c +0 -0
index 346259e3bbc8..90488f565d6f 100644
@@ -33,6 +33,16 @@
  #define DRV_NAME "pata_falcon"
  #define DRV_VERSION "0.1.0"
 
Quoted 5 lines

drivers/ata/pata_falcon.c line 39

Quoted 4 lines
drivers/ata/pata_falcon.c +4 -0
+static int pata_falcon_swap_mask;
+
+module_param_named(data_swab, pata_falcon_swap_mask, int, 0444);
+MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default==0)");

Hm, Greg KH keeps saying us that the module parameters belong to '90s. :-)

What else can I use that would allow setting a driver parameter at boot time? This driver will be built-in pretty much all the time.

Quoted 11 lines

[...]

drivers/ata/pata_falcon.c static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc, · line 60

Quoted 8 lines
drivers/ata/pata_falcon.c +2 -0
@@ -44,13 +54,15 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
  	struct ata_device *dev = qc->dev;
  	struct ata_port *ap = dev->link->ap;
  	void __iomem *data_addr = ap->ioaddr.data_addr;
+	struct pata_falcon_priv *priv = ap->private_data;
  	unsigned int words = buflen >> 1;
  	struct scsi_cmnd *cmd = qc->scsicmd;
+	int dev_id = dev->devno;

You hardly need this variable...

Fixed in v3.

Quoted 8 lines

drivers/ata/pata_falcon.c static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc, · line 65

Quoted 7 lines
drivers/ata/pata_falcon.c +1 -1
  	bool swap = 1;
 
  	if (dev->class == ATA_DEV_ATA && cmd &&
  	    !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
-		swap = 0;
+		swap = priv->swap_data && (priv->swap_mask & BIT(dev_id));

This looks convoluted -- only the 2nd subexpression should be enough...

Pointless attempt at optimizing this for the default case. Gone now.

Quoted 10 lines

[...]

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 182

Quoted 6 lines
drivers/ata/pata_falcon.c +2 -0
@@ -165,6 +178,13 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
  	ap->pio_mask = ATA_PIO4;
  	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
+	priv = devm_kzalloc(&pdev->dev,
+		sizeof(struct pata_falcon_priv), GFP_KERNEL);

sizeof(*priv) is preferred IIRC...

Quoted 6 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 186

Quoted 4 lines
drivers/ata/pata_falcon.c +4 -0
+	if (!priv)
+		return -ENOMEM;
+
+	ap->private_data = priv;

Also you hardly need a heap allocation -- encoding your couple flags
could use the ap->private_data itself...

That's what Finn suggested as well - changed in v2.

Cheers,

    Michael

Quoted 4 lines

[...]

MBR, Sergey

#7 lore raw

Re: [PATCH 1/3] m68k/q40: fix IO base selection for Q40 in pata_falcon.c

In reply to Michael Schmitz

Hi Sergey,

Am 21.08.2023 um 07:19 schrieb Michael Schmitz:

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/ata/pata_falcon.c +0 -0
index 996516e64f13..346259e3bbc8 100644
@@ -123,8 +123,8 @@ static int __init pata_falcon_init_one(struct
 platform_device *pdev)
Quoted 8 lines

drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 127

Quoted 7 lines
drivers/ata/pata_falcon.c +2 -2
      struct resource *base_res, *ctl_res, *irq_res;
      struct ata_host *host;
      struct ata_port *ap;
-    void __iomem *base;
-    int irq = 0;
+    void __iomem *base, *ctl_base;
+    int irq = 0, io_offset = 1, reg_scale = 4;

Maybe reg_step?

Quoted 4 lines

Could name it that, too. I can't recall where I picked up the term 'register scaling'...

I'll see what's the consensus (if any) in drivers/.

I've seen some use of 'step' but mostly use of 'shift'.

Rewriting pata_falcon_init_one() to use register shift instead of register step is trivial, so unless anyone objects, I'll send that version as v4.

Cheers,

Michael

Quoted 10 lines

Cheers,

Michael

Quoted 4 lines

[...]

MBR, Sergey

#15 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

In reply to Michael Schmitz

Hello!

On 8/20/23 10:27 PM, Michael Schmitz wrote:
[...]

Quoted 1 line

thanks for reviewing - this has mostly been addressed in v2 or v3 (which I forgot to send to you, sorry). Damien asked for the patch title to be changed (now 'ata: pata_falcon: add data_swab option to byte-swap disk data) so you might have missed it on the list.

I didn't want to repeat such request after him. :-)
I'm subscribed to linux-ide thru my Gmail account, and I'm still not seeing
your further patch versions on the list... :-/

[...]

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

[...]

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/ata/pata_falcon.c +0 -0
index 346259e3bbc8..90488f565d6f 100644
Quoted 8 lines

drivers/ata/pata_falcon.c line 38

Quoted 7 lines
drivers/ata/pata_falcon.c +3 -0
@@ -33,6 +33,16 @@
   #define DRV_NAME "pata_falcon"
   #define DRV_VERSION "0.1.0"
   +static int pata_falcon_swap_mask;
+
+module_param_named(data_swab, pata_falcon_swap_mask, int, 0444);
+MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default==0)");

    Hm, Greg KH keeps saying us that the module parameters belong to '90s. :-)

Quoted 1 line

What else can I use that would allow setting a driver parameter at boot time? This driver will be built-in pretty much all the time.

I guess he means sysfs...

[...]

MBR, Sergey

#16 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

On 8/22/23 10:10 PM, Sergei Shtylyov wrote:
[...]

Quoted 5 lines
Quoted 1 line

thanks for reviewing - this has mostly been addressed in v2 or v3 (which I forgot to send to you, sorry). Damien asked for the patch title to be changed (now 'ata: pata_falcon: add data_swab option to byte-swap disk data) so you might have missed it on the list.

I didn't want to repeat such request after him. :-)
I'm subscribed to linux-ide thru my Gmail account, and I'm still not seeing
your further patch versions on the list... :-/

Had to reply from Gmail account as the OMP server rejected my msg.
Please be sure to always CC: me on the PATA patches!

Quoted 14 lines

[...]

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Some users of pata_falcon on Q40 have IDE disks in default IDE little endian byte order, whereas legacy disks use host-native big-endian byte order as on the Atari Falcon.

Add module parameter 'data_swab' to allow connecting drives with non-native data byte order. Drives selected by the data_swap bit mask will have their user data byte-swapped to host byte order, i.e. 'pata_falcon.data_swab=2' will byte-swap all user data on drive B, leaving data on drive A in native byte order. On Q40, drives on a second IDE interface may be added to the bit mask as bits 2 and 3.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.

Cc William R Sowerbutts <[email protected]>
Cc Finn Thain <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

[...]

MBR, Sergey

#17 lore raw

Re: [PATCH 2/3] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data

Hi Sergey,

Am 23.08.2023 um 07:44 schrieb Sergei Shtylyov:

Quoted 11 lines · Sergei Shtylyov

[...]

Quoted 5 lines
Quoted 1 line

thanks for reviewing - this has mostly been addressed in v2 or v3 (which I forgot to send to you, sorry). Damien asked for the patch title to be changed (now 'ata: pata_falcon: add data_swab option to byte-swap disk data) so you might have missed it on the list.

I didn't want to repeat such request after him. :-)
I'm subscribed to linux-ide thru my Gmail account, and I'm still not seeing
your further patch versions on the list... :-/

Had to reply from Gmail account as the OMP server rejected my msg.
Please be sure to always CC: me on the PATA patches!

Will do - v4 to go out shortly (afer a final boot test).

Cheers,

Michael