diff mbox series

[v5,2/2] ata: pata_falcon: add data_swab option to byte-swap disk data

Message ID 20230825011335.25808-3-schmitzmic@gmail.com
State New
Headers show
Series Q40 IDE fixes | expand

Commit Message

Michael Schmitz Aug. 25, 2023, 1:13 a.m. UTC
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 <will@sowerbutts.com>
Cc: Finn Thain <fthain@linux-m68k.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: William R Sowerbutts <will@sowerbutts.com>
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

---

Changes since v4:

Damien Le Moal:
- spell out bitmask shift calculation

Changes since v2:

Geert Uytterhoeven:
- only shift swap bitmask if pdev->id > 0

Finn Thain:
- use pdev->devno directly for byte swap check

Changes since v1:

Damien Le Moal:
- change patch title
- drop swap_data flag

Finn Thain:
- drop allocation of ap->private struct, use field as bitmask

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 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Geert Uytterhoeven Aug. 25, 2023, 7:46 a.m. UTC | #1
Hi Michael,

On Fri, Aug 25, 2023 at 3:13 AM Michael Schmitz <schmitzmic@gmail.com> wrote:
> 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 <will@sowerbutts.com>
> Cc: Finn Thain <fthain@linux-m68k.org>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Tested-by: William R Sowerbutts <will@sowerbutts.com>
> Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
>
> ---
>
> Changes since v4:
>
> Damien Le Moal:
> - spell out bitmask shift calculation

Thanks for the update!

Sorry to bother you again...

> --- a/drivers/ata/pata_falcon.c
> +++ b/drivers/ata/pata_falcon.c

> @@ -124,7 +129,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
>         struct ata_host *host;
>         struct ata_port *ap;
>         void __iomem *base, *ctl_base;
> -       int irq = 0, io_offset = 1, reg_shift = 2; /* Falcon defaults */
> +       int irq = 0, io_offset = 1, reg_shift = 2, mask_shift; /* Falcon defaults */

The comment does not apply to the mask_shift variable, unless you
pre-initialize it to 0...

>
>         dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
>
> @@ -194,6 +199,12 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
>         ata_port_desc(ap, "cmd %px ctl %px data %px",
>                       base, ctl_base, ap->ioaddr.data_addr);
>
> +       if (pdev->id > 0)
> +               mask_shift = 2;
> +       else
> +               mask_shift = 0;

... and drop the else.

> +       ap->private_data = (void *)(uintptr_t)(pata_falcon_swap_mask >> mask_shift);
> +
>         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
Michael Schmitz Aug. 26, 2023, 12:44 a.m. UTC | #2
Hi Geert,

Am 25.08.23 um 19:46 schrieb Geert Uytterhoeven:
> Hi Michael,
>
> On Fri, Aug 25, 2023 at 3:13 AM Michael Schmitz <schmitzmic@gmail.com> wrote:
>> 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 <will@sowerbutts.com>
>> Cc: Finn Thain <fthain@linux-m68k.org>
>> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
>> Tested-by: William R Sowerbutts <will@sowerbutts.com>
>> Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
>> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>> Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
>>
>> ---
>>
>> Changes since v4:
>>
>> Damien Le Moal:
>> - spell out bitmask shift calculation
> Thanks for the update!
>
> Sorry to bother you again...
>
>> --- a/drivers/ata/pata_falcon.c
>> +++ b/drivers/ata/pata_falcon.c
>> @@ -124,7 +129,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
>>         struct ata_host *host;
>>         struct ata_port *ap;
>>         void __iomem *base, *ctl_base;
>> -       int irq = 0, io_offset = 1, reg_shift = 2; /* Falcon defaults */
>> +       int irq = 0, io_offset = 1, reg_shift = 2, mask_shift; /* Falcon defaults */
> The comment does not apply to the mask_shift variable, unless you
> pre-initialize it to 0...

It does not apply to mask_shift even then - '0' is the default for the
first Q40 ISA adapter also, not just for Falcon.

I'll move mask_shift to its own line so the comment can be correct.

>
>>         dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
>>
>> @@ -194,6 +199,12 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
>>         ata_port_desc(ap, "cmd %px ctl %px data %px",
>>                       base, ctl_base, ap->ioaddr.data_addr);
>>
>> +       if (pdev->id > 0)
>> +               mask_shift = 2;
>> +       else
>> +               mask_shift = 0;
> ... and drop the else.

