public inbox for linux-m68k@lists.linux-m68k.org
 help / color / mirror / Atom feed
From: Michael Schmitz <schmitzmic@gmail.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
	Finn Thain <fthain@linux-m68k.org>
Cc: will@sowerbutts.com, linux-m68k@vger.kernel.org, rz@linux-m68k.org
Subject: Re: [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data
Date: Fri, 18 Aug 2023 07:21:56 +1200	[thread overview]
Message-ID: <8bf4980e-f269-48d2-5b77-3fd6c7270bef@gmail.com> (raw)
In-Reply-To: <CAMuHMdV6NWRKL8DAD2e4HPz=fbcAUqi6ww-8_9Mjg0t8eiZCGQ@mail.gmail.com>

Hi Geert,

On 17/08/23 23:47, Geert Uytterhoeven wrote:
> On Thu, Aug 17, 2023 at 12:15 PM Finn Thain <fthain@linux-m68k.org> wrote:
>> On Thu, 17 Aug 2023, Michael Schmitz wrote:
>>> Some 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.
>> Many would say that's off by one, as it's popular to number the LSB as bit
>> zero.
>>
>>> 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>
>>> Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
>>> --- a/drivers/ata/pata_falcon.c
>>> +++ b/drivers/ata/pata_falcon.c
>>> @@ -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;
> 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.
>
>>> +             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


>
>> --- 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_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);
> "(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}()....
>
>>          /* 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.
>
>> +
>>          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
>

  reply	other threads:[~2023-08-17 19:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17  3:49 [PATCH RFC v3 0/2] Q40 IDE fixes Michael Schmitz
2023-08-17  3:50 ` [PATCH RFC v3 1/2] m68k/q40: fix IO base selection for Q40 in pata_falcon.c Michael Schmitz
2023-08-17  3:50 ` [PATCH RFC v3 2/2] m68k/q40: add data_swab option for pata_falcon to byte-swap disk data Michael Schmitz
2023-08-17 10:15   ` Finn Thain
2023-08-17 11:47     ` Geert Uytterhoeven
2023-08-17 19:21       ` Michael Schmitz [this message]
2023-08-17 21:28         ` Michael Schmitz
2023-08-18 14:33           ` Geert Uytterhoeven
2023-08-18 23:53             ` Finn Thain
2023-08-21  7:46               ` Geert Uytterhoeven
2023-08-21 11:08                 ` Finn Thain
2023-08-21 20:36                   ` Michael Schmitz
2023-08-21 23:18                     ` Finn Thain
     [not found]     ` <F32F62FE-2A74-4648-8BF1-0D1A1E76309B@linux-m68k.org>
2023-08-17 19:07       ` Michael Schmitz
2023-08-17 19:14     ` Michael Schmitz
2023-08-18  0:36       ` Finn Thain
2023-08-17  3:56 ` [PATCH RFC v3 0/2] Q40 IDE fixes Michael Schmitz
2023-08-17  9:20 ` William R Sowerbutts
2023-08-17 20:25   ` William R Sowerbutts
2023-08-17 21:29     ` Michael Schmitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bf4980e-f269-48d2-5b77-3fd6c7270bef@gmail.com \
    --to=schmitzmic@gmail.com \
    --cc=fthain@linux-m68k.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-m68k@vger.kernel.org \
    --cc=rz@linux-m68k.org \
    --cc=will@sowerbutts.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox