m68k: pata_cswarp: Add Amiga cslab ata support
Subsystems (2)
v5 cover m68k: pata_cswarp: Add Amiga cslab ata support
Here is a driver (and the subsequent defconfig change) for the pata/CF socket in the CS-Lab Warp series of Amiga boards.
This is a respin of v4 addressing Geert's review - apologies for the long delay.
Tested on real Warp hardware.
v4: https://lore.kernel.org/linux-ide/[email protected]/
Changes in v5:
- return the number of bytes actually consumed on the bus
- fix the trailing byte in pata_cswarp_data_xfer()
- drop a blank line in Kconfig
- fix the remaining checkpatch complaints
Changes in v4:
- refactor pata_cswarp_data_xfer()
- ioremap WARP_OFFSET_ATA region
Changes in v3:
- suppress a comment
- properly return ata_host_activate() error code
Change in v2:
- fix style, remove duplicate swap macro, driver version, etc
- rework the zorro attach mechanism
- remove the unnecessary zorro ids refactor
Paolo Pisati (2):
ata: pata_cswarp: Add Amiga cslab ata support
m68k: defconfig: enable PATA_CSWARP
arch/m68k/configs/amiga_defconfig | 1 + arch/m68k/configs/multi_defconfig | 1 + drivers/ata/Kconfig | 10 ++ drivers/ata/Makefile | 1 + drivers/ata/pata_cswarp.c | 180 ++++++++++++++++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 drivers/ata/pata_cswarp.c
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
Signature · 1 line
2.43.0
PATCH v5 1/2 ata: pata_cswarp: Add Amiga cslab ata support
Driver for the on-board IDE interface on CS-Lab Warp Expansion Card (NOTE that idemode=native has to be set in Warp Configuration)
--- drivers/ata/Kconfig | 10 +++ drivers/ata/Makefile | 1 + drivers/ata/pata_cswarp.c | 180 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 drivers/ata/pata_cswarp.c
drivers/ata/Kconfig +10 -0
@@ -1040,6 +1040,16 @@ config PATA_GAYLE If unsure, say N. +config PATA_CSWARP + tristate "Amiga CS Warp PATA support" + depends on M68K && AMIGA && ZORRO + help + This option enables support for the on-board IDE interface on + CS-Lab Warp Expansion Card (NOTE that idemode=native has to be + set in Warp Configuration) + + If unsure, say N. + config PATA_BUDDHA tristate "Buddha/Catweasel/X-Surf PATA support" depends on ZORRO
drivers/ata/Makefile +1 -0
@@ -100,6 +100,7 @@ obj-$(CONFIG_PATA_WINBOND) += pata_sl82c105.o obj-$(CONFIG_PATA_CMD640_PCI) += pata_cmd640.o obj-$(CONFIG_PATA_FALCON) += pata_falcon.o obj-$(CONFIG_PATA_GAYLE) += pata_gayle.o +obj-$(CONFIG_PATA_CSWARP) += pata_cswarp.o obj-$(CONFIG_PATA_BUDDHA) += pata_buddha.o obj-$(CONFIG_PATA_ISAPNP) += pata_isapnp.o obj-$(CONFIG_PATA_IXP4XX_CF) += pata_ixp4xx_cf.o
drivers/ata/pata_cswarp.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v5 1/2] ata: pata_cswarp: Add Amiga cslab ata support
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Missing NULL check for ioremap() return value. - [Medium] Resource leak of I/O mapping on probe…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing NULL check for ioremap() return value.
- [Medium] Resource leak of I/O mapping on probe error path.
--
--- Patch [1]: [PATCH v5 1/2] ata: pata_cswarp: Add Amiga cslab ata support ---
Note: The format of this report is altered due to recitation restrictions. I will not quote the original patch code directly, but will instead provide a free-form summary of the findings.
commit 50c3007b9ddccb0c0a488126c545810ad538a593
Author: Paolo Pisati <[email protected]>
ata: pata_cswarp: Add Amiga cslab ata support
This commit adds support for the on-board IDE interface on the CS-Lab Warp Expansion Card. It introduces the pata_cswarp driver handling initialization, data transfer, and configuration for PIO mode.
[Severity: High]
In drivers/ata/pata_cswarp.c:pata_cswarp_probe(), the code calls ioremap() but does not check the return value before using it.
Could ioremap() return NULL under memory pressure or if the vmalloc area is exhausted? If so, using the returned base pointer without validation to calculate static offsets (such as base + 1 * 4) and assigning them to the ATA port's IO address structure might lead to an immediate kernel oops or exception vector table corruption on m68k systems. Should there be a NULL check immediately after the ioremap() call?
[Severity: Medium]
In drivers/ata/pata_cswarp.c:pata_cswarp_probe(), there is a potential resource leak on the error path for ata_host_activate().
If the call to ata_host_activate() fails and returns an error code, the function exits directly by returning that error. Because the base pointer was mapped manually with ioremap() rather than a managed API like devm_ioremap(), does this leave the I/O mapping permanently leaked? There appears to be no explicit iounmap(base) in this specific error path to clean up the mapping.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Geert Uytterhoeven
maintainerRe: [PATCH v5 1/2] ata: pata_cswarp: Add Amiga cslab ata support
In reply to Paolo PisatiHi Paolo,
Quoted 5 lines · Paolo Pisati
Driver for the on-board IDE interface on CS-Lab Warp Expansion Card (NOTE that idemode=native has to be set in Warp Configuration)
Assisted-by Claude_Code:claude-opus-5Signed-off-by Paolo Pisati <[email protected]>
Thanks for the update!
Quoted 19 lines
drivers/ata/pata_cswarp.c new file +16
-0+static unsigned int pata_cswarp_data_xfer (struct ata_queued_cmd *qc, +unsigned char *buf, +unsigned int buflen,int rw) +{ +struct ata_device *dev = qc->dev; +struct ata_port *ap = dev->link->ap; +void __iomem *data_addr = ap->ioaddr.data_addr; +unsigned int words = buflen >>1 ; +u16 *buf16 = (u16 *)buf; + +/* Transfer multiple of 2 bytes */ +if (rw ==READ ) +raw_insw (data_addr, buf16, words); +else +raw_outsw (data_addr, buf16, words); +
drivers/ata/pata_cswarp.c line 65
Quoted 10 lines
drivers/ata/pata_cswarp.c new file +10
-0+/* Transfer trailing byte, if any. */ +if (unlikely (buflen &0x01 )) { +if (rw ==READ ) + buf[buflen -1 ] =raw_inw (data_addr) >>8 ; +else +raw_outw (buf[buflen -1 ] <<8 , data_addr); + words++; + } + +return words <<1 ;
This may be one less than the actual number of bytes Why not buflen?
Quoted 37 lines
drivers/ata/pata_cswarp.c new file +36
-0+} +static int pata_cswarp_probe (struct zorro_dev *z, +const struct zorro_device_id *ent) +{ +static const char board_name[] ="csWarp" ; +struct ata_host *host; +struct ata_port *ap; +void __iomem *base; +unsigned long board = z->resource.start; + +dev_info (&z->dev,"%s IDE controller (board: 0x%lx)\n" , board_name, + board); + +if (!devm_request_mem_region (&z->dev, board +WARP_OFFSET_ATA ,0x1800 , +DRV_NAME )) +return -ENXIO ; + + host =ata_host_alloc (&z->dev,1 ); +if (!host) +return -ENXIO ; + + ap = host->ports[0 ]; + base =ioremap (board +WARP_OFFSET_ATA ,0x1800 ); + + ap->ops = &pata_cswarp_ops; + + ap->pio_mask =ATA_PIO4 ; + ap->flags |=ATA_FLAG_SLAVE_POSS |ATA_FLAG_NO_IORDY | +ATA_FLAG_PIO_POLLING ; + + ap->ioaddr.data_addr = base; + ap->ioaddr.error_addr = base +1 *4 ; + ap->ioaddr.feature_addr = base +1 *4 ; + ap->ioaddr.nsect_addr = base +2 *4 ; + ap->ioaddr.lbal_addr = base +3 *4 ; + ap->ioaddr.lbam_addr = base +4 *4 ;
drivers/ata/pata_cswarp.c line 138
Quoted 10 lines
drivers/ata/pata_cswarp.c new file +10
-0+ ap->ioaddr.lbah_addr = base +5 *4 ; + ap->ioaddr.device_addr = base +6 *4 ; + ap->ioaddr.status_addr = base +7 *4 ; + ap->ioaddr.command_addr = base +7 *4 ; + + ap->ioaddr.altstatus_addr = base + (0x1000 | (6UL <<2 )); + ap->ioaddr.ctl_addr = base + (0x1000 | (6UL <<2 )); + +ata_port_desc (ap," cmd 0x%lx ctl 0x%lx" , (unsigned long )base, + (unsigned long )ap->ioaddr.ctl_addr);
Both printed addresses are virtual addresses hence not really useful. If you want to print something, please print board or z->resource instead.
drivers/ata/pata_cswarp.c line 154
Quoted 3 lines
drivers/ata/pata_cswarp.c new file +3
-0+static const struct zorro_device_id pata_cswarp_zorro_tbl[] = { + {ZORRO_PROD_CSLAB_WARP_1260 ,0 }, + {0 }
Please use named initializers, and drop unneeded zeroes, like Uwe just did in all existing Zorro drivers:
{ .id = ZORRO_PROD_CSLAB_WARP_1260 },
{ }Quoted 1 line
+};
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
Geert Uytterhoeven
maintainerRe: [PATCH v5 1/2] ata: pata_cswarp: Add Amiga cslab ata support
Hi Paolo,
Quoted 4 lines · Geert Uytterhoeven
Quoted 3 lines · Paolo Pisati
Driver for the on-board IDE interface on CS-Lab Warp Expansion Card (NOTE that idemode=native has to be set in Warp Configuration)
Quoted 8 lines
drivers/ata/pata_cswarp.c line 153
Quoted 8 lines
Assisted-by Claude_Code:claude-opus-5Signed-off-by Paolo Pisati <[email protected]>drivers/ata/pata_cswarp.c new file +2
-0+static const struct zorro_device_id pata_cswarp_zorro_tbl[] = { + {ZORRO_PROD_CSLAB_WARP_1260 ,0 },
FTR, this doesn't build anymore.
You also should include <linux/device-id/zorro.h>.
Quoted 7 lines
Quoted 1 line
+ { 0 }
Please use named initializers, and drop unneeded zeroes, like Uwe just did in all existing Zorro drivers:
{ .id = ZORRO_PROD_CSLAB_WARP_1260 }, { }
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 v5 1/2] ata: pata_cswarp: Add Amiga cslab ata support
In reply to Geert UytterhoevenQuoted 21 lines · Geert Uytterhoeven
Quoted 21 lines
drivers/ata/pata_cswarp.c new file +21
-0+static unsigned int pata_cswarp_data_xfer (struct ata_queued_cmd *qc, +unsigned char *buf, +unsigned int buflen,int rw) +{ +struct ata_device *dev = qc->dev; +struct ata_port *ap = dev->link->ap; +void __iomem *data_addr = ap->ioaddr.data_addr; +unsigned int words = buflen >>1 ; +u16 *buf16 = (u16 *)buf; + +/* Transfer multiple of 2 bytes */ +if (rw ==READ ) +raw_insw (data_addr, buf16, words); +else +raw_outsw (data_addr, buf16, words); + +/* Transfer trailing byte, if any. */ +if (unlikely (buflen &0x01 )) { +if (rw ==READ ) + buf[buflen -1 ] =raw_inw (data_addr) >>8 ; +else
Quoted 8 lines
drivers/ata/pata_cswarp.c line 65
Quoted 5 lines
drivers/ata/pata_cswarp.c new file +5
-0+raw_outw (buf[buflen -1 ] <<8 , data_addr); + words++; + } + +return words <<1 ;This may be one less than the actual number of bytes Why not buflen?
Cause every other driver (e.g. buddha, falcon, gayle, etc) is actually returning words << 1: i think we are returning the "whole number of bytes" read from the bus/ATA register here, or at least that's how i understood it.
Anyhow, thanks for the review, i'll send a V6 addressing all comments.
Signature · 2 lines
bye, p.
Re: [PATCH v5 1/2] ata: pata_cswarp: Add Amiga cslab ata support
In reply to Geert UytterhoevenHi Geert,
Quoted 20 lines · Geert Uytterhoeven
Quoted 20 lines
drivers/ata/pata_cswarp.c new file +20
-0+static unsigned int pata_cswarp_data_xfer (struct ata_queued_cmd *qc, +unsigned char *buf, +unsigned int buflen,int rw) +{ +struct ata_device *dev = qc->dev; +struct ata_port *ap = dev->link->ap; +void __iomem *data_addr = ap->ioaddr.data_addr; +unsigned int words = buflen >>1 ; +u16 *buf16 = (u16 *)buf; + +/* Transfer multiple of 2 bytes */ +if (rw ==READ ) +raw_insw (data_addr, buf16, words); +else +raw_outsw (data_addr, buf16, words); + +/* Transfer trailing byte, if any. */ +if (unlikely (buflen &0x01 )) { +if (rw ==READ ) + buf[buflen -1 ] =raw_inw (data_addr) >>8 ;
Quoted 9 lines
drivers/ata/pata_cswarp.c line 65
Quoted 6 lines
drivers/ata/pata_cswarp.c new file +6
-0+else +raw_outw (buf[buflen -1 ] <<8 , data_addr); + words++; + } + +return words <<1 ;This may be one less than the actual number of bytes Why not buflen?
words = buflen >> 1;
followed by
if (buflen & 0x01) words++;
makes 'words' the correct (i.e. rounded upwards if buflen was odd) number of words transferred.
The return value is then either correct, or one larger than the actual number of bytes?
I believe the template for these functions was drivers/ata/libata-sff.c:ata_sff_data_xfer() which follows the exact same logic.
Cheers,
MIchael
Quoted 64 lines
Quoted 36 lines
drivers/ata/pata_cswarp.c new file +36
-0+} +static int pata_cswarp_probe (struct zorro_dev *z, +const struct zorro_device_id *ent) +{ +static const char board_name[] ="csWarp" ; +struct ata_host *host; +struct ata_port *ap; +void __iomem *base; +unsigned long board = z->resource.start; + +dev_info (&z->dev,"%s IDE controller (board: 0x%lx)\n" , board_name, + board); + +if (!devm_request_mem_region (&z->dev, board +WARP_OFFSET_ATA ,0x1800 , +DRV_NAME )) +return -ENXIO ; + + host =ata_host_alloc (&z->dev,1 ); +if (!host) +return -ENXIO ; + + ap = host->ports[0 ]; + base =ioremap (board +WARP_OFFSET_ATA ,0x1800 ); + + ap->ops = &pata_cswarp_ops; + + ap->pio_mask =ATA_PIO4 ; + ap->flags |=ATA_FLAG_SLAVE_POSS |ATA_FLAG_NO_IORDY | +ATA_FLAG_PIO_POLLING ; + + ap->ioaddr.data_addr = base; + ap->ioaddr.error_addr = base +1 *4 ; + ap->ioaddr.feature_addr = base +1 *4 ; + ap->ioaddr.nsect_addr = base +2 *4 ; + ap->ioaddr.lbal_addr = base +3 *4 ; + ap->ioaddr.lbam_addr = base +4 *4 ;drivers/ata/pata_cswarp.c line 138
Quoted 10 lines
drivers/ata/pata_cswarp.c new file +10
-0+ ap->ioaddr.lbah_addr = base +5 *4 ; + ap->ioaddr.device_addr = base +6 *4 ; + ap->ioaddr.status_addr = base +7 *4 ; + ap->ioaddr.command_addr = base +7 *4 ; + + ap->ioaddr.altstatus_addr = base + (0x1000 | (6UL <<2 )); + ap->ioaddr.ctl_addr = base + (0x1000 | (6UL <<2 )); + +ata_port_desc (ap," cmd 0x%lx ctl 0x%lx" , (unsigned long )base, + (unsigned long )ap->ioaddr.ctl_addr);Both printed addresses are virtual addresses hence not really useful. If you want to print something, please print board or
z->resourceinstead.drivers/ata/pata_cswarp.c line 154
Quoted 3 lines
drivers/ata/pata_cswarp.c new file +3
-0+static const struct zorro_device_id pata_cswarp_zorro_tbl[] = { + {ZORRO_PROD_CSLAB_WARP_1260 ,0 }, + {0 }Please use named initializers, and drop unneeded zeroes, like Uwe just did in all existing Zorro drivers:
{ .id = ZORRO_PROD_CSLAB_WARP_1260 }, { }Quoted 1 line
+};
Gr{oetje,eeting}s,
Geert
Geert Uytterhoeven
maintainerRe: [PATCH v5 1/2] ata: pata_cswarp: Add Amiga cslab ata support
Hi Michael,
Quoted 30 lines · Michael Schmitz
Quoted 20 lines · Geert Uytterhoeven
Quoted 20 lines
drivers/ata/pata_cswarp.c new file +20
-0+static unsigned int pata_cswarp_data_xfer (struct ata_queued_cmd *qc, +unsigned char *buf, +unsigned int buflen,int rw) +{ +struct ata_device *dev = qc->dev; +struct ata_port *ap = dev->link->ap; +void __iomem *data_addr = ap->ioaddr.data_addr; +unsigned int words = buflen >>1 ; +u16 *buf16 = (u16 *)buf; + +/* Transfer multiple of 2 bytes */ +if (rw ==READ ) +raw_insw (data_addr, buf16, words); +else +raw_outsw (data_addr, buf16, words); + +/* Transfer trailing byte, if any. */ +if (unlikely (buflen &0x01 )) { +if (rw ==READ ) + buf[buflen -1 ] =raw_inw (data_addr) >>8 ;Quoted 9 lines
drivers/ata/pata_cswarp.c line 65
Quoted 6 lines
drivers/ata/pata_cswarp.c new file +6
-0+else +raw_outw (buf[buflen -1 ] <<8 , data_addr); + words++; + } + +return words <<1 ;This may be one less than the actual number of bytes Why not buflen?
Quoted 8 lines
words = buflen >> 1;
followed by
if (buflen &
0x01) words++;makes 'words' the correct (i.e. rounded upwards if buflen was odd) number of words transferred.
Thanks, I had completely missed that increment.
Quoted 6 lines
The return value is then either correct, or one larger than the actual number of bytes?
I believe the template for these functions was drivers/ata/libata-sff.c:ata_sff_data_xfer() which follows the exact same logic.
Then Life's Good ;-)
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
PATCH v5 2/2 m68k: defconfig: enable PATA_CSWARP
In reply to Paolo PisatiEnable the new CS-Lab Warp PATA driver in the Amiga and multi defconfigs.
--- arch/m68k/configs/amiga_defconfig | 1 + arch/m68k/configs/multi_defconfig | 1 + 2 files changed, 2 insertions(+)
arch/m68k/configs/amiga_defconfig +1 -0
@@ -284,6 +284,7 @@ CONFIG_ATA=y # CONFIG_ATA_VERBOSE_ERROR is not set # CONFIG_ATA_BMDMA is not set CONFIG_PATA_GAYLE=y +CONFIG_PATA_CSWARP=y CONFIG_PATA_BUDDHA=y CONFIG_MD=y CONFIG_MD_LINEAR=m
arch/m68k/configs/multi_defconfig +1 -0
@@ -310,6 +310,7 @@ CONFIG_ATA=y # CONFIG_ATA_BMDMA is not set CONFIG_PATA_FALCON=y CONFIG_PATA_GAYLE=y +CONFIG_PATA_CSWARP=y CONFIG_PATA_BUDDHA=y CONFIG_PATA_PLATFORM=y CONFIG_MD=y
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v5 2/2] m68k: defconfig: enable PATA_CSWARP
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Missing check for ioremap() failure in pata_cswarp_probe(). - [Medium] Missing iounmap() on the…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing check for ioremap() failure in pata_cswarp_probe().
- [Medium] Missing iounmap() on the ata_host_activate() error path.
--
--- Patch [2]: [PATCH v5 2/2] m68k: defconfig: enable PATA_CSWARP --- commit 50c3007b9ddccb0c0a488126c545810ad538a593
Author: Paolo Pisati <[email protected]>
ata: pata_cswarp: Add Amiga cslab ata support
This commit introduces the pata_cswarp driver to provide support for the on-board IDE interface on the CS-Lab Warp Expansion Card.
Quoted 6 lines
drivers/ata/pata_cswarp.c new file +0
-0@@ -0,0 +1,180 @@
[ ... ]
Quoted 3 lines
drivers/ata/pata_cswarp.c new file +3
-0+static int pata_cswarp_probe (struct zorro_dev *z, +const struct zorro_device_id *ent) +{
[ ... ]
drivers/ata/pata_cswarp.c
Quoted 8 lines
drivers/ata/pata_cswarp.c new file +8
-0+ host =ata_host_alloc (&z->dev,1 ); +if (!host) +return -ENXIO ; + + ap = host->ports[0 ]; + base =ioremap (board +WARP_OFFSET_ATA ,0x1800 ); + + ap->ops = &pata_cswarp_ops;
[Severity: High]
Is it possible for ioremap() to fail and return a NULL pointer here?
If memory mapping fails during device probe, base would be NULL.
This NULL pointer is then used to calculate and assign various ATA port I/O addresses (e.g., ap->ioaddr.error_addr = base + 1 * 4).
When the block layer or ATA framework later attempts to access these I/O ports, will this result in a kernel panic due to an invalid pointer dereference?
Quoted 2 lines
drivers/ata/pata_cswarp.c new file +2
-0+ + ap->pio_mask =ATA_PIO4 ;
[ ... ]
drivers/ata/pata_cswarp.c
Quoted 6 lines
drivers/ata/pata_cswarp.c new file +6
-0+ata_port_desc (ap," cmd 0x%lx ctl 0x%lx" , (unsigned long )base, + (unsigned long )ap->ioaddr.ctl_addr); + +return ata_host_activate (host,0 ,NULL , +IRQF_SHARED , &pata_cswarp_sht); +}
[Severity: Medium]
Does this error path leak the I/O memory mapping?
If ata_host_activate() fails, it returns a non-zero error code which is immediately returned by pata_cswarp_probe().
Since this driver uses manual memory mapping rather than devm_ioremap() (as seen by the manual iounmap() call in pata_cswarp_remove()), should iounmap(base) be called before returning the error?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2