Damien did seem quite partial to that one, so I'll leave it.

Cheers,

    Michael

>
>> +       ap->private_data = (void *)(uintptr_t)(pata_falcon_swap_mask >> mask_shift);
>> +
>>         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
>
Damien Le Moal Aug. 26, 2023, 1:55 a.m. UTC | #3
On 8/26/23 09:44, Michael Schmitz wrote:
> Hi Geert,
> 
> Am 25.08.23 um 19:46 schrieb Geert Uytterhoeven:
>> Hi Michael,
>>
>> On Fri, Aug 25, 2023 at 3:13 AM Michael Schmitz <schmitzmic@gmail.com> wrote:
>>> 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 <will@sowerbutts.com>
>>> Cc: Finn Thain <fthain@linux-m68k.org>
>>> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
>>> Tested-by: William R Sowerbutts <will@sowerbutts.com>
>>> Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
>>> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>>> Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
>>>
>>> ---
>>>
>>> Changes since v4:
>>>
>>> Damien Le Moal:
>>> - spell out bitmask shift calculation
>> Thanks for the update!
>>
>> Sorry to bother you again...
>>
>>> --- a/drivers/ata/pata_falcon.c
>>> +++ b/drivers/ata/pata_falcon.c
>>> @@ -124,7 +129,7 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
>>>         struct ata_host *host;
>>>         struct ata_port *ap;
>>>         void __iomem *base, *ctl_base;
>>> -       int irq = 0, io_offset = 1, reg_shift = 2; /* Falcon defaults */
>>> +       int irq = 0, io_offset = 1, reg_shift = 2, mask_shift; /* Falcon defaults */
>> The comment does not apply to the mask_shift variable, unless you
>> pre-initialize it to 0...
> 
> It does not apply to mask_shift even then - '0' is the default for the
> first Q40 ISA adapter also, not just for Falcon.
> 
> I'll move mask_shift to its own line so the comment can be correct.
> 
>>
>>>         dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
>>>
>>> @@ -194,6 +199,12 @@ static int __init pata_falcon_init_one(struct platform_device *pdev)
>>>         ata_port_desc(ap, "cmd %px ctl %px data %px",
>>>                       base, ctl_base, ap->ioaddr.data_addr);
>>>
>>> +       if (pdev->id > 0)
>>> +               mask_shift = 2;
>>> +       else
>>> +               mask_shift = 0;
>> ... and drop the else.
> 
> Damien did seem quite partial to that one, so I'll leave it.

I am OK with mask_shift initialized to 0 when declared.
So whichever you prefer is fine.
What I do not like is the use of "?" instead of the easier to read plain "if" :)

> 
> Cheers,
> 
>     Michael
> 
>>
>>> +       ap->private_data = (void *)(uintptr_t)(pata_falcon_swap_mask >> mask_shift);
>>> +
>>>         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
>>
>
diff mbox series

Patch

diff --git a/drivers/ata/pata_falcon.c b/drivers/ata/pata_falcon.c
index 616064b02de6..8da044fa1825 100644
--- a/drivers/ata/pata_falcon.c
+++ b/drivers/ata/pata_falcon.c
@@ -33,6 +33,11 @@ 
 #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)");
+
 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 = (uintptr_t)ap->private_data & BIT(dev->devno);
 
 	/* Transfer multiple of 2 bytes */
 	if (rw == READ) {
@@ -124,7 +129,7 @@  static int __init pata_falcon_init_one(struct platform_device *pdev)
 	struct ata_host *host;
 	struct ata_port *ap;
 	void __iomem *base, *ctl_base;
-	int irq = 0, io_offset = 1, reg_shift = 2; /* Falcon defaults */
+	int irq = 0, io_offset = 1, reg_shift = 2, mask_shift; /* Falcon defaults */
 
 	dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
 
@@ -194,6 +199,12 @@  static int __init pata_falcon_init_one(struct platform_device *pdev)
 	ata_port_desc(ap, "cmd %px ctl %px data %px",
 		      base, ctl_base, ap->ioaddr.data_addr);
 
+	if (pdev->id > 0)
+		mask_shift = 2;
+	else
+		mask_shift = 0;
+	ap->private_data = (void *)(uintptr_t)(pata_falcon_swap_mask >> mask_shift);
+
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (irq_res && irq_res->start > 0) {
 		irq = irq_res->start;