Q40 IDE fixes
v3 cover Q40 IDE fixes
v4 of the Q40 IDE patch, split into two parts. First patch just fixes the bug introduced when converting Q40 to use pata_falcon, second patch adds the byte-swapping option requested by William.
Please review this again, just to make sure I haven't messed up anything when applying the review comments to the split patches.
Cheers,
Michael
RFC PATCH v3 1/2 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 (and the later obsoleted falconide.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 v3:
- split off byte swap option into separate patch
Geert Uytterhoeven:
- review comments
Changes from v2:
- add driver parameter 'data_swap' as bit mask for drives to swap
Changes from 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
@@ -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
RFC PATCH v3 2/2 m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
In reply to Michael SchmitzSome users of pata_falcon on Q40 have IDE disks in classic little endian byte order, whereas legacy disks use 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 3 and 4.
Default setting is no byte swapping, i.e. compatibility with the native Falcon or Q40 operating system disk format.
---
Changes since 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 | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/ata/pata_falcon.c +28 -1
@@ -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,10 +178,20 @@ 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;if (base_res) {/* only Q40 has IO resources */ +if (pdev->id) + pata_falcon_swap_mask >>=2 ; + priv->swap_mask = pata_falcon_swap_mask; io_offset =0x10000 ; reg_scale =1 ; base = (void __iomem *)base_res->start;
@@ -178,6 +201,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev) &base_res->start, &ctl_res->start); }else { + priv->swap_mask = pata_falcon_swap_mask; base = (void __iomem *)base_mem_res->start; ctl_base = (void __iomem *)ctl_mem_res->start;
@@ -199,6 +223,9 @@ 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; +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
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Quoted 11 lines · Michael Schmitz
Some users of
pata_falconon Q40 have IDE disks in classic little endian byte order, whereas legacy disks use 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 thedata_swapbit 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 3 and 4.
Many would say that's off by one, as it's popular to number the LSB as bit zero.
Quoted 103 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]>Signed-off-by Michael Schmitz <[email protected]>---
Changes since 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 useWilliam Sowerbutts:
- correct IDE drive number used in data swap conditional--- drivers/ata/pata_falcon.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/ata/pata_falcon.c +25
-1@@ -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,10 +178,20 @@ 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;if (base_res) {/* only Q40 has IO resources */ +if (pdev->id) + pata_falcon_swap_mask >>=2 ; + priv->swap_mask = pata_falcon_swap_mask; io_offset =0x10000 ; reg_scale =1 ; base = (void __iomem *)base_res->start;@@ -178,6 +201,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev) &base_res->start, &ctl_res->start); }else { + priv->swap_mask = pata_falcon_swap_mask; base = (void __iomem *)base_mem_res->start; ctl_base = (void __iomem *)ctl_mem_res->start;
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 231
Quoted 9 lines
drivers/ata/pata_falcon.c +3
-0@@ -199,6 +223,9 @@ 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; +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;
I think the patch could be simplified by dropping the dynamic memory allocation...
drivers/ata/pata_falcon.c +8 -1
@@ -33,6 +33,11 @@#define DRV_NAME "pata_falcon"#define DRV_VERSION "0.1.0" +static int pata_falcon_data_swab; + +module_param_named (data_swab, pata_falcon_data_swab, int,0444 ); +MODULE_PARM_DESC (data_swab,"Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default: 0)" ); +static const struct scsi_host_template pata_falcon_sht = {ATA_PIO_SHT (DRV_NAME ), };
@@ -50,7 +55,7 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,if (dev->class ==ATA_DEV_ATA && cmd && !blk_rq_is_passthrough (scsi_cmd_to_rq (cmd))) - swap =0 ; + swap = (int )ap->private_data &BIT (dev->devno);/* Transfer multiple of 2 bytes */ if (rw ==READ ) {
@@ -199,6 +204,8 @@ 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; + ap->private_data = (void *)((pata_falcon_data_swab >> (2 * pdev->id)) &3 ); + irq_res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 );if (irq_res && irq_res->start >0 ) { irq = irq_res->start;
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Quoted 42 lines · Finn Thain
Quoted 11 lines · Michael Schmitz
Some users of
pata_falconon Q40 have IDE disks in classic little endian byte order, whereas legacy disks use 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 thedata_swapbit 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 3 and 4.Many would say that's off by one, as it's popular to number the LSB as bit zero.
Quoted 26 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]>Signed-off-by Michael Schmitz <[email protected]>drivers/ata/pata_falcon.c +7
-0@@ -165,10 +178,20 @@ 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 3 lines
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 193
Quoted 3 lines
drivers/ata/pata_falcon.c +2
-0if (base_res) {/* only Q40 has IO resources */ +if (pdev->id) + pata_falcon_swap_mask >>=2 ;
Although this driver uses module_platform_driver_probe(), and thus does not support unbind/rebind, shifting a global variable is still fragile, and depends on probe order (what if the second interface is probed first?).
Quoted 1 line
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 194
Quoted 1 line
drivers/ata/pata_falcon.c +1
-0+ priv->swap_mask = pata_falcon_swap_mask;
priv->swap_mask = pata_falcon_swap_mask >> (2 * pdev->id);
Quoted 15 lines
drivers/ata/pata_falcon.c +5
-0@@ -33,6 +33,11 @@#define DRV_NAME "pata_falcon"#define DRV_VERSION "0.1.0" +static int pata_falcon_data_swab; + +module_param_named (data_swab, pata_falcon_data_swab, int,0444 ); +MODULE_PARM_DESC (data_swab,"Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default: 0)" ); +static const struct scsi_host_template pata_falcon_sht = {ATA_PIO_SHT (DRV_NAME ), };
drivers/ata/pata_falcon.c static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc, · line 58
Quoted 5 lines
drivers/ata/pata_falcon.c +1
-1@@ -50,7 +55,7 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,if (dev->class ==ATA_DEV_ATA && cmd && !blk_rq_is_passthrough (scsi_cmd_to_rq (cmd))) - swap =0 ; + swap = (int )ap->private_data &BIT (dev->devno);
"(uintptr_t)", to make it 64-bit clean.
Yeah, we don't support COMPILE_TEST=y yet for PATA_FALCON. BTW, looks like we don't need any of the following anymore:
#include <asm/setup.h>
#include <asm/atarihw.h>
#include <asm/atariints.h>
#include <asm/atari_stdma.h>That leaves us with <asm/ide.h>, (which does not exist on most architectures, and seems to be mostly obsolete), for the (indirectly included) definitions of raw_{in,out}sw_{,swapw}()....
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 207
Quoted 8 lines
drivers/ata/pata_falcon.c +1
-0/* Transfer multiple of 2 bytes */ if (rw ==READ ) {@@ -199,6 +204,8 @@ 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; + ap->private_data = (void *)((pata_falcon_data_swab >> (2 * pdev->id)) &3 );
"(void *)(uintptr_t)", to make it 64-bit clean.
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 211
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;
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Hi Geert,
Quoted 39 lines · Geert Uytterhoeven
Quoted 38 lines · Finn Thain
Quoted 11 lines · Michael Schmitz
Some users of
pata_falconon Q40 have IDE disks in classic little endian byte order, whereas legacy disks use 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 thedata_swapbit 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 3 and 4.Many would say that's off by one, as it's popular to number the LSB as bit zero.
Quoted 23 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]>Signed-off-by Michael Schmitz <[email protected]>drivers/ata/pata_falcon.c +7
-0@@ -165,10 +178,20 @@ 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 7 lines
Quoted 3 lines
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 193
Quoted 3 lines
drivers/ata/pata_falcon.c +2
-0if (base_res) {/* only Q40 has IO resources */ +if (pdev->id) + pata_falcon_swap_mask >>=2 ;Although this driver uses
module_platform_driver_probe(), and thus does not support unbind/rebind, shifting a global variable is still fragile, and depends on probe order (what if the second interface is probed first?).
True - I had worried about that but forgot to change it.
Quoted 3 lines
Quoted 2 lines
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 194
Quoted 2 lines
drivers/ata/pata_falcon.c +1
-0+ priv->swap_mask = pata_falcon_swap_mask;
priv->swap_mask=pata_falcon_swap_mask>> (2 *pdev->id);
The Atari platform driver data is registered with pdev->id=-1. That'll break here.
(Not sure why that choice of pdev->id, and whether it can be changed to 0 easily)
Cheers,
Michael
Quoted 52 lines
Quoted 16 lines
drivers/ata/pata_falcon.c +5
-0@@ -33,6 +33,11 @@#define DRV_NAME "pata_falcon"#define DRV_VERSION "0.1.0" +static int pata_falcon_data_swab; + +module_param_named (data_swab, pata_falcon_data_swab, int,0444 ); +MODULE_PARM_DESC (data_swab,"Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default: 0)" ); +static const struct scsi_host_template pata_falcon_sht = {ATA_PIO_SHT (DRV_NAME ), };drivers/ata/pata_falcon.c static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc, · line 58
Quoted 5 lines
drivers/ata/pata_falcon.c +1
-1@@ -50,7 +55,7 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,if (dev->class ==ATA_DEV_ATA && cmd && !blk_rq_is_passthrough (scsi_cmd_to_rq (cmd))) - swap =0 ; + swap = (int )ap->private_data &BIT (dev->devno);"(
uintptr_t)", to make it 64-bit clean.Yeah, we don't support COMPILE_TEST=y yet for
PATA_FALCON. BTW, looks like we don't need any of the following anymore:#include <asm/setup.h> #include <asm/atarihw.h> #include <asm/atariints.h> #include <asm/atari_stdma.h>That leaves us with <
asm/ide.h>, (which does not exist on most architectures, and seems to be mostly obsolete), for the (indirectly included) definitions of raw_{in,out}sw_{,swapw}()....drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 207
Quoted 7 lines
drivers/ata/pata_falcon.c +1
-0/* Transfer multiple of 2 bytes */ if (rw ==READ ) {@@ -199,6 +204,8 @@ 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; + ap->private_data = (void *)((pata_falcon_data_swab >> (2 * pdev->id)) &3 );"(void *)(uintptr_t)", to make it 64-bit clean.
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 211
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;Gr{oetje,eeting}s,
Geert
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Hi Geert,
Quoted 5 lines · Michael Schmitz
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
+
priv->swap_mask=pata_falcon_swap_mask;
priv->swap_mask=pata_falcon_swap_mask>> (2 *pdev->id);The Atari platform driver data is registered with pdev->id=-1. That'll break here.
Confirmed.
Quoted 2 lines
(Not sure why that choice of
pdev->id, and whether it can be changed to 0 easily)
Seems to work OK with ID set to 0, so I'll simplify that as you suggest.
Cheers,
Michael
Quoted 61 lines
Cheers,
Michael
Quoted 56 lines
Quoted 19 lines
drivers/ata/pata_falcon.c +5
-0@@ -33,6 +33,11 @@ #define DRV_NAME "pata_falcon" #define DRV_VERSION "0.1.0" +static int pata_falcon_data_swab; + +module_param_named (data_swab, pata_falcon_data_swab, int,0444 ); +MODULE_PARM_DESC(data_swab, "Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default: 0)"); + static const struct scsi_host_template pata_falcon_sht = { ATA_PIO_SHT(DRV_NAME),};
drivers/ata/pata_falcon.c +0
-0@@ -50,7 +55,7 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,Quoted 4 lines
if (
dev->class==ATA_DEV_ATA&& cmd && !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd))) - swap = 0;
+ swap = (int)ap->private_data &BIT(dev->devno);"(
uintptr_t)", to make it 64-bit clean.Yeah, we don't support COMPILE_TEST=y yet for
PATA_FALCON. BTW, looks like we don't need any of the following anymore:#include <
asm/setup.h>
#include <asm/atarihw.h>
#include <asm/atariints.h>
#include <asm/atari_stdma.h>That leaves us with <
asm/ide.h>, (which does not exist on most architectures, and seems to be mostly obsolete), for the (indirectly included) definitions of raw_{in,out}sw_{,swapw}()....drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct · line 209
Quoted 9 lines
/* Transfer multiple of 2 bytes */
if (rw == READ) {drivers/ata/pata_falcon.c +1
-0@@ -199,6 +204,8 @@ 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; + ap->private_data = (void *)((pata_falcon_data_swab >> (2 * pdev->id)) &3 );"(void *)(uintptr_t)", to make it 64-bit clean.
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;Gr{oetje,eeting}s,
Geert
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Hi Michael,
Quoted 8 lines · Michael Schmitz
Quoted 5 lines · Michael Schmitz
Quoted 2 lines
Quoted 1 line
Quoted 1 line
+
priv->swap_mask=pata_falcon_swap_mask;
priv->swap_mask=pata_falcon_swap_mask>> (2 *pdev->id);The Atari platform driver data is registered with pdev->id=-1. That'll break here.
Confirmed.
Oops.
Quoted 3 lines
Quoted 2 lines
(Not sure why that choice of
pdev->id, and whether it can be changed to 0 easily)Seems to work OK with ID set to 0, so I'll simplify that as you suggest.
-1 is used to indicate there can only ever be a single instance. Of course 0 also works, but causes ".0" to be appended to the platform device's name, visible in e.g. /sys/bus/platform/devices/.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Quoted 3 lines · Geert Uytterhoeven
Of course 0 also works, but causes ".0" to be appended to the platform device's name, visible in e.g.
/sys/bus/platform/devices/.
That seems desirable to me.
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Hi Finn,
Quoted 5 lines · Finn Thain
Quoted 2 lines · Geert Uytterhoeven
Of course 0 also works, but causes ".0" to be appended to the platform device's name, visible in e.g.
/sys/bus/platform/devices/.That seems desirable to me.
Why would it be desirable?
IMHO this is an unneeded change which is visible in userspace.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Quoted 10 lines · Geert Uytterhoeven
Quoted 5 lines · Finn Thain
Quoted 2 lines · Geert Uytterhoeven
Of course 0 also works, but causes ".0" to be appended to the platform device's name, visible in e.g.
/sys/bus/platform/devices/.That seems desirable to me.
Why would it be desirable?
IMHO this is an unneeded change which is visible in userspace.
Only so what's visible in userspace would be consistent across atari and q40 (and anything else that happens to instantiate the device in future).
Basically, I don't really understand why id -1 is better than id 0. I've searched Documentation/device-tree and I still don't understand why a singleton would need a special bus id.
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
CC Adrian for comment...
Does anything in the Debian installer rely on a specific device name suffix in /sys/bus/platform/devices/ ?
On Atari, atari-falcon-ide does not have a suffix, but on Q40, it would get suffix .0 or .1 depending on what IO base the ISA IDE adapter uses.
Seeing as Q40 support in the atari-falcon-ide has been broken since it was introduced, this is rather about future installer support than about inadvertently breaking current code.
Cheers,
Michael
Quoted 16 lines · Finn Thain
Quoted 8 lines · Geert Uytterhoeven
Quoted 4 lines · Finn Thain
Quoted 2 lines · Geert Uytterhoeven
Of course 0 also works, but causes ".0" to be appended to the platform device's name, visible in e.g.
/sys/bus/platform/devices/.That seems desirable to me.
Why would it be desirable?
IMHO this is an unneeded change which is visible in userspace.Only so what's visible in userspace would be consistent across atari and q40 (and anything else that happens to instantiate the device in future).
Basically, I don't really understand why id -1 is better than id 0. I've searched
Documentation/device-treeand I still don't understand why a singleton would need a special bus id.
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Quoted 2 lines · Michael Schmitz
CC Adrian for comment...
My comments in the messages quoted below should not be interpreted as an objection to the patches Michael submitted.
I've already done too much bikeshedding there and while it's always tempting to do more I will desist.
This was just a look askance at the design of the driver model. So it's really only of academic interest.
Quoted 32 lines
Does anything in the Debian installer rely on a specific device name suffix in
/sys/bus/platform/devices/?On Atari, atari-falcon-ide does not have a suffix, but on Q40, it would get suffix .0 or .1 depending on what IO base the ISA IDE adapter uses.
Seeing as Q40 support in the atari-falcon-ide has been broken since it was introduced, this is rather about future installer support than about inadvertently breaking current code.
Cheers,
Michael
Quoted 16 lines · Finn Thain
Quoted 8 lines · Geert Uytterhoeven
Quoted 4 lines · Finn Thain
Quoted 2 lines · Geert Uytterhoeven
Of course 0 also works, but causes ".0" to be appended to the platform device's name, visible in e.g.
/sys/bus/platform/devices/.That seems desirable to me.
Why would it be desirable?
IMHO this is an unneeded change which is visible in userspace.Only so what's visible in userspace would be consistent across atari and q40 (and anything else that happens to instantiate the device in future).
Basically, I don't really understand why id -1 is better than id 0. I've searched
Documentation/device-treeand I still don't understand why a singleton would need a special bus id.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Hi Richard,
Quoted 1 line · Richard Z
Nitpicking now, there is nothing classic about little endian as all older computers were either big or mid endian.
Right, but IDE was introduced on little endian hardware.
Maybe 'IDE default byte order' would be more exact here.
Quoted 1 line
It is rather some rare ide host adapters like the Q40 one reversed the byte order of 16bit words which was cheap and convenient in the 1980-9ies but not interoperable with the large majority of other host adapters resulting in a reversed byte/16bit order on disk.
True - installing an IDE disk from e.g. Atari on a Mac, Amiga or PC wasn't something you'd have antcipated at that time. Floppy disks were for data interchange.
Cheers,
Michael
Quoted 2 lines
Richard
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
In reply to Finn ThainHi Finn.
Quoted 13 lines · Finn Thain
Quoted 11 lines · Michael Schmitz
Some users of
pata_falconon Q40 have IDE disks in classic little endian byte order, whereas legacy disks use 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 thedata_swapbit 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 3 and 4.
Quoted 2 lines
Many would say that's off by one, as it's popular to number the LSB as bit zero.
Old FORTRAN programmers never die. They just cause havoc in C.
I'll fix that.
Quoted 105 lines
Quoted 105 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]>Signed-off-by Michael Schmitz <[email protected]>---
Changes since 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 useWilliam Sowerbutts:
- correct IDE drive number used in data swap conditional--- drivers/ata/pata_falcon.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/ata/pata_falcon.c +25
-1@@ -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,10 +178,20 @@ 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;if (base_res) {/* only Q40 has IO resources */ +if (pdev->id) + pata_falcon_swap_mask >>=2 ; + priv->swap_mask = pata_falcon_swap_mask; io_offset =0x10000 ; reg_scale =1 ; base = (void __iomem *)base_res->start;@@ -178,6 +201,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev) &base_res->start, &ctl_res->start); }else { + priv->swap_mask = pata_falcon_swap_mask; base = (void __iomem *)base_mem_res->start; ctl_base = (void __iomem *)ctl_mem_res->start;@@ -199,6 +223,9 @@ 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;
Quoted 9 lines
drivers/ata/pata_falcon.c static int __init pata_falcon_init_one(struct platform_device *pdev) · line 211
Quoted 7 lines
drivers/ata/pata_falcon.c +3
-0+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;I think the patch could be simplified by dropping the dynamic memory allocation...
If using a private data pointer field for an int bitmask is acceptable use ...
I'll see if I can find any performance impact from the additional swap_data flag. If there's none, your solution may be cleaner.
Cheers,
Michael
Quoted 35 lines
drivers/ata/pata_falcon.c +8
-1@@ -33,6 +33,11 @@#define DRV_NAME "pata_falcon"#define DRV_VERSION "0.1.0" +static int pata_falcon_data_swab; + +module_param_named (data_swab, pata_falcon_data_swab, int,0444 ); +MODULE_PARM_DESC (data_swab,"Data byte swap enable/disable bitmap (0x1==drive1, 0x2==drive2, 0x4==drive3, 0x8==drive4, default: 0)" ); +static const struct scsi_host_template pata_falcon_sht = {ATA_PIO_SHT (DRV_NAME ), };@@ -50,7 +55,7 @@ static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,if (dev->class ==ATA_DEV_ATA && cmd && !blk_rq_is_passthrough (scsi_cmd_to_rq (cmd))) - swap =0 ; + swap = (int )ap->private_data &BIT (dev->devno);/* Transfer multiple of 2 bytes */ if (rw ==READ ) {@@ -199,6 +204,8 @@ 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; + ap->private_data = (void *)((pata_falcon_data_swab >> (2 * pdev->id)) &3 ); + irq_res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 );if (irq_res && irq_res->start >0 ) { irq = irq_res->start;
Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Quoted 6 lines · Michael Schmitz
Quoted 2 lines
I think the patch could be simplified by dropping the dynamic memory allocation...
If using a private data pointer field for an int bitmask is acceptable use ...
I thought that was implicit in Geert's response.
I used a similar technique in drivers/nubus/proc.c and it didn't bother anyone.
Quoted 3 lines
I'll see if I can find any performance impact from the additional
swap_dataflag. If there's none, your solution may be cleaner.
It was the maintenance impact of the extra code that motivated my suggestion. However, by avoiding kalloc we also avoid having to dereference the pointer in the fast path.
$subject meant to say v4, of course ...
Cheers,
Michael
Am 17.08.2023 um 15:49 schrieb Michael Schmitz:
Quoted 11 lines
v4 of the Q40 IDE patch, split into two parts. First patch just fixes the bug introduced when converting Q40 to use
pata_falcon, second patch adds the byte-swapping option requested by William.Please review this again, just to make sure I haven't messed up anything when applying the review comments to the split patches.
Cheers,
Michael
I'll test this evening and report back.
With a working pata_legacy possible, I would be happy to live without byte-swapping in pata_falcon.
Thanks
Will
Quoted 11 lines · Michael Schmitz
v4 of the Q40 IDE patch, split into two parts. First patch just fixes the bug introduced when converting Q40 to use
pata_falcon, second patch adds the byte-swapping option requested by William.Please review this again, just to make sure I haven't messed up anything when applying the review comments to the split patches.
Cheers,
Michael
_________________________________________________________________________
William R Sowerbutts [email protected]
"Carpe post meridiem" http://sowerbutts.com
main(){char*s=">#=0> ^#X@#@^7=",c=0,m;for(;c<15;c++)for
(m=-1;m<7;putchar(m++/6&c%3/2?10:s[c]-31&1<<m?42:32));} Quoted 1 line · William R Sowerbutts
I'll test this evening and report back.
The patches work.
Thanks
Will
_________________________________________________________________________
William R Sowerbutts [email protected]
"Carpe post meridiem" http://sowerbutts.com
main(){char*s=">#=0> ^#X@#@^7=",c=0,m;for(;c<15;c++)for
(m=-1;m<7;putchar(m++/6&c%3/2?10:s[c]-31&1<<m?42:32));} Hi William,
Quoted 3 lines · William R Sowerbutts
Quoted 1 line · William R Sowerbutts
I'll test this evening and report back.
The patches work.
Thanks for testing - I'll get this series off to linux-ide now.
Cheers,
Michael
Quoted 11 lines
Thanks
Will
_________________________________________________________________________
William R Sowerbutts [email protected]
"Carpe post meridiem" http://sowerbutts.commain(){char*s=">#=0> ^#X@#@^7=",c=0,m;for(;c<15;c++)for (m=-1;m<7;putchar(m++/6&c%3/2?10:s[c]-31&1<<m?42:32));}