Skip to contentSkip to conversation

pata_parport: paride replacement

RFC PATCH In review Ondrej Zary 5 participants 27 messages Mar 5, 2022 – Mar 9, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 pata_parport: paride replacement

Hello,
this is a RFC patch for the new pata_parport libata driver - a paride replacement.

Protocol driver registration and device creation was changed since the second preview - no more protocol numbers or parport I/O addresses.

All parports and all protocol drivers are now probed automatically unless probe=0 parameter is used. So just "modprobe epat" is enough for a Imation SuperDisk drive to work.

Manual device creation:
echo auto >/sys/bus/pata_parport/new_device echo "parport0 epat 4" >/sys/bus/pata_parport/new_device echo "parport0 auto" >/sys/bus/pata_parport/new_device echo "auto epat" >/sys/bus/pata_parport/new_device

Deleting devices:
echo pata_parport.0 >/sys/bus/pata_parport/delete_device

Haven't found any sane way to hook pi_connect() and pi_disconnect() to libata. So pi_connect() is called on every protocol driver access and pi_disconnect() is called by a timer that's activated after protocol driver access.

Found that the EPP-32 mode is buggy in EPAT - and also in many (all?) other protocol drivers - they don't handle non-multiple-of-4 block transfers correctly. I'll fix that later.

The bpck_connect() in bpck driver seems to need to know if a CD drive is attached (weird) but it's called before device detection. This probably cannot be fixed without the HW.

I have only two devices and both have the same EPAT chip, unfortunately:
Imation SupserDisk
HP C4381A (drive was dead, replaced by TOSHIBA CD-ROM XM-6202B)

The both work:

# modprobe epat
[  122.635395] pata_parport: protocol epat registered
[  122.738114] epat pata_parport.0: epat, Shuttle EPAT chip c6 at 0x378, mode 5 (EPP-32), delay 1
[  122.789035] scsi host4: pata_parport-epat
[  122.789226] ata5: PATA max PIO0 port parport0 protocol epat
[  127.831534] ata5: link is slow to respond, please be patient (ready=0)
[  132.811623] ata5: device not ready (errno=-16), forcing hardreset
[  133.015024] ata5.00: ATAPI: TOSHIBA CD-ROM XM-6202B, 1108, max MWDMA2
[  133.023016] scsi 4:0:0:0: CD-ROM            TOSHIBA  CD-ROM XM-6202B  1108 PQ: 0 ANSI: 5
[  133.043817] scsi 4:0:0:0: Attached scsi generic sg1 type 5
[  133.088146] sr 4:0:0:0: [sr0] scsi3-mmc drive: 32x/32x cd/rw xa/form2 cdda tray
[  133.088163] cdrom: Uniform CD-ROM driver Revision: 3.20
[  133.125939] sr 4:0:0:0: Attached scsi CD-ROM sr0
# mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
[  157.922575] ISO 9660 Extensions: Microsoft Joliet Level 3
[  157.991030] ISO 9660 Extensions: RRIP_1991A
# hdparm -t --direct /dev/sr0

/dev/sr0:
Timing O_DIRECT disk reads: 2 MB in 3.08 seconds = 664.47 kB/sec

# modprobe epat
[  448.160910] pata_parport: protocol epat registered
[  448.267068] epat pata_parport.0: epat, Shuttle EPAT chip c6 at 0x378, mode 5 (EPP-32), delay 1
[  448.301624] scsi host4: pata_parport-epat
[  448.301769] ata6: PATA max PIO0 port parport0 protocol epat
[  448.533850] ata6.00: ATAPI: LS-120 COSM   04              UHD Floppy, 0270M09T, max PIO2
[  448.615500] scsi 4:0:0:0: Direct-Access     MATSHITA LS-120 COSM   04 0270 PQ: 0 ANSI: 5
[  448.651279] sd 4:0:0:0: Attached scsi generic sg1 type 0
[  448.686028] sd 4:0:0:0: [sdb] Media removed, stopped polling
[  448.717879] sd 4:0:0:0: [sdb] Attached SCSI removable disk
[  472.259786] sd 4:0:0:0: [sdb] Read Capacity(16) failed: Result: hostbyte=DID_ERROR driverbyte=DRIVER_OK
[  472.259805] sd 4:0:0:0: [sdb] Sense not available.
[  483.042442] sd 4:0:0:0: [sdb] 246528 512-byte logical blocks: (126 MB/120 MiB)
[  483.158446] sdb: detected capacity change from 0 to 246528
[  483.309771]  sdb:
# hdparm -t --direct /dev/sdb

/dev/sdb:
Timing O_DIRECT disk reads: 2 MB in 44.19 seconds = 46.35 kB/sec

#1 lore raw

PATCH 1/16 pata_parport: add core driver (PARIDE replacement)

Add pata_parport (PARIDE replacement) core libata driver.

---
 drivers/ata/Kconfig                     |  25 +
 drivers/ata/Makefile                    |   2 +
 drivers/ata/pata_parport/Kconfig        |  10 +
 drivers/ata/pata_parport/Makefile       |   9 +
 drivers/ata/pata_parport/pata_parport.c | 809 ++++++++++++++++++++++++
 drivers/ata/pata_parport/pata_parport.h | 110 ++++
 6 files changed, 965 insertions(+)
 create mode 100644 drivers/ata/pata_parport/Kconfig
 create mode 100644 drivers/ata/pata_parport/Makefile
 create mode 100644 drivers/ata/pata_parport/pata_parport.c
 create mode 100644 drivers/ata/pata_parport/pata_parport.h
drivers/ata/Kconfig +25 -0
index cb54631fd950..de4548471398 100644
@@ -1161,6 +1161,31 @@ config PATA_WINBOND_VLB
 	  Support for the Winbond W83759A controller on Vesa Local Bus
 	  systems.
 
+config PATA_PARPORT
+	tristate "Parallel port IDE device support (PARIDE replacement)"
+	depends on PARPORT_PC
+	help
+	  There are many external CD-ROM and disk devices that connect through
+	  your computer's parallel port. Most of them are actually IDE devices
+	  using a parallel port IDE adapter. This option enables the PATA_PARPORT
+	  subsystem which contains drivers for many of these external drives.
+	  Read <file:Documentation/admin-guide/blockdev/paride.rst> for more information.
+
+	  If you have said Y to the "Parallel-port support" configuration
+	  option, you may share a single port between your printer and other
+	  parallel port devices. Answer Y to build PATA_PARPORT support into your
+	  kernel, or M if you would like to build it as a loadable module. If
+	  your parallel port support is in a loadable module, you must build
+	  PATA_PARPORT as a module. If you built PATA_PARPORT support into your kernel,
+	  you may still build the individual protocol modules as loadable
+	  modules. If you build this support as a module, it will be called pata_parport.
+
+	  Unlike the old PARIDE, there are no high-level drivers needed.
+	  The IDE devices behind parallel port adapters are handled by the
+	  ATA layer.
+
+source "drivers/ata/pata_parport/Kconfig"
+
 comment "Generic fallback / legacy drivers"
 
 config PATA_ACPI
drivers/ata/Makefile +2 -0
index b8aebfb14e82..bd6b5fdc004e 100644
@@ -114,6 +114,8 @@ obj-$(CONFIG_PATA_SAMSUNG_CF)	+= pata_samsung_cf.o
 
 obj-$(CONFIG_PATA_PXA)		+= pata_pxa.o
 
+obj-$(CONFIG_PATA_PARPORT)	+= pata_parport/
+
 # Should be last but two libata driver
 obj-$(CONFIG_PATA_ACPI)		+= pata_acpi.o
 # Should be last but one libata driver
drivers/ata/pata_parport/Kconfig new file +10 -0
new file mode 100644
index 000000000000..56dc6b25d5fa
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# PATA_PARPORT configuration
+#
+# PATA_PARPORT doesn't need PARPORT, but if PARPORT is configured as a module,
+# PATA_PARPORT must also be a module.
+# PATA_PARPORT only supports PC style parports. Tough for USB or other parports...
+
+comment "Parallel IDE protocol modules"
+	depends on PATA_PARPORT
drivers/ata/pata_parport/Makefile new file +9 -0
new file mode 100644
index 000000000000..b105e1cb8dc6
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for Parallel port IDE device drivers.
+#
+# 7 October 2000, Bartlomiej Zolnierkiewicz <[email protected]>
+# Rewritten to use lists instead of if-statements.
+#
+
+obj-$(CONFIG_PATA_PARPORT)		+= pata_parport.o
drivers/ata/pata_parport/pata_parport.c new file +809 -0

809 lines not on this page · raw message

drivers/ata/pata_parport/pata_parport.h new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#2 lore raw

Re: [PATCH 01/16] pata_parport: add core driver (PARIDE replacement)

Quoted 21 lines · Ondrej Zary

Add pata_parport (PARIDE replacement) core libata driver.

---
 drivers/ata/Kconfig                     |  25 +
 drivers/ata/Makefile                    |   2 +
 drivers/ata/pata_parport/Kconfig        |  10 +
 drivers/ata/pata_parport/Makefile       |   9 +
 drivers/ata/pata_parport/pata_parport.c | 809 ++++++++++++++++++++++++
 drivers/ata/pata_parport/pata_parport.h | 110 ++++
 6 files changed, 965 insertions(+)
 create mode 100644 drivers/ata/pata_parport/Kconfig
 create mode 100644 drivers/ata/pata_parport/Makefile
 create mode 100644 drivers/ata/pata_parport/pata_parport.c
 create mode 100644 drivers/ata/pata_parport/pata_parport.h
drivers/ata/Kconfig +0 -0
index cb54631fd950..de4548471398 100644

drivers/ata/Kconfig config PATA_WINBOND_VLB · line 1165

Quoted 5 lines
drivers/ata/Kconfig +2 -0
@@ -1161,6 +1161,31 @@ config PATA_WINBOND_VLB
 	  Support for the Winbond W83759A controller on Vesa Local Bus
 	  systems.
 
+config PATA_PARPORT
+	tristate "Parallel port IDE device support (PARIDE replacement)"

I would remove the "(PARIDE replacement)" from the title. If really needed, mention it in the description that this support used to be implemented by PARIDE. But I do not think that is necessary. The last paragraph of the description implies that.

Quoted 10 lines
drivers/ata/Kconfig +10 -0
+	depends on PARPORT_PC
+	help
+	  There are many external CD-ROM and disk devices that connect through
+	  your computer's parallel port. Most of them are actually IDE devices
+	  using a parallel port IDE adapter. This option enables the PATA_PARPORT
+	  subsystem which contains drivers for many of these external drives.
+	  Read <file:Documentation/admin-guide/blockdev/paride.rst> for more information.
+
+	  If you have said Y to the "Parallel-port support" configuration
+	  option, you may share a single port between your printer and other

drivers/ata/Kconfig config PATA_WINBOND_VLB · line 1185

Quoted 10 lines
drivers/ata/Kconfig +10 -0
+	  parallel port devices. Answer Y to build PATA_PARPORT support into your
+	  kernel, or M if you would like to build it as a loadable module. If
+	  your parallel port support is in a loadable module, you must build
+	  PATA_PARPORT as a module. If you built PATA_PARPORT support into your kernel,
+	  you may still build the individual protocol modules as loadable
+	  modules. If you build this support as a module, it will be called pata_parport.
+
+	  Unlike the old PARIDE, there are no high-level drivers needed.
+	  The IDE devices behind parallel port adapters are handled by the
+	  ATA layer.

Several lines are too long. Rewrap please.

Quoted 25 lines
drivers/ata/Kconfig +3 -0
+
+source "drivers/ata/pata_parport/Kconfig"
+
 comment "Generic fallback / legacy drivers"
 
 config PATA_ACPI
drivers/ata/Makefile +2 -0
index b8aebfb14e82..bd6b5fdc004e 100644
@@ -114,6 +114,8 @@ obj-$(CONFIG_PATA_SAMSUNG_CF)	+= pata_samsung_cf.o
 
 obj-$(CONFIG_PATA_PXA)		+= pata_pxa.o
 
+obj-$(CONFIG_PATA_PARPORT)	+= pata_parport/
+
 # Should be last but two libata driver
 obj-$(CONFIG_PATA_ACPI)		+= pata_acpi.o
 # Should be last but one libata driver
drivers/ata/pata_parport/Kconfig new file +0 -0
new file mode 100644
index 000000000000..56dc6b25d5fa

drivers/ata/pata_parport/Kconfig line 6

Quoted 6 lines
drivers/ata/pata_parport/Kconfig new file +6 -0
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# PATA_PARPORT configuration
+#
+# PATA_PARPORT doesn't need PARPORT, but if PARPORT is configured as a module,
+# PATA_PARPORT must also be a module.

This does not parse. If PARPORT is not needed, then why does how PARPORT is compiled matter ? Something is not consistent here.

drivers/ata/pata_parport/Kconfig line 7

Quoted 1 line
drivers/ata/pata_parport/Kconfig new file +1 -0
+# PATA_PARPORT only supports PC style parports. Tough for USB or other parports...

The second sentence does not parse. What are you trying to say ?

Quoted 28 lines
drivers/ata/pata_parport/Kconfig new file +3 -0
+
+comment "Parallel IDE protocol modules"
+	depends on PATA_PARPORT
drivers/ata/pata_parport/Makefile new file +9 -0
new file mode 100644
index 000000000000..b105e1cb8dc6
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for Parallel port IDE device drivers.
+#
+# 7 October 2000, Bartlomiej Zolnierkiewicz <[email protected]>
+# Rewritten to use lists instead of if-statements.
+#
+
+obj-$(CONFIG_PATA_PARPORT)		+= pata_parport.o
drivers/ata/pata_parport/pata_parport.c new file +4 -0
new file mode 100644
index 000000000000..7f814062cedd
@@ -0,0 +1,809 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/parport.h>

drivers/ata/pata_parport/pata_parport.c line 14

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+#include "pata_parport.h"
+
+#define DRV_NAME "pata_parport"
+
+static DEFINE_IDR(parport_list);
+static DEFINE_IDR(protocols);
+static DEFINE_IDA(pata_parport_bus_dev_ids);
+static DEFINE_MUTEX(pi_mutex);
+
+static bool probe = 1;

s/1/true to match the type.

drivers/ata/pata_parport/pata_parport.c line 20

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+module_param(probe, bool, 0644);
+MODULE_PARM_DESC(probe, "Enable automatic device probing (0=off, 1=on [default])");
+
+static bool verbose;
+module_param(verbose, bool, 0644);
+MODULE_PARM_DESC(verbose, "Enable verbose messages (0=off [default], 1=on)");

Is this really necessary ? pr_debug() and all ata_xxx_debug() functions can be enabled dynamically.

drivers/ata/pata_parport/pata_parport.c line 28

Quoted 8 lines
drivers/ata/pata_parport/pata_parport.c new file +8 -0
+
+#define DISCONNECT_TIMEOUT	(HZ / 10)
+
+static void pi_connect(struct pi_adapter *pi)
+{
+	del_timer_sync(&pi->timer);
+	if (pi->claimed)
+		return;

Nit: I would reverse the condition to avoid the return. Or add a block line to separate the following hunk. Better readability this way, I think.

drivers/ata/pata_parport/pata_parport.c line 37

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.c new file +9 -0
+	pi->claimed = 1;
+	parport_claim_or_block(pi->pardev);
+	pi->proto->connect(pi);
+}
+
+static void pi_disconnect_later(struct pi_adapter *pi)
+{
+	mod_timer(&pi->timer, jiffies + DISCONNECT_TIMEOUT);
+}

Is this really needed ? Not sure it helps in any way. At least the name should be changed to reflect what this does. May be something like pi_start_disconnect_timeout() ?

drivers/ata/pata_parport/pata_parport.c line 44

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+
+static void pi_disconnect_timer(struct timer_list *t)
+{
+	struct pi_adapter *pi = from_timer(pi, t, timer);
+
+	if (!pi->claimed)
+		return;

A blank line here would be nice for readability.

drivers/ata/pata_parport/pata_parport.c line 51

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+	pi->proto->disconnect(pi);
+	parport_release(pi->pardev);
+	pi->claimed = 0;
+}
+
+/* functions taken from libata-sff.c and converted from direct port I/O */
+static unsigned int pata_parport_devchk(struct ata_port *ap, unsigned int device)

Should this be a bool function ?

Quoted 25 lines
drivers/ata/pata_parport/pata_parport.c new file +25 -0
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	u8 nsect, lbal;
+
+	ap->ops->sff_dev_select(ap, device);
+
+	pi_connect(pi);
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 0x55);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0xaa);
+
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 0xaa);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0x55);
+
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 055);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0xaa);
+
+	nsect = pi->proto->read_regr(pi, 0, ATA_REG_NSECT);
+	lbal = pi->proto->read_regr(pi, 0, ATA_REG_LBAL);
+	pi_disconnect_later(pi);
+
+	if ((nsect == 0x55) && (lbal == 0xaa))
+		return 1;	/* we found a device */
+
+	return 0;		/* nothing found */
+}

drivers/ata/pata_parport/pata_parport.c line 86

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+
+static int pata_parport_bus_softreset(struct ata_port *ap, unsigned int devmask,
+				      unsigned long deadline)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	/* software reset.  causes dev0 to be selected */
+	pi->proto->write_regr(pi, 1, 6, ap->ctl);
+	udelay(20);	/* FIXME: flush */

Then please fix it.

drivers/ata/pata_parport/pata_parport.c line 88

Quoted 2 lines
drivers/ata/pata_parport/pata_parport.c new file +2 -0
+	pi->proto->write_regr(pi, 1, 6, ap->ctl | ATA_SRST);
+	udelay(20);	/* FIXME: flush */

Here too.

Quoted 19 lines
drivers/ata/pata_parport/pata_parport.c new file +19 -0
+	pi->proto->write_regr(pi, 1, 6, ap->ctl);
+	ap->last_ctl = ap->ctl;
+	pi_disconnect_later(pi);
+
+	/* wait the port to become ready */
+	return ata_sff_wait_after_reset(&ap->link, devmask, deadline);
+}
+
+static int pata_parport_softreset(struct ata_link *link, unsigned int *classes,
+				  unsigned long deadline)
+{
+	struct ata_port *ap = link->ap;
+	unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
+	unsigned int devmask = 0;
+	int rc;
+	u8 err;
+
+	/* determine if device 0/1 are present */
+	if (pata_parport_devchk(ap, 0))

drivers/ata/pata_parport/pata_parport.c line 117

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+		devmask |= (1 << 0);
+	if (slave_possible && pata_parport_devchk(ap, 1))
+		devmask |= (1 << 1);
+
+	/* select device 0 again */
+	ap->ops->sff_dev_select(ap, 0);
+
+	/* issue bus reset */
+	rc = pata_parport_bus_softreset(ap, devmask, deadline);
+	/* if link is occupied, -ENODEV too is an error */

Please merge this comment with the one above. That will make the code more readable (I know this is the style used by many drivers, but let's not repeat the weird style :)).

Quoted 43 lines
drivers/ata/pata_parport/pata_parport.c new file +43 -0
+	if (rc && (rc != -ENODEV || sata_scr_valid(link))) {
+		ata_link_err(link, "SRST failed (errno=%d)\n", rc);
+		return rc;
+	}
+
+	/* determine by signature whether we have ATA or ATAPI devices */
+	classes[0] = ata_sff_dev_classify(&link->device[0],
+					  devmask & (1 << 0), &err);
+	if (slave_possible && err != 0x81)
+		classes[1] = ata_sff_dev_classify(&link->device[1],
+						  devmask & (1 << 1), &err);
+
+	return 0;
+}
+
+static u8 pata_parport_check_status(struct ata_port *ap)
+{
+	u8 status;
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	status = pi->proto->read_regr(pi, 0, ATA_REG_STATUS);
+	pi_disconnect_later(pi);
+
+	return status;
+}
+
+static u8 pata_parport_check_altstatus(struct ata_port *ap)
+{
+	u8 altstatus;
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	altstatus = pi->proto->read_regr(pi, 1, 6);
+	pi_disconnect_later(pi);
+
+	return altstatus;
+}
+
+static void pata_parport_dev_select(struct ata_port *ap, unsigned int device)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	u8 tmp;

drivers/ata/pata_parport/pata_parport.c line 170

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+
+	pi_connect(pi);
+	if (device == 0)
+		tmp = ATA_DEVICE_OBS;
+	else
+		tmp = ATA_DEVICE_OBS | ATA_DEV1;
+
+	pi->proto->write_regr(pi, 0, ATA_REG_DEVICE, tmp);
+	pi_disconnect_later(pi);
+	ata_sff_pause(ap);	/* needed; also flushes, for mmio */

The comment does not parse... Why is it needed ?
And pleasde move the comment above the call, with a blank line separating it from the previous lines.

Quoted 13 lines
drivers/ata/pata_parport/pata_parport.c new file +13 -0
+}
+
+static void pata_parport_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
+
+	pi_connect(pi);
+	if (tf->ctl != ap->last_ctl) {
+		pi->proto->write_regr(pi, 1, 6, tf->ctl);
+		ap->last_ctl = tf->ctl;
+		ata_wait_idle(ap);
+	}

drivers/ata/pata_parport/pata_parport.c line 193

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+
+	if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
+		pi->proto->write_regr(pi, 0, ATA_REG_FEATURE, tf->hob_feature);
+		pi->proto->write_regr(pi, 0, ATA_REG_NSECT, tf->hob_nsect);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAL, tf->hob_lbal);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAM, tf->hob_lbam);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAH, tf->hob_lbah);
+	}
+
+	if (is_addr) {

Move this if above the previous one. Doing so, you can remove the need for is_addr var and simplify the previous if condition.

That said, many pata drivers check that flag but it is always set by libata core. So checking it seems useless. Need to dig into this.

Quoted 93 lines
drivers/ata/pata_parport/pata_parport.c new file +93 -0
+		pi->proto->write_regr(pi, 0, ATA_REG_FEATURE, tf->feature);
+		pi->proto->write_regr(pi, 0, ATA_REG_NSECT, tf->nsect);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAL, tf->lbal);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAM, tf->lbam);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAH, tf->lbah);
+	}
+
+	if (tf->flags & ATA_TFLAG_DEVICE)
+		pi->proto->write_regr(pi, 0, ATA_REG_DEVICE, tf->device);
+
+	ata_wait_idle(ap);
+	pi_disconnect_later(pi);
+}
+
+static void pata_parport_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	tf->command = pi->proto->read_regr(pi, 0, ATA_REG_STATUS);
+	tf->feature = pi->proto->read_regr(pi, 0, ATA_REG_ERR);
+	tf->nsect = pi->proto->read_regr(pi, 0, ATA_REG_NSECT);
+	tf->lbal = pi->proto->read_regr(pi, 0, ATA_REG_LBAL);
+	tf->lbam = pi->proto->read_regr(pi, 0, ATA_REG_LBAM);
+	tf->lbah = pi->proto->read_regr(pi, 0, ATA_REG_LBAH);
+	tf->device = pi->proto->read_regr(pi, 0, ATA_REG_DEVICE);
+
+	if (tf->flags & ATA_TFLAG_LBA48) {
+		pi->proto->write_regr(pi, 1, 6, tf->ctl | ATA_HOB);
+		tf->hob_feature = pi->proto->read_regr(pi, 0, ATA_REG_ERR);
+		tf->hob_nsect = pi->proto->read_regr(pi, 0, ATA_REG_NSECT);
+		tf->hob_lbal = pi->proto->read_regr(pi, 0, ATA_REG_LBAL);
+		tf->hob_lbam = pi->proto->read_regr(pi, 0, ATA_REG_LBAM);
+		tf->hob_lbah = pi->proto->read_regr(pi, 0, ATA_REG_LBAH);
+		pi->proto->write_regr(pi, 1, 6, tf->ctl);
+		ap->last_ctl = tf->ctl;
+	}
+	pi_disconnect_later(pi);
+}
+
+static void pata_parport_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	pi->proto->write_regr(pi, 0, ATA_REG_CMD, tf->command);
+	ata_sff_pause(ap);
+	pi_disconnect_later(pi);
+}
+
+static unsigned int pata_parport_data_xfer(struct ata_queued_cmd *qc, unsigned char *buf,
+					   unsigned int buflen, int rw)
+{
+	struct ata_port *ap = qc->dev->link->ap;
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	if (rw == READ)
+		pi->proto->read_block(pi, buf, buflen);
+	else
+		pi->proto->write_block(pi, buf, buflen);
+	pi_disconnect_later(pi);
+
+	return buflen;
+}
+
+static void pata_parport_drain_fifo(struct ata_queued_cmd *qc)
+{
+	int count;
+	struct ata_port *ap;
+	struct pi_adapter *pi;
+	char junk[2];
+
+	/* We only need to flush incoming data when a command was running */
+	if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE)
+		return;
+
+	ap = qc->ap;
+	pi = ap->host->private_data;
+	/* Drain up to 64K of data before we give up this recovery method */
+	for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ)
+						&& count < 65536; count += 2) {
+		pi_connect(pi);
+		pi->proto->read_block(pi, junk, 2);
+		pi_disconnect_later(pi);
+	}
+
+	if (count)
+		ata_port_dbg(ap, "drained %d bytes to clear DRQ\n", count);
+}
+
+static void pata_parport_lost_interrupt(struct ata_port *ap)
+{

drivers/ata/pata_parport/pata_parport.c line 296

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	u8 status;
+	struct ata_queued_cmd *qc;
+
+	/* Only one outstanding command per SFF channel */
+	qc = ata_qc_from_tag(ap, ap->link.active_tag);
+	/* We cannot lose an interrupt on a non-existent or polled command */
+	if (!qc || qc->tf.flags & ATA_TFLAG_POLLING)
+		return;
+	/* See if the controller thinks it is still busy - if so the command
+	   isn't a lost IRQ but is still in progress */

Please use multi-line comment style:

/*
* See if...
* ...
*/

drivers/ata/pata_parport/pata_parport.c line 302

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+	status = pata_parport_check_altstatus(ap);
+	if (status & ATA_BUSY)
+		return;
+
+	/* There was a command running, we are no longer busy and we have
+	   no interrupt. */

same

Quoted 87 lines
drivers/ata/pata_parport/pata_parport.c new file +87 -0
+	ata_port_warn(ap, "lost interrupt (Status 0x%x)\n", status);
+	/* Run the host interrupt logic as if the interrupt had not been lost */
+	ata_sff_port_intr(ap, qc);
+}
+
+static struct ata_port_operations pata_parport_port_ops = {
+	.qc_prep		= ata_noop_qc_prep,
+	.qc_issue		= ata_sff_qc_issue,
+	.qc_fill_rtf		= ata_sff_qc_fill_rtf,
+
+	.freeze			= ata_sff_freeze,
+	.thaw			= ata_sff_thaw,
+	.prereset		= ata_sff_prereset,
+	.softreset		= pata_parport_softreset,
+	.postreset		= ata_sff_postreset,
+	.error_handler		= ata_sff_error_handler,
+	.sched_eh		= ata_std_sched_eh,
+	.end_eh			= ata_std_end_eh,
+
+	.sff_dev_select		= pata_parport_dev_select,
+	.sff_check_status	= pata_parport_check_status,
+	.sff_check_altstatus	= pata_parport_check_altstatus,
+	.sff_tf_load		= pata_parport_tf_load,
+	.sff_tf_read		= pata_parport_tf_read,
+	.sff_exec_command	= pata_parport_exec_command,
+	.sff_data_xfer		= pata_parport_data_xfer,
+	.sff_drain_fifo		= pata_parport_drain_fifo,
+
+	.lost_interrupt		= pata_parport_lost_interrupt,
+};
+
+static const struct ata_port_info pata_parport_port_info = {
+	.flags		= ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_POLLING,
+	.pio_mask	= ATA_PIO0,
+	/* No DMA */
+	.port_ops	= &pata_parport_port_ops,
+};
+
+void pi_release(struct pi_adapter *pi)
+{
+	parport_unregister_device(pi->pardev);
+	if (pi->proto->release_proto)
+		pi->proto->release_proto(pi);
+	module_put(pi->proto->owner);
+}
+
+static int default_test_proto(struct pi_adapter *pi, char *scratch)
+{
+	int j, k;
+	int e[2] = { 0, 0 };
+
+	pi->proto->connect(pi);
+
+	for (j = 0; j < 2; j++) {
+		pi->proto->write_regr(pi, 0, 6, 0xa0 + j * 0x10);
+		for (k = 0; k < 256; k++) {
+			pi->proto->write_regr(pi, 0, 2, k ^ 0xaa);
+			pi->proto->write_regr(pi, 0, 3, k ^ 0x55);
+			if (pi->proto->read_regr(pi, 0, 2) != (k ^ 0xaa))
+				e[j]++;
+		}
+	}
+	pi->proto->disconnect(pi);
+
+	if (verbose)
+		dev_info(&pi->dev, "%s: port 0x%x, mode  %d, test=(%d,%d)\n",
+		       pi->proto->name, pi->port,
+		       pi->mode, e[0], e[1]);
+
+	return (e[0] && e[1]);	/* not here if both > 0 */
+}
+
+static int pi_test_proto(struct pi_adapter *pi, char *scratch)
+{
+	int res;
+
+	parport_claim_or_block(pi->pardev);
+	if (pi->proto->test_proto)
+		res = pi->proto->test_proto(pi, scratch, verbose);
+	else
+		res = default_test_proto(pi, scratch);
+	parport_release(pi->pardev);
+
+	return res;
+}
+
+static int pi_probe_mode(struct pi_adapter *pi, int max, char *scratch)

drivers/ata/pata_parport/pata_parport.c line 399

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+{
+	int best, range;
+
+	if (pi->mode != -1) {
+		if (pi->mode >= max)
+			return 0;
+		range = 3;
+		if (pi->mode >= pi->proto->epp_first)
+			range = 8;
+		if ((range == 8) && (pi->port % 8))

extra internal parenthesis not needed.

drivers/ata/pata_parport/pata_parport.c line 408

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.c new file +9 -0
+			return 0;
+		return (!pi_test_proto(pi, scratch));
+	}
+	best = -1;
+	for (pi->mode = 0; pi->mode < max; pi->mode++) {
+		range = 3;
+		if (pi->mode >= pi->proto->epp_first)
+			range = 8;
+		if ((range == 8) && (pi->port % 8))

same

drivers/ata/pata_parport/pata_parport.c line 414

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+			break;
+		if (!pi_test_proto(pi, scratch))
+			best = pi->mode;
+	}
+	pi->mode = best;
+	return (best > -1);

same

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +11 -0
+}
+
+
+static int pi_probe_unit(struct pi_adapter *pi, int unit, char *scratch)
+{
+	int max, s, e;
+
+	s = unit;
+	e = s + 1;
+
+	if (s == -1) {

drivers/ata/pata_parport/pata_parport.c line 435

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+		s = 0;
+		e = pi->proto->max_units;
+	}
+
+	if (pi->proto->test_port) {
+		parport_claim_or_block(pi->pardev);
+		max = pi->proto->test_port(pi);
+		parport_release(pi->pardev);
+	} else
+		max = pi->proto->max_mode;

Please add curly bracket for the else too.

drivers/ata/pata_parport/pata_parport.c line 445

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+
+	if (pi->proto->probe_unit) {
+		parport_claim_or_block(pi->pardev);
+		for (pi->unit = s; pi->unit < e; pi->unit++)
+			if (pi->proto->probe_unit(pi)) {
+				parport_release(pi->pardev);
+				if (pi_probe_mode(pi, max, scratch))
+					return 1;
+				return 0;
+			}

Please add curly bracket for the for too. Technically not needed, but since the "if" is over multiple lines, this will make the code more readable (I had to recheck why the following parport_release() call was indented like this...).

drivers/ata/pata_parport/pata_parport.c line 452

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+		parport_release(pi->pardev);
+		return 0;
+	}
+
+	if (!pi_probe_mode(pi, max, scratch))
+		return 0;
+	return 1;

return pi_probe_mode(pi, max, scratch); ?

Quoted 21 lines
drivers/ata/pata_parport/pata_parport.c new file +21 -0
+}
+
+static void pata_parport_dev_release(struct device *dev)
+{
+	struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev);
+
+	kfree(pi);
+}
+
+void pata_parport_bus_release(struct device *dev)
+{
+	/* nothing to do here but required to avoid warning on device removal */
+}
+
+static struct bus_type pata_parport_bus_type = {
+	.name = DRV_NAME,
+};
+
+static struct device pata_parport_bus = {
+	.init_name = DRV_NAME,
+	.release = pata_parport_bus_release,

drivers/ata/pata_parport/pata_parport.c line 483

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+};
+
+struct pi_adapter *pi_init_one(struct parport *parport, struct pi_protocol *pr,
+			       int mode, int unit, int delay)
+{
+	struct pardev_cb par_cb = { };
+	char scratch[512];
+	const struct ata_port_info *ppi[] = { &pata_parport_port_info };
+	struct ata_host *host;
+	struct pi_adapter *pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL);

I would prefer hainving the pi = kzalloc() initialization right above the "if (!pi)" below.

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +11 -0
+
+	if (!pi)
+		return NULL;
+
+	/* set up pi->dev before pi_probe_unit() so it can use dev_printk() */
+	pi->dev.parent = &pata_parport_bus;
+	pi->dev.bus = &pata_parport_bus_type;
+	pi->dev.driver = &pr->driver;
+	pi->dev.release = pata_parport_dev_release;
+	pi->dev.id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
+	if (pi->dev.id < 0)

drivers/ata/pata_parport/pata_parport.c line 504

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+		return NULL; /* pata_parport_dev_release will do kfree(pi) */
+	dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);
+	if (device_register(&pi->dev)) {
+		put_device(&pi->dev);
+		goto out_ida_free;
+	}
+
+	pi->proto = pr;
+
+	/* still racy */

What is racy ?

Quoted 64 lines
drivers/ata/pata_parport/pata_parport.c new file +64 -0
+	if (!try_module_get(pi->proto->owner))
+		goto out_unreg_dev;
+	if (pi->proto->init_proto && pi->proto->init_proto(pi) < 0)
+		goto out_module_put;
+
+	pi->delay = (delay == -1) ? pi->proto->default_delay : delay;
+	pi->mode = mode;
+	pi->port = parport->base;
+
+	par_cb.private = pi;
+	pi->pardev = parport_register_dev_model(parport, dev_name(&pi->dev),
+						&par_cb, pi->dev.id);
+	if (!pi->pardev)
+		goto out_module_put;
+
+	if (!pi_probe_unit(pi, unit, scratch)) {
+		dev_info(&pi->dev, "Adapter not found\n");
+		goto out_unreg_parport;
+	}
+
+	pi->proto->log_adapter(pi, scratch, verbose);
+
+	host = ata_host_alloc_pinfo(&pi->dev, ppi, 1);
+	if (!host)
+		goto out_unreg_parport;
+	dev_set_drvdata(&pi->dev, host);
+	host->private_data = pi;
+
+	ata_port_desc(host->ports[0], "port %s", pi->pardev->port->name);
+	ata_port_desc(host->ports[0], "protocol %s", pi->proto->name);
+
+	timer_setup(&pi->timer, pi_disconnect_timer, 0);
+
+	if (ata_host_activate(host, 0, NULL, 0, &pi->proto->sht))
+		goto out_unreg_parport;
+
+	return pi;
+
+out_unreg_parport:
+	parport_unregister_device(pi->pardev);
+	if (pi->proto->release_proto)
+		pi->proto->release_proto(pi);
+out_module_put:
+	module_put(pi->proto->owner);
+out_unreg_dev:
+	device_unregister(&pi->dev);
+out_ida_free:
+	ida_free(&pata_parport_bus_dev_ids, pi->dev.id);
+	return NULL;
+}
+
+int pata_parport_register_driver(struct pi_protocol *pr)
+{
+	int error;
+	struct parport *parport;
+	int port_num;
+
+	pr->driver.bus = &pata_parport_bus_type;
+	pr->driver.name = pr->name;
+	error = driver_register(&pr->driver);
+	if (error)
+		return error;
+
+	mutex_lock(&pi_mutex);

drivers/ata/pata_parport/pata_parport.c line 578

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	error = idr_alloc(&protocols, pr, 0, 0, GFP_KERNEL);
+	if (error < 0) {
+		driver_unregister(&pr->driver);
+		mutex_unlock(&pi_mutex);
+		return error;
+	}
+
+	pr_info("pata_parport: protocol %s registered\n", pr->name);
+
+	if (probe)	/* probe all parports using this protocol */

Please move the comment inside the if and use curly brackets for the if since its statement is multi-line.

Quoted 5 lines
drivers/ata/pata_parport/pata_parport.c new file +5 -0
+		idr_for_each_entry(&parport_list, parport, port_num)
+			pi_init_one(parport, pr, -1, 0, -1);
+	mutex_unlock(&pi_mutex);
+
+	return 0;

drivers/ata/pata_parport/pata_parport.c line 593

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+}
+EXPORT_SYMBOL(pata_parport_register_driver);
+
+void pata_parport_unregister_driver(struct pi_protocol *pr)
+{
+	struct pi_protocol *pr_iter;
+	int id = -1;
+
+	mutex_lock(&pi_mutex);
+	idr_for_each_entry(&protocols, pr_iter, id)

Add curly brackets.

drivers/ata/pata_parport/pata_parport.c line 598

Quoted 5 lines
drivers/ata/pata_parport/pata_parport.c new file +5 -0
+		if (pr_iter == pr)
+			break;
+	idr_remove(&protocols, id);
+	mutex_unlock(&pi_mutex);
+	pr_info("pata_parport: protocol %s removed\n", pr->name);

I do not think this message is needed.

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +11 -0
+	driver_unregister(&pr->driver);
+}
+EXPORT_SYMBOL(pata_parport_unregister_driver);
+
+static ssize_t new_device_store(struct bus_type *bus, const char *buf, size_t count)
+{
+	char port[12] = "auto";
+	char protocol[8] = "auto";
+	int mode = -1, unit = -1, delay = -1;
+	struct pi_protocol *pr, *pr_wanted;
+	struct device_driver *drv;

drivers/ata/pata_parport/pata_parport.c line 619

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	struct parport *parport;
+	int port_num, port_wanted, pr_num;
+	bool ok = false;
+
+	if (sscanf(buf, "%11s %7s %d %d %d",
+			port, protocol, &mode, &unit, &delay) < 1)
+		return -EINVAL;
+
+	if (sscanf(port, "parport%u", &port_wanted) < 1) {
+		if (!strcmp(port, "auto"))

Curly brackets please.

drivers/ata/pata_parport/pata_parport.c line 630

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +11 -0
+			port_wanted = -1;
+		else {
+			pr_err("invalid port name %s\n", port);
+			return -EINVAL;
+		}
+	}
+
+	drv = driver_find(protocol, &pata_parport_bus_type);
+	if (!drv) {
+		if (!strcmp(protocol, "auto"))
+			pr_wanted = NULL;

same.

drivers/ata/pata_parport/pata_parport.c line 636

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+		else {
+			pr_err("protocol %s not found\n", protocol);
+			return -EINVAL;
+		}
+	} else
+		pr_wanted = container_of(drv, struct pi_protocol, driver);

Here too.

drivers/ata/pata_parport/pata_parport.c line 649

Quoted 13 lines
drivers/ata/pata_parport/pata_parport.c new file +13 -0
+
+	mutex_lock(&pi_mutex);
+	/* walk all parports */
+	idr_for_each_entry(&parport_list, parport, port_num) {
+		if (port_num == port_wanted || port_wanted == -1) {
+			parport = parport_find_number(port_num);
+			if (!parport) {
+				pr_err("no such port %s\n", port);
+				mutex_unlock(&pi_mutex);
+				return -ENODEV;
+			}
+			/* walk all protocols */
+			idr_for_each_entry(&protocols, pr, pr_num)

Add curly brackets to this one too.

Quoted 57 lines
drivers/ata/pata_parport/pata_parport.c new file +57 -0
+				if (pr == pr_wanted || !pr_wanted)
+					if (pi_init_one(parport, pr, mode, unit,
+							delay))
+						ok = true;
+			parport_put_port(parport);
+		}
+	}
+	mutex_unlock(&pi_mutex);
+	if (!ok)
+		return -ENODEV;
+
+	return count;
+}
+static BUS_ATTR_WO(new_device);
+
+static void pi_remove_one(struct device *dev)
+{
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct pi_adapter *pi = host->private_data;
+
+	ata_host_detach(host);
+	del_timer_sync(&pi->timer);
+	pi_release(pi);
+	device_unregister(dev);
+	ida_free(&pata_parport_bus_dev_ids, dev->id);
+	/* pata_parport_dev_release will do kfree(pi) */
+}
+
+static ssize_t delete_device_store(struct bus_type *bus, const char *buf, size_t count)
+{
+	struct device *dev;
+	char device_name[32];
+	int fields;
+
+	fields = sscanf(buf, "%31s", device_name);
+	if (fields < 1)
+		return -EINVAL;
+
+	mutex_lock(&pi_mutex);
+	dev = bus_find_device_by_name(bus, NULL, device_name);
+	if (!dev) {
+		mutex_unlock(&pi_mutex);
+		return -ENODEV;
+	}
+
+	pi_remove_one(dev);
+	mutex_unlock(&pi_mutex);
+
+	return count;
+}
+static BUS_ATTR_WO(delete_device);
+
+static void pata_parport_attach(struct parport *port)
+{
+	struct pi_protocol *pr;
+	int pr_num, id;
+

drivers/ata/pata_parport/pata_parport.c line 716

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	mutex_lock(&pi_mutex);
+	id = idr_alloc(&parport_list, port, port->number, port->number, GFP_KERNEL);
+	if (id < 0) {
+		mutex_unlock(&pi_mutex);
+		return;
+	}
+
+	if (probe) /* probe this port using all protocols */
+		idr_for_each_entry(&protocols, pr, pr_num)
+			pi_init_one(port, pr, -1, 0, -1);

Curly brackets and comment under the if.

Quoted 33 lines
drivers/ata/pata_parport/pata_parport.c new file +33 -0
+	mutex_unlock(&pi_mutex);
+}
+
+static int pi_remove_port(struct device *dev, void *p)
+{
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct pi_adapter *pi = host->private_data;
+
+	if (pi->pardev->port == p)
+		pi_remove_one(dev);
+
+	return 0;
+}
+
+static void pata_parport_detach(struct parport *port)
+{
+	mutex_lock(&pi_mutex);
+	bus_for_each_dev(&pata_parport_bus_type, NULL, port, pi_remove_port);
+	idr_remove(&parport_list, port->number);
+	mutex_unlock(&pi_mutex);
+}
+
+static struct parport_driver pata_parport_driver = {
+	.name = DRV_NAME,
+	.match_port = pata_parport_attach,
+	.detach = pata_parport_detach,
+	.devmodel = true,
+};
+
+static __init int pata_parport_init(void)
+{
+	int error;
+

drivers/ata/pata_parport/pata_parport.c line 759

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	error = bus_register(&pata_parport_bus_type);
+	if (error) {
+		pr_err("failed to register pata_parport bus, error: %d\n", error);
+		return error;
+	}
+
+	error = device_register(&pata_parport_bus);
+	if (error) {
+		pr_err("failed to register pata_parport bus, error: %d\n", error);
+		return error;

Bug. This should not be here.

Quoted 56 lines
drivers/ata/pata_parport/pata_parport.c new file +50 -0
+		goto out_unregister_bus;
+	}
+
+	error = bus_create_file(&pata_parport_bus_type, &bus_attr_new_device);
+	if (error) {
+		pr_err("unable to create sysfs file, error: %d\n", error);
+		goto out_unregister_dev;
+	}
+
+	error = bus_create_file(&pata_parport_bus_type, &bus_attr_delete_device);
+	if (error) {
+		pr_err("unable to create sysfs file, error: %d\n", error);
+		goto out_remove_new;
+	}
+
+	error = parport_register_driver(&pata_parport_driver);
+	if (error) {
+		pr_err("unable to register parport driver, error: %d\n", error);
+		goto out_remove_del;
+	}
+
+	return 0;
+
+out_remove_del:
+	bus_remove_file(&pata_parport_bus_type, &bus_attr_delete_device);
+out_remove_new:
+	bus_remove_file(&pata_parport_bus_type, &bus_attr_new_device);
+out_unregister_dev:
+	device_unregister(&pata_parport_bus);
+out_unregister_bus:
+	bus_unregister(&pata_parport_bus_type);
+	return error;
+}
+
+static __exit void pata_parport_exit(void)
+{
+	parport_unregister_driver(&pata_parport_driver);
+	bus_remove_file(&pata_parport_bus_type, &bus_attr_new_device);
+	bus_remove_file(&pata_parport_bus_type, &bus_attr_delete_device);
+	device_unregister(&pata_parport_bus);
+	bus_unregister(&pata_parport_bus_type);
+}
+
+MODULE_AUTHOR("Ondrej Zary");
+MODULE_DESCRIPTION("driver for parallel port ATA adapters");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paride");
+
+module_init(pata_parport_init);
+module_exit(pata_parport_exit);
drivers/ata/pata_parport/pata_parport.h new file +0 -0
new file mode 100644
index 000000000000..c4201b809b20

drivers/ata/pata_parport/pata_parport.h line 6

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.h new file +6 -0
@@ -0,0 +1,110 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ *	paride.h	(c) 1997-8  Grant R. Guenther <[email protected]>
+ *				    Under the terms of the GPL.
+ *
+ * This file defines the interface for adapter chip drivers.

Which adapter ? "Parallel port IDE adapter chip", no ?

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.h new file +6 -0
+ */
+
+#include <linux/libata.h>
+
+struct pi_adapter {
+	struct device dev;

drivers/ata/pata_parport/pata_parport.h line 22

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.h new file +10 -0
+	struct pi_protocol *proto;	/* adapter protocol */
+	int port;			/* base address of parallel port */
+	int mode;			/* transfer mode in use */
+	int delay;			/* adapter delay setting */
+	int unit;			/* unit number for chained adapters */
+	int saved_r0;			/* saved port state */
+	int saved_r2;			/* saved port state */
+	unsigned long private;		/* for protocol module */
+	struct pardevice *pardev;	/* pointer to pardevice */
+	int claimed;			/* parport has already been claimed */

Make this a bool ?

Quoted 16 lines
drivers/ata/pata_parport/pata_parport.h new file +16 -0
+	struct timer_list timer;	/* disconnect timer */
+};
+
+/* registers are addressed as (cont,regr)
+ *	cont: 0 for command register file, 1 for control register(s)
+ *	regr: 0-7 for register number.
+ */
+
+/* macros and functions exported to the protocol modules */
+#define delay_p			(pi->delay ? udelay(pi->delay) : (void)0)
+#define out_p(offs, byte)	do { outb(byte, pi->port + offs); delay_p; } while (0)
+#define in_p(offs)		(delay_p, inb(pi->port + offs))
+
+#define w0(byte)		out_p(0, byte)
+#define r0()			(in_p(0) & 0xff)
+#define w1(byte)		out_p(1, byte)

drivers/ata/pata_parport/pata_parport.h line 48

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.h new file +10 -0
+#define r1()			(in_p(1) & 0xff)
+#define w2(byte)		out_p(2, byte)
+#define r2()			(in_p(2) & 0xff)
+#define w3(byte)		out_p(3, byte)
+#define w4(byte)		out_p(4, byte)
+#define r4()			(in_p(4) & 0xff)
+#define w4w(data)		do { outw(data, pi->port + 4); delay_p; } while (0)
+#define w4l(data)		do { outl(data, pi->port + 4); delay_p; } while (0)
+#define r4w()			(delay_p, inw(pi->port + 4) & 0xffff)
+#define r4l()			(delay_p, inl(pi->port + 4) & 0xffffffff)

Why not align this with the others ?

Quoted 16 lines
drivers/ata/pata_parport/pata_parport.h new file +16 -0
+
+static inline u16 pi_swab16(char *b, int k)
+{
+	union { u16 u; char t[2]; } r;
+
+	r.t[0] = b[2 * k + 1]; r.t[1] = b[2 * k];
+	return r.u;
+}
+
+static inline u32 pi_swab32(char *b, int k)
+{
+	union { u32 u; char f[4]; } r;
+
+	r.f[0] = b[4 * k + 1]; r.f[1] = b[4 * k];
+	r.f[2] = b[4 * k + 3]; r.f[3] = b[4 * k + 2];
+	return r.u;

drivers/ata/pata_parport/pata_parport.h line 74

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.h new file +10 -0
+}
+
+struct pi_protocol {
+	char name[8];		/* name for this protocol */
+
+	int max_mode;		/* max mode number */
+	int epp_first;		/* modes >= this use 8 ports */
+
+	int default_delay;	/* delay parameter if not specified */
+	int max_units;		/* max chained units probed for */

Except maybe epp_first, I find the comments for these fields useless: no information added.

Quoted 15 lines
drivers/ata/pata_parport/pata_parport.h new file +15 -0
+
+	void (*write_regr)(struct pi_adapter *pi, int cont, int regr, int val);
+	int (*read_regr)(struct pi_adapter *pi, int cont, int regr);
+	void (*write_block)(struct pi_adapter *pi, char *buf, int count);
+	void (*read_block)(struct pi_adapter *pi, char *buf, int count);
+
+	void (*connect)(struct pi_adapter *pi);
+	void (*disconnect)(struct pi_adapter *pi);
+
+	int (*test_port)(struct pi_adapter *pi);
+	int (*probe_unit)(struct pi_adapter *pi);
+	int (*test_proto)(struct pi_adapter *pi, char *scratch, int verbose);
+	void (*log_adapter)(struct pi_adapter *pi, char *scratch, int verbose);
+
+	int (*init_proto)(struct pi_adapter *pi);

drivers/ata/pata_parport/pata_parport.h line 99

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.h new file +10 -0
+	void (*release_proto)(struct pi_adapter *pi);
+	struct module *owner;
+	struct device_driver driver;
+	struct scsi_host_template sht;
+};
+
+#define PATA_PARPORT_SHT ATA_PIO_SHT
+
+extern int pata_parport_register_driver(struct pi_protocol *pr);
+extern void pata_parport_unregister_driver(struct pi_protocol *pr);

No need for extern.

drivers/ata/pata_parport/pata_parport.h line 110

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.h new file +11 -0
+
+/**
+ * module_pata_parport_driver() - Helper macro for registering a pata_parport driver
+ * @__pi_protocol: pi_protocol struct
+ *
+ * Helper macro for pata_parport drivers which do not do anything special in module
+ * init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_pata_parport_driver(__pi_protocol) \
+	module_driver(__pi_protocol, pata_parport_register_driver, pata_parport_unregister_driver)

Make this a static inline ?

Signature · 2 lines
Damien Le Moal
Western Digital Research
#3 lore raw

Re: [PATCH 01/16] pata_parport: add core driver (PARIDE replacement)

Quoted 91 lines · Damien Le Moal
Quoted 21 lines · Ondrej Zary

Add pata_parport (PARIDE replacement) core libata driver.

---
 drivers/ata/Kconfig                     |  25 +
 drivers/ata/Makefile                    |   2 +
 drivers/ata/pata_parport/Kconfig        |  10 +
 drivers/ata/pata_parport/Makefile       |   9 +
 drivers/ata/pata_parport/pata_parport.c | 809 ++++++++++++++++++++++++
 drivers/ata/pata_parport/pata_parport.h | 110 ++++
 6 files changed, 965 insertions(+)
 create mode 100644 drivers/ata/pata_parport/Kconfig
 create mode 100644 drivers/ata/pata_parport/Makefile
 create mode 100644 drivers/ata/pata_parport/pata_parport.c
 create mode 100644 drivers/ata/pata_parport/pata_parport.h
drivers/ata/Kconfig +0 -0
index cb54631fd950..de4548471398 100644

drivers/ata/Kconfig config PATA_WINBOND_VLB · line 1165

Quoted 5 lines
drivers/ata/Kconfig +2 -0
@@ -1161,6 +1161,31 @@ config PATA_WINBOND_VLB
 	  Support for the Winbond W83759A controller on Vesa Local Bus
 	  systems.
 
+config PATA_PARPORT
+	tristate "Parallel port IDE device support (PARIDE replacement)"

I would remove the "(PARIDE replacement)" from the title. If really needed, mention it in the description that this support used to be implemented by PARIDE. But I do not think that is necessary. The last paragraph of the description implies that.

Quoted 10 lines
drivers/ata/Kconfig +10 -0
+	depends on PARPORT_PC
+	help
+	  There are many external CD-ROM and disk devices that connect through
+	  your computer's parallel port. Most of them are actually IDE devices
+	  using a parallel port IDE adapter. This option enables the PATA_PARPORT
+	  subsystem which contains drivers for many of these external drives.
+	  Read <file:Documentation/admin-guide/blockdev/paride.rst> for more information.
+
+	  If you have said Y to the "Parallel-port support" configuration
+	  option, you may share a single port between your printer and other

drivers/ata/Kconfig config PATA_WINBOND_VLB · line 1185

Quoted 10 lines
drivers/ata/Kconfig +10 -0
+	  parallel port devices. Answer Y to build PATA_PARPORT support into your
+	  kernel, or M if you would like to build it as a loadable module. If
+	  your parallel port support is in a loadable module, you must build
+	  PATA_PARPORT as a module. If you built PATA_PARPORT support into your kernel,
+	  you may still build the individual protocol modules as loadable
+	  modules. If you build this support as a module, it will be called pata_parport.
+
+	  Unlike the old PARIDE, there are no high-level drivers needed.
+	  The IDE devices behind parallel port adapters are handled by the
+	  ATA layer.

Several lines are too long. Rewrap please.

Quoted 25 lines
drivers/ata/Kconfig +3 -0
+
+source "drivers/ata/pata_parport/Kconfig"
+
 comment "Generic fallback / legacy drivers"
 
 config PATA_ACPI
drivers/ata/Makefile +2 -0
index b8aebfb14e82..bd6b5fdc004e 100644
@@ -114,6 +114,8 @@ obj-$(CONFIG_PATA_SAMSUNG_CF)	+= pata_samsung_cf.o
 
 obj-$(CONFIG_PATA_PXA)		+= pata_pxa.o
 
+obj-$(CONFIG_PATA_PARPORT)	+= pata_parport/
+
 # Should be last but two libata driver
 obj-$(CONFIG_PATA_ACPI)		+= pata_acpi.o
 # Should be last but one libata driver
drivers/ata/pata_parport/Kconfig new file +0 -0
new file mode 100644
index 000000000000..56dc6b25d5fa

drivers/ata/pata_parport/Kconfig line 6

Quoted 6 lines
drivers/ata/pata_parport/Kconfig new file +6 -0
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# PATA_PARPORT configuration
+#
+# PATA_PARPORT doesn't need PARPORT, but if PARPORT is configured as a module,
+# PATA_PARPORT must also be a module.

This does not parse. If PARPORT is not needed, then why does how PARPORT is compiled matter ? Something is not consistent here.

Quoted 3 lines

drivers/ata/pata_parport/Kconfig line 7

Quoted 1 line
drivers/ata/pata_parport/Kconfig new file +1 -0
+# PATA_PARPORT only supports PC style parports. Tough for USB or other parports...

The second sentence does not parse. What are you trying to say ?

It's copied from paride.

Quoted 41 lines
Quoted 28 lines
drivers/ata/pata_parport/Kconfig new file +3 -0
+
+comment "Parallel IDE protocol modules"
+	depends on PATA_PARPORT
drivers/ata/pata_parport/Makefile new file +9 -0
new file mode 100644
index 000000000000..b105e1cb8dc6
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for Parallel port IDE device drivers.
+#
+# 7 October 2000, Bartlomiej Zolnierkiewicz <[email protected]>
+# Rewritten to use lists instead of if-statements.
+#
+
+obj-$(CONFIG_PATA_PARPORT)		+= pata_parport.o
drivers/ata/pata_parport/pata_parport.c new file +4 -0
new file mode 100644
index 000000000000..7f814062cedd
@@ -0,0 +1,809 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/parport.h>

drivers/ata/pata_parport/pata_parport.c line 14

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+#include "pata_parport.h"
+
+#define DRV_NAME "pata_parport"
+
+static DEFINE_IDR(parport_list);
+static DEFINE_IDR(protocols);
+static DEFINE_IDA(pata_parport_bus_dev_ids);
+static DEFINE_MUTEX(pi_mutex);
+
+static bool probe = 1;

s/1/true to match the type.

Quoted 9 lines

drivers/ata/pata_parport/pata_parport.c line 20

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+module_param(probe, bool, 0644);
+MODULE_PARM_DESC(probe, "Enable automatic device probing (0=off, 1=on [default])");
+
+static bool verbose;
+module_param(verbose, bool, 0644);
+MODULE_PARM_DESC(verbose, "Enable verbose messages (0=off [default], 1=on)");

Is this really necessary ? pr_debug() and all ata_xxx_debug() functions can be enabled dynamically.

The verbose messages are for adapter chip detection. That happens before the ata host is registered.

Quoted 12 lines

drivers/ata/pata_parport/pata_parport.c line 28

Quoted 8 lines
drivers/ata/pata_parport/pata_parport.c new file +8 -0
+
+#define DISCONNECT_TIMEOUT	(HZ / 10)
+
+static void pi_connect(struct pi_adapter *pi)
+{
+	del_timer_sync(&pi->timer);
+	if (pi->claimed)
+		return;

Nit: I would reverse the condition to avoid the return. Or add a block line to separate the following hunk. Better readability this way, I think.

Quoted 13 lines

drivers/ata/pata_parport/pata_parport.c line 37

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.c new file +9 -0
+	pi->claimed = 1;
+	parport_claim_or_block(pi->pardev);
+	pi->proto->connect(pi);
+}
+
+static void pi_disconnect_later(struct pi_adapter *pi)
+{
+	mod_timer(&pi->timer, jiffies + DISCONNECT_TIMEOUT);
+}

Is this really needed ? Not sure it helps in any way. At least the name should be changed to reflect what this does. May be something like pi_start_disconnect_timeout() ?

Disconnect needs to happen after end of an operation so the parport is freed for device(s) (like a printer) connected to pass-through port of a paride device. There could be even multiple paride devices chained on one parport.

Disconnecting immediately at the end of each function does not work (probably breaks the protocol?)

The old high-level drivers (pd, pf...) did connect and disconnect manually on each operation (command or data transfer) but it does not seem to be possible with libata.

Quoted 10 lines

drivers/ata/pata_parport/pata_parport.c line 44

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+
+static void pi_disconnect_timer(struct timer_list *t)
+{
+	struct pi_adapter *pi = from_timer(pi, t, timer);
+
+	if (!pi->claimed)
+		return;

A blank line here would be nice for readability.

Quoted 9 lines

drivers/ata/pata_parport/pata_parport.c line 51

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+	pi->proto->disconnect(pi);
+	parport_release(pi->pardev);
+	pi->claimed = 0;
+}
+
+/* functions taken from libata-sff.c and converted from direct port I/O */
+static unsigned int pata_parport_devchk(struct ata_port *ap, unsigned int device)

Should this be a bool function ?

I don't know. It's copied from libata-sff.c

Quoted 29 lines
Quoted 29 lines
drivers/ata/pata_parport/pata_parport.c new file +29 -0
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	u8 nsect, lbal;
+
+	ap->ops->sff_dev_select(ap, device);
+
+	pi_connect(pi);
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 0x55);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0xaa);
+
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 0xaa);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0x55);
+
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 055);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0xaa);
+
+	nsect = pi->proto->read_regr(pi, 0, ATA_REG_NSECT);
+	lbal = pi->proto->read_regr(pi, 0, ATA_REG_LBAL);
+	pi_disconnect_later(pi);
+
+	if ((nsect == 0x55) && (lbal == 0xaa))
+		return 1;	/* we found a device */
+
+	return 0;		/* nothing found */
+}
+
+static int pata_parport_bus_softreset(struct ata_port *ap, unsigned int devmask,
+				      unsigned long deadline)
+{
Quoted 8 lines

drivers/ata/pata_parport/pata_parport.c line 86

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	/* software reset.  causes dev0 to be selected */
+	pi->proto->write_regr(pi, 1, 6, ap->ctl);
+	udelay(20);	/* FIXME: flush */

Then please fix it.

I don't know what that means. It's copied from libata-sff.c

Quoted 88 lines

drivers/ata/pata_parport/pata_parport.c line 88

Quoted 2 lines
drivers/ata/pata_parport/pata_parport.c new file +2 -0
+	pi->proto->write_regr(pi, 1, 6, ap->ctl | ATA_SRST);
+	udelay(20);	/* FIXME: flush */

Here too.

Quoted 19 lines
drivers/ata/pata_parport/pata_parport.c new file +19 -0
+	pi->proto->write_regr(pi, 1, 6, ap->ctl);
+	ap->last_ctl = ap->ctl;
+	pi_disconnect_later(pi);
+
+	/* wait the port to become ready */
+	return ata_sff_wait_after_reset(&ap->link, devmask, deadline);
+}
+
+static int pata_parport_softreset(struct ata_link *link, unsigned int *classes,
+				  unsigned long deadline)
+{
+	struct ata_port *ap = link->ap;
+	unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
+	unsigned int devmask = 0;
+	int rc;
+	u8 err;
+
+	/* determine if device 0/1 are present */
+	if (pata_parport_devchk(ap, 0))

drivers/ata/pata_parport/pata_parport.c line 117

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+		devmask |= (1 << 0);
+	if (slave_possible && pata_parport_devchk(ap, 1))
+		devmask |= (1 << 1);
+
+	/* select device 0 again */
+	ap->ops->sff_dev_select(ap, 0);
+
+	/* issue bus reset */
+	rc = pata_parport_bus_softreset(ap, devmask, deadline);
+	/* if link is occupied, -ENODEV too is an error */

Please merge this comment with the one above. That will make the code more readable (I know this is the style used by many drivers, but let's not repeat the weird style :)).

Quoted 49 lines
drivers/ata/pata_parport/pata_parport.c new file +49 -0
+	if (rc && (rc != -ENODEV || sata_scr_valid(link))) {
+		ata_link_err(link, "SRST failed (errno=%d)\n", rc);
+		return rc;
+	}
+
+	/* determine by signature whether we have ATA or ATAPI devices */
+	classes[0] = ata_sff_dev_classify(&link->device[0],
+					  devmask & (1 << 0), &err);
+	if (slave_possible && err != 0x81)
+		classes[1] = ata_sff_dev_classify(&link->device[1],
+						  devmask & (1 << 1), &err);
+
+	return 0;
+}
+
+static u8 pata_parport_check_status(struct ata_port *ap)
+{
+	u8 status;
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	status = pi->proto->read_regr(pi, 0, ATA_REG_STATUS);
+	pi_disconnect_later(pi);
+
+	return status;
+}
+
+static u8 pata_parport_check_altstatus(struct ata_port *ap)
+{
+	u8 altstatus;
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	altstatus = pi->proto->read_regr(pi, 1, 6);
+	pi_disconnect_later(pi);
+
+	return altstatus;
+}
+
+static void pata_parport_dev_select(struct ata_port *ap, unsigned int device)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	u8 tmp;
+
+	pi_connect(pi);
+	if (device == 0)
+		tmp = ATA_DEVICE_OBS;
+	else
+		tmp = ATA_DEVICE_OBS | ATA_DEV1;
Quoted 8 lines

drivers/ata/pata_parport/pata_parport.c line 170

Quoted 4 lines
drivers/ata/pata_parport/pata_parport.c new file +4 -0
+
+	pi->proto->write_regr(pi, 0, ATA_REG_DEVICE, tmp);
+	pi_disconnect_later(pi);
+	ata_sff_pause(ap);	/* needed; also flushes, for mmio */

The comment does not parse... Why is it needed ?
And pleasde move the comment above the call, with a blank line separating it from the previous lines.

I don't know. It's copied from libata-sff.c

Quoted 27 lines
Quoted 13 lines
drivers/ata/pata_parport/pata_parport.c new file +13 -0
+}
+
+static void pata_parport_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
+
+	pi_connect(pi);
+	if (tf->ctl != ap->last_ctl) {
+		pi->proto->write_regr(pi, 1, 6, tf->ctl);
+		ap->last_ctl = tf->ctl;
+		ata_wait_idle(ap);
+	}

drivers/ata/pata_parport/pata_parport.c line 193

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+
+	if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
+		pi->proto->write_regr(pi, 0, ATA_REG_FEATURE, tf->hob_feature);
+		pi->proto->write_regr(pi, 0, ATA_REG_NSECT, tf->hob_nsect);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAL, tf->hob_lbal);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAM, tf->hob_lbam);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAH, tf->hob_lbah);
+	}
+
+	if (is_addr) {

Move this if above the previous one. Doing so, you can remove the need for is_addr var and simplify the previous if condition.

Quoted 2 lines

That said, many pata drivers check that flag but it is always set by libata core. So checking it seems useless. Need to dig into this.

It's copied from libata-sff.c which is almost libata core.

Quoted 341 lines
Quoted 93 lines
drivers/ata/pata_parport/pata_parport.c new file +93 -0
+		pi->proto->write_regr(pi, 0, ATA_REG_FEATURE, tf->feature);
+		pi->proto->write_regr(pi, 0, ATA_REG_NSECT, tf->nsect);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAL, tf->lbal);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAM, tf->lbam);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAH, tf->lbah);
+	}
+
+	if (tf->flags & ATA_TFLAG_DEVICE)
+		pi->proto->write_regr(pi, 0, ATA_REG_DEVICE, tf->device);
+
+	ata_wait_idle(ap);
+	pi_disconnect_later(pi);
+}
+
+static void pata_parport_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	tf->command = pi->proto->read_regr(pi, 0, ATA_REG_STATUS);
+	tf->feature = pi->proto->read_regr(pi, 0, ATA_REG_ERR);
+	tf->nsect = pi->proto->read_regr(pi, 0, ATA_REG_NSECT);
+	tf->lbal = pi->proto->read_regr(pi, 0, ATA_REG_LBAL);
+	tf->lbam = pi->proto->read_regr(pi, 0, ATA_REG_LBAM);
+	tf->lbah = pi->proto->read_regr(pi, 0, ATA_REG_LBAH);
+	tf->device = pi->proto->read_regr(pi, 0, ATA_REG_DEVICE);
+
+	if (tf->flags & ATA_TFLAG_LBA48) {
+		pi->proto->write_regr(pi, 1, 6, tf->ctl | ATA_HOB);
+		tf->hob_feature = pi->proto->read_regr(pi, 0, ATA_REG_ERR);
+		tf->hob_nsect = pi->proto->read_regr(pi, 0, ATA_REG_NSECT);
+		tf->hob_lbal = pi->proto->read_regr(pi, 0, ATA_REG_LBAL);
+		tf->hob_lbam = pi->proto->read_regr(pi, 0, ATA_REG_LBAM);
+		tf->hob_lbah = pi->proto->read_regr(pi, 0, ATA_REG_LBAH);
+		pi->proto->write_regr(pi, 1, 6, tf->ctl);
+		ap->last_ctl = tf->ctl;
+	}
+	pi_disconnect_later(pi);
+}
+
+static void pata_parport_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	pi->proto->write_regr(pi, 0, ATA_REG_CMD, tf->command);
+	ata_sff_pause(ap);
+	pi_disconnect_later(pi);
+}
+
+static unsigned int pata_parport_data_xfer(struct ata_queued_cmd *qc, unsigned char *buf,
+					   unsigned int buflen, int rw)
+{
+	struct ata_port *ap = qc->dev->link->ap;
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	if (rw == READ)
+		pi->proto->read_block(pi, buf, buflen);
+	else
+		pi->proto->write_block(pi, buf, buflen);
+	pi_disconnect_later(pi);
+
+	return buflen;
+}
+
+static void pata_parport_drain_fifo(struct ata_queued_cmd *qc)
+{
+	int count;
+	struct ata_port *ap;
+	struct pi_adapter *pi;
+	char junk[2];
+
+	/* We only need to flush incoming data when a command was running */
+	if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE)
+		return;
+
+	ap = qc->ap;
+	pi = ap->host->private_data;
+	/* Drain up to 64K of data before we give up this recovery method */
+	for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ)
+						&& count < 65536; count += 2) {
+		pi_connect(pi);
+		pi->proto->read_block(pi, junk, 2);
+		pi_disconnect_later(pi);
+	}
+
+	if (count)
+		ata_port_dbg(ap, "drained %d bytes to clear DRQ\n", count);
+}
+
+static void pata_parport_lost_interrupt(struct ata_port *ap)
+{

drivers/ata/pata_parport/pata_parport.c line 296

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	u8 status;
+	struct ata_queued_cmd *qc;
+
+	/* Only one outstanding command per SFF channel */
+	qc = ata_qc_from_tag(ap, ap->link.active_tag);
+	/* We cannot lose an interrupt on a non-existent or polled command */
+	if (!qc || qc->tf.flags & ATA_TFLAG_POLLING)
+		return;
+	/* See if the controller thinks it is still busy - if so the command
+	   isn't a lost IRQ but is still in progress */

Please use multi-line comment style:

/*
* See if...
* ...
*/

drivers/ata/pata_parport/pata_parport.c line 302

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+	status = pata_parport_check_altstatus(ap);
+	if (status & ATA_BUSY)
+		return;
+
+	/* There was a command running, we are no longer busy and we have
+	   no interrupt. */

same

Quoted 87 lines
drivers/ata/pata_parport/pata_parport.c new file +87 -0
+	ata_port_warn(ap, "lost interrupt (Status 0x%x)\n", status);
+	/* Run the host interrupt logic as if the interrupt had not been lost */
+	ata_sff_port_intr(ap, qc);
+}
+
+static struct ata_port_operations pata_parport_port_ops = {
+	.qc_prep		= ata_noop_qc_prep,
+	.qc_issue		= ata_sff_qc_issue,
+	.qc_fill_rtf		= ata_sff_qc_fill_rtf,
+
+	.freeze			= ata_sff_freeze,
+	.thaw			= ata_sff_thaw,
+	.prereset		= ata_sff_prereset,
+	.softreset		= pata_parport_softreset,
+	.postreset		= ata_sff_postreset,
+	.error_handler		= ata_sff_error_handler,
+	.sched_eh		= ata_std_sched_eh,
+	.end_eh			= ata_std_end_eh,
+
+	.sff_dev_select		= pata_parport_dev_select,
+	.sff_check_status	= pata_parport_check_status,
+	.sff_check_altstatus	= pata_parport_check_altstatus,
+	.sff_tf_load		= pata_parport_tf_load,
+	.sff_tf_read		= pata_parport_tf_read,
+	.sff_exec_command	= pata_parport_exec_command,
+	.sff_data_xfer		= pata_parport_data_xfer,
+	.sff_drain_fifo		= pata_parport_drain_fifo,
+
+	.lost_interrupt		= pata_parport_lost_interrupt,
+};
+
+static const struct ata_port_info pata_parport_port_info = {
+	.flags		= ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_POLLING,
+	.pio_mask	= ATA_PIO0,
+	/* No DMA */
+	.port_ops	= &pata_parport_port_ops,
+};
+
+void pi_release(struct pi_adapter *pi)
+{
+	parport_unregister_device(pi->pardev);
+	if (pi->proto->release_proto)
+		pi->proto->release_proto(pi);
+	module_put(pi->proto->owner);
+}
+
+static int default_test_proto(struct pi_adapter *pi, char *scratch)
+{
+	int j, k;
+	int e[2] = { 0, 0 };
+
+	pi->proto->connect(pi);
+
+	for (j = 0; j < 2; j++) {
+		pi->proto->write_regr(pi, 0, 6, 0xa0 + j * 0x10);
+		for (k = 0; k < 256; k++) {
+			pi->proto->write_regr(pi, 0, 2, k ^ 0xaa);
+			pi->proto->write_regr(pi, 0, 3, k ^ 0x55);
+			if (pi->proto->read_regr(pi, 0, 2) != (k ^ 0xaa))
+				e[j]++;
+		}
+	}
+	pi->proto->disconnect(pi);
+
+	if (verbose)
+		dev_info(&pi->dev, "%s: port 0x%x, mode  %d, test=(%d,%d)\n",
+		       pi->proto->name, pi->port,
+		       pi->mode, e[0], e[1]);
+
+	return (e[0] && e[1]);	/* not here if both > 0 */
+}
+
+static int pi_test_proto(struct pi_adapter *pi, char *scratch)
+{
+	int res;
+
+	parport_claim_or_block(pi->pardev);
+	if (pi->proto->test_proto)
+		res = pi->proto->test_proto(pi, scratch, verbose);
+	else
+		res = default_test_proto(pi, scratch);
+	parport_release(pi->pardev);
+
+	return res;
+}
+
+static int pi_probe_mode(struct pi_adapter *pi, int max, char *scratch)

drivers/ata/pata_parport/pata_parport.c line 399

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+{
+	int best, range;
+
+	if (pi->mode != -1) {
+		if (pi->mode >= max)
+			return 0;
+		range = 3;
+		if (pi->mode >= pi->proto->epp_first)
+			range = 8;
+		if ((range == 8) && (pi->port % 8))

extra internal parenthesis not needed.

drivers/ata/pata_parport/pata_parport.c line 408

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.c new file +9 -0
+			return 0;
+		return (!pi_test_proto(pi, scratch));
+	}
+	best = -1;
+	for (pi->mode = 0; pi->mode < max; pi->mode++) {
+		range = 3;
+		if (pi->mode >= pi->proto->epp_first)
+			range = 8;
+		if ((range == 8) && (pi->port % 8))

same

drivers/ata/pata_parport/pata_parport.c line 414

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+			break;
+		if (!pi_test_proto(pi, scratch))
+			best = pi->mode;
+	}
+	pi->mode = best;
+	return (best > -1);

same

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +11 -0
+}
+
+
+static int pi_probe_unit(struct pi_adapter *pi, int unit, char *scratch)
+{
+	int max, s, e;
+
+	s = unit;
+	e = s + 1;
+
+	if (s == -1) {

drivers/ata/pata_parport/pata_parport.c line 435

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+		s = 0;
+		e = pi->proto->max_units;
+	}
+
+	if (pi->proto->test_port) {
+		parport_claim_or_block(pi->pardev);
+		max = pi->proto->test_port(pi);
+		parport_release(pi->pardev);
+	} else
+		max = pi->proto->max_mode;

Please add curly bracket for the else too.

drivers/ata/pata_parport/pata_parport.c line 445

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+
+	if (pi->proto->probe_unit) {
+		parport_claim_or_block(pi->pardev);
+		for (pi->unit = s; pi->unit < e; pi->unit++)
+			if (pi->proto->probe_unit(pi)) {
+				parport_release(pi->pardev);
+				if (pi_probe_mode(pi, max, scratch))
+					return 1;
+				return 0;
+			}

Please add curly bracket for the for too. Technically not needed, but since the "if" is over multiple lines, this will make the code more readable (I had to recheck why the following parport_release() call was indented like this...).

drivers/ata/pata_parport/pata_parport.c line 452

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+		parport_release(pi->pardev);
+		return 0;
+	}
+
+	if (!pi_probe_mode(pi, max, scratch))
+		return 0;
+	return 1;

return pi_probe_mode(pi, max, scratch); ?

Quoted 21 lines
drivers/ata/pata_parport/pata_parport.c new file +21 -0
+}
+
+static void pata_parport_dev_release(struct device *dev)
+{
+	struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev);
+
+	kfree(pi);
+}
+
+void pata_parport_bus_release(struct device *dev)
+{
+	/* nothing to do here but required to avoid warning on device removal */
+}
+
+static struct bus_type pata_parport_bus_type = {
+	.name = DRV_NAME,
+};
+
+static struct device pata_parport_bus = {
+	.init_name = DRV_NAME,
+	.release = pata_parport_bus_release,

drivers/ata/pata_parport/pata_parport.c line 483

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+};
+
+struct pi_adapter *pi_init_one(struct parport *parport, struct pi_protocol *pr,
+			       int mode, int unit, int delay)
+{
+	struct pardev_cb par_cb = { };
+	char scratch[512];
+	const struct ata_port_info *ppi[] = { &pata_parport_port_info };
+	struct ata_host *host;
+	struct pi_adapter *pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL);

I would prefer hainving the pi = kzalloc() initialization right above the "if (!pi)" below.

Quoted 15 lines
drivers/ata/pata_parport/pata_parport.c new file +15 -0
+
+	if (!pi)
+		return NULL;
+
+	/* set up pi->dev before pi_probe_unit() so it can use dev_printk() */
+	pi->dev.parent = &pata_parport_bus;
+	pi->dev.bus = &pata_parport_bus_type;
+	pi->dev.driver = &pr->driver;
+	pi->dev.release = pata_parport_dev_release;
+	pi->dev.id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
+	if (pi->dev.id < 0)
+		return NULL; /* pata_parport_dev_release will do kfree(pi) */
+	dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);
+	if (device_register(&pi->dev)) {
+		put_device(&pi->dev);
Quoted 8 lines

drivers/ata/pata_parport/pata_parport.c line 504

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+		goto out_ida_free;
+	}
+
+	pi->proto = pr;
+
+	/* still racy */

What is racy ?

I don't know - the comment came from paride. I'll probably just delete it.

Quoted 386 lines
Quoted 64 lines
drivers/ata/pata_parport/pata_parport.c new file +64 -0
+	if (!try_module_get(pi->proto->owner))
+		goto out_unreg_dev;
+	if (pi->proto->init_proto && pi->proto->init_proto(pi) < 0)
+		goto out_module_put;
+
+	pi->delay = (delay == -1) ? pi->proto->default_delay : delay;
+	pi->mode = mode;
+	pi->port = parport->base;
+
+	par_cb.private = pi;
+	pi->pardev = parport_register_dev_model(parport, dev_name(&pi->dev),
+						&par_cb, pi->dev.id);
+	if (!pi->pardev)
+		goto out_module_put;
+
+	if (!pi_probe_unit(pi, unit, scratch)) {
+		dev_info(&pi->dev, "Adapter not found\n");
+		goto out_unreg_parport;
+	}
+
+	pi->proto->log_adapter(pi, scratch, verbose);
+
+	host = ata_host_alloc_pinfo(&pi->dev, ppi, 1);
+	if (!host)
+		goto out_unreg_parport;
+	dev_set_drvdata(&pi->dev, host);
+	host->private_data = pi;
+
+	ata_port_desc(host->ports[0], "port %s", pi->pardev->port->name);
+	ata_port_desc(host->ports[0], "protocol %s", pi->proto->name);
+
+	timer_setup(&pi->timer, pi_disconnect_timer, 0);
+
+	if (ata_host_activate(host, 0, NULL, 0, &pi->proto->sht))
+		goto out_unreg_parport;
+
+	return pi;
+
+out_unreg_parport:
+	parport_unregister_device(pi->pardev);
+	if (pi->proto->release_proto)
+		pi->proto->release_proto(pi);
+out_module_put:
+	module_put(pi->proto->owner);
+out_unreg_dev:
+	device_unregister(&pi->dev);
+out_ida_free:
+	ida_free(&pata_parport_bus_dev_ids, pi->dev.id);
+	return NULL;
+}
+
+int pata_parport_register_driver(struct pi_protocol *pr)
+{
+	int error;
+	struct parport *parport;
+	int port_num;
+
+	pr->driver.bus = &pata_parport_bus_type;
+	pr->driver.name = pr->name;
+	error = driver_register(&pr->driver);
+	if (error)
+		return error;
+
+	mutex_lock(&pi_mutex);

drivers/ata/pata_parport/pata_parport.c line 578

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	error = idr_alloc(&protocols, pr, 0, 0, GFP_KERNEL);
+	if (error < 0) {
+		driver_unregister(&pr->driver);
+		mutex_unlock(&pi_mutex);
+		return error;
+	}
+
+	pr_info("pata_parport: protocol %s registered\n", pr->name);
+
+	if (probe)	/* probe all parports using this protocol */

Please move the comment inside the if and use curly brackets for the if since its statement is multi-line.

Quoted 5 lines
drivers/ata/pata_parport/pata_parport.c new file +5 -0
+		idr_for_each_entry(&parport_list, parport, port_num)
+			pi_init_one(parport, pr, -1, 0, -1);
+	mutex_unlock(&pi_mutex);
+
+	return 0;

drivers/ata/pata_parport/pata_parport.c line 593

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+}
+EXPORT_SYMBOL(pata_parport_register_driver);
+
+void pata_parport_unregister_driver(struct pi_protocol *pr)
+{
+	struct pi_protocol *pr_iter;
+	int id = -1;
+
+	mutex_lock(&pi_mutex);
+	idr_for_each_entry(&protocols, pr_iter, id)

Add curly brackets.

drivers/ata/pata_parport/pata_parport.c line 598

Quoted 5 lines
drivers/ata/pata_parport/pata_parport.c new file +5 -0
+		if (pr_iter == pr)
+			break;
+	idr_remove(&protocols, id);
+	mutex_unlock(&pi_mutex);
+	pr_info("pata_parport: protocol %s removed\n", pr->name);

I do not think this message is needed.

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +11 -0
+	driver_unregister(&pr->driver);
+}
+EXPORT_SYMBOL(pata_parport_unregister_driver);
+
+static ssize_t new_device_store(struct bus_type *bus, const char *buf, size_t count)
+{
+	char port[12] = "auto";
+	char protocol[8] = "auto";
+	int mode = -1, unit = -1, delay = -1;
+	struct pi_protocol *pr, *pr_wanted;
+	struct device_driver *drv;

drivers/ata/pata_parport/pata_parport.c line 619

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	struct parport *parport;
+	int port_num, port_wanted, pr_num;
+	bool ok = false;
+
+	if (sscanf(buf, "%11s %7s %d %d %d",
+			port, protocol, &mode, &unit, &delay) < 1)
+		return -EINVAL;
+
+	if (sscanf(port, "parport%u", &port_wanted) < 1) {
+		if (!strcmp(port, "auto"))

Curly brackets please.

drivers/ata/pata_parport/pata_parport.c line 630

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +11 -0
+			port_wanted = -1;
+		else {
+			pr_err("invalid port name %s\n", port);
+			return -EINVAL;
+		}
+	}
+
+	drv = driver_find(protocol, &pata_parport_bus_type);
+	if (!drv) {
+		if (!strcmp(protocol, "auto"))
+			pr_wanted = NULL;

same.

drivers/ata/pata_parport/pata_parport.c line 636

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+		else {
+			pr_err("protocol %s not found\n", protocol);
+			return -EINVAL;
+		}
+	} else
+		pr_wanted = container_of(drv, struct pi_protocol, driver);

Here too.

drivers/ata/pata_parport/pata_parport.c line 649

Quoted 13 lines
drivers/ata/pata_parport/pata_parport.c new file +13 -0
+
+	mutex_lock(&pi_mutex);
+	/* walk all parports */
+	idr_for_each_entry(&parport_list, parport, port_num) {
+		if (port_num == port_wanted || port_wanted == -1) {
+			parport = parport_find_number(port_num);
+			if (!parport) {
+				pr_err("no such port %s\n", port);
+				mutex_unlock(&pi_mutex);
+				return -ENODEV;
+			}
+			/* walk all protocols */
+			idr_for_each_entry(&protocols, pr, pr_num)

Add curly brackets to this one too.

Quoted 57 lines
drivers/ata/pata_parport/pata_parport.c new file +57 -0
+				if (pr == pr_wanted || !pr_wanted)
+					if (pi_init_one(parport, pr, mode, unit,
+							delay))
+						ok = true;
+			parport_put_port(parport);
+		}
+	}
+	mutex_unlock(&pi_mutex);
+	if (!ok)
+		return -ENODEV;
+
+	return count;
+}
+static BUS_ATTR_WO(new_device);
+
+static void pi_remove_one(struct device *dev)
+{
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct pi_adapter *pi = host->private_data;
+
+	ata_host_detach(host);
+	del_timer_sync(&pi->timer);
+	pi_release(pi);
+	device_unregister(dev);
+	ida_free(&pata_parport_bus_dev_ids, dev->id);
+	/* pata_parport_dev_release will do kfree(pi) */
+}
+
+static ssize_t delete_device_store(struct bus_type *bus, const char *buf, size_t count)
+{
+	struct device *dev;
+	char device_name[32];
+	int fields;
+
+	fields = sscanf(buf, "%31s", device_name);
+	if (fields < 1)
+		return -EINVAL;
+
+	mutex_lock(&pi_mutex);
+	dev = bus_find_device_by_name(bus, NULL, device_name);
+	if (!dev) {
+		mutex_unlock(&pi_mutex);
+		return -ENODEV;
+	}
+
+	pi_remove_one(dev);
+	mutex_unlock(&pi_mutex);
+
+	return count;
+}
+static BUS_ATTR_WO(delete_device);
+
+static void pata_parport_attach(struct parport *port)
+{
+	struct pi_protocol *pr;
+	int pr_num, id;
+

drivers/ata/pata_parport/pata_parport.c line 716

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	mutex_lock(&pi_mutex);
+	id = idr_alloc(&parport_list, port, port->number, port->number, GFP_KERNEL);
+	if (id < 0) {
+		mutex_unlock(&pi_mutex);
+		return;
+	}
+
+	if (probe) /* probe this port using all protocols */
+		idr_for_each_entry(&protocols, pr, pr_num)
+			pi_init_one(port, pr, -1, 0, -1);

Curly brackets and comment under the if.

Quoted 33 lines
drivers/ata/pata_parport/pata_parport.c new file +33 -0
+	mutex_unlock(&pi_mutex);
+}
+
+static int pi_remove_port(struct device *dev, void *p)
+{
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct pi_adapter *pi = host->private_data;
+
+	if (pi->pardev->port == p)
+		pi_remove_one(dev);
+
+	return 0;
+}
+
+static void pata_parport_detach(struct parport *port)
+{
+	mutex_lock(&pi_mutex);
+	bus_for_each_dev(&pata_parport_bus_type, NULL, port, pi_remove_port);
+	idr_remove(&parport_list, port->number);
+	mutex_unlock(&pi_mutex);
+}
+
+static struct parport_driver pata_parport_driver = {
+	.name = DRV_NAME,
+	.match_port = pata_parport_attach,
+	.detach = pata_parport_detach,
+	.devmodel = true,
+};
+
+static __init int pata_parport_init(void)
+{
+	int error;
+

drivers/ata/pata_parport/pata_parport.c line 759

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	error = bus_register(&pata_parport_bus_type);
+	if (error) {
+		pr_err("failed to register pata_parport bus, error: %d\n", error);
+		return error;
+	}
+
+	error = device_register(&pata_parport_bus);
+	if (error) {
+		pr_err("failed to register pata_parport bus, error: %d\n", error);
+		return error;

Bug. This should not be here.

Quoted 56 lines
drivers/ata/pata_parport/pata_parport.c new file +50 -0
+		goto out_unregister_bus;
+	}
+
+	error = bus_create_file(&pata_parport_bus_type, &bus_attr_new_device);
+	if (error) {
+		pr_err("unable to create sysfs file, error: %d\n", error);
+		goto out_unregister_dev;
+	}
+
+	error = bus_create_file(&pata_parport_bus_type, &bus_attr_delete_device);
+	if (error) {
+		pr_err("unable to create sysfs file, error: %d\n", error);
+		goto out_remove_new;
+	}
+
+	error = parport_register_driver(&pata_parport_driver);
+	if (error) {
+		pr_err("unable to register parport driver, error: %d\n", error);
+		goto out_remove_del;
+	}
+
+	return 0;
+
+out_remove_del:
+	bus_remove_file(&pata_parport_bus_type, &bus_attr_delete_device);
+out_remove_new:
+	bus_remove_file(&pata_parport_bus_type, &bus_attr_new_device);
+out_unregister_dev:
+	device_unregister(&pata_parport_bus);
+out_unregister_bus:
+	bus_unregister(&pata_parport_bus_type);
+	return error;
+}
+
+static __exit void pata_parport_exit(void)
+{
+	parport_unregister_driver(&pata_parport_driver);
+	bus_remove_file(&pata_parport_bus_type, &bus_attr_new_device);
+	bus_remove_file(&pata_parport_bus_type, &bus_attr_delete_device);
+	device_unregister(&pata_parport_bus);
+	bus_unregister(&pata_parport_bus_type);
+}
+
+MODULE_AUTHOR("Ondrej Zary");
+MODULE_DESCRIPTION("driver for parallel port ATA adapters");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paride");
+
+module_init(pata_parport_init);
+module_exit(pata_parport_exit);
drivers/ata/pata_parport/pata_parport.h new file +0 -0
new file mode 100644
index 000000000000..c4201b809b20

drivers/ata/pata_parport/pata_parport.h line 6

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.h new file +6 -0
@@ -0,0 +1,110 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ *	paride.h	(c) 1997-8  Grant R. Guenther <[email protected]>
+ *				    Under the terms of the GPL.
+ *
+ * This file defines the interface for adapter chip drivers.

Which adapter ? "Parallel port IDE adapter chip", no ?

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.h new file +6 -0
+ */
+
+#include <linux/libata.h>
+
+struct pi_adapter {
+	struct device dev;

drivers/ata/pata_parport/pata_parport.h line 22

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.h new file +10 -0
+	struct pi_protocol *proto;	/* adapter protocol */
+	int port;			/* base address of parallel port */
+	int mode;			/* transfer mode in use */
+	int delay;			/* adapter delay setting */
+	int unit;			/* unit number for chained adapters */
+	int saved_r0;			/* saved port state */
+	int saved_r2;			/* saved port state */
+	unsigned long private;		/* for protocol module */
+	struct pardevice *pardev;	/* pointer to pardevice */
+	int claimed;			/* parport has already been claimed */

Make this a bool ?

Quoted 20 lines
drivers/ata/pata_parport/pata_parport.h new file +20 -0
+	struct timer_list timer;	/* disconnect timer */
+};
+
+/* registers are addressed as (cont,regr)
+ *	cont: 0 for command register file, 1 for control register(s)
+ *	regr: 0-7 for register number.
+ */
+
+/* macros and functions exported to the protocol modules */
+#define delay_p			(pi->delay ? udelay(pi->delay) : (void)0)
+#define out_p(offs, byte)	do { outb(byte, pi->port + offs); delay_p; } while (0)
+#define in_p(offs)		(delay_p, inb(pi->port + offs))
+
+#define w0(byte)		out_p(0, byte)
+#define r0()			(in_p(0) & 0xff)
+#define w1(byte)		out_p(1, byte)
+#define r1()			(in_p(1) & 0xff)
+#define w2(byte)		out_p(2, byte)
+#define r2()			(in_p(2) & 0xff)
+#define w3(byte)		out_p(3, byte)
Quoted 8 lines

drivers/ata/pata_parport/pata_parport.h line 48

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.h new file +6 -0
+#define w4(byte)		out_p(4, byte)
+#define r4()			(in_p(4) & 0xff)
+#define w4w(data)		do { outw(data, pi->port + 4); delay_p; } while (0)
+#define w4l(data)		do { outl(data, pi->port + 4); delay_p; } while (0)
+#define r4w()			(delay_p, inw(pi->port + 4) & 0xffff)
+#define r4l()			(delay_p, inl(pi->port + 4) & 0xffffffff)

Why not align this with the others ?

It's aligned properly in the file, only looks bad in a diff.

Quoted 58 lines
Quoted 16 lines
drivers/ata/pata_parport/pata_parport.h new file +16 -0
+
+static inline u16 pi_swab16(char *b, int k)
+{
+	union { u16 u; char t[2]; } r;
+
+	r.t[0] = b[2 * k + 1]; r.t[1] = b[2 * k];
+	return r.u;
+}
+
+static inline u32 pi_swab32(char *b, int k)
+{
+	union { u32 u; char f[4]; } r;
+
+	r.f[0] = b[4 * k + 1]; r.f[1] = b[4 * k];
+	r.f[2] = b[4 * k + 3]; r.f[3] = b[4 * k + 2];
+	return r.u;

drivers/ata/pata_parport/pata_parport.h line 74

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.h new file +10 -0
+}
+
+struct pi_protocol {
+	char name[8];		/* name for this protocol */
+
+	int max_mode;		/* max mode number */
+	int epp_first;		/* modes >= this use 8 ports */
+
+	int default_delay;	/* delay parameter if not specified */
+	int max_units;		/* max chained units probed for */

Except maybe epp_first, I find the comments for these fields useless: no information added.

Quoted 15 lines
drivers/ata/pata_parport/pata_parport.h new file +15 -0
+
+	void (*write_regr)(struct pi_adapter *pi, int cont, int regr, int val);
+	int (*read_regr)(struct pi_adapter *pi, int cont, int regr);
+	void (*write_block)(struct pi_adapter *pi, char *buf, int count);
+	void (*read_block)(struct pi_adapter *pi, char *buf, int count);
+
+	void (*connect)(struct pi_adapter *pi);
+	void (*disconnect)(struct pi_adapter *pi);
+
+	int (*test_port)(struct pi_adapter *pi);
+	int (*probe_unit)(struct pi_adapter *pi);
+	int (*test_proto)(struct pi_adapter *pi, char *scratch, int verbose);
+	void (*log_adapter)(struct pi_adapter *pi, char *scratch, int verbose);
+
+	int (*init_proto)(struct pi_adapter *pi);

drivers/ata/pata_parport/pata_parport.h line 99

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.h new file +10 -0
+	void (*release_proto)(struct pi_adapter *pi);
+	struct module *owner;
+	struct device_driver driver;
+	struct scsi_host_template sht;
+};
+
+#define PATA_PARPORT_SHT ATA_PIO_SHT
+
+extern int pata_parport_register_driver(struct pi_protocol *pr);
+extern void pata_parport_unregister_driver(struct pi_protocol *pr);

No need for extern.

Quoted 13 lines

drivers/ata/pata_parport/pata_parport.h line 110

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.h new file +11 -0
+
+/**
+ * module_pata_parport_driver() - Helper macro for registering a pata_parport driver
+ * @__pi_protocol: pi_protocol struct
+ *
+ * Helper macro for pata_parport drivers which do not do anything special in module
+ * init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_pata_parport_driver(__pi_protocol) \
+	module_driver(__pi_protocol, pata_parport_register_driver, pata_parport_unregister_driver)

Make this a static inline ?

It's a macro that expands to other macro (defined in include/linux/device/driver.h) that expands to __init and __exit functions, module_init() and module_exit() so we can use:

module_pata_parport_driver(on26);

instead of:

static int __init on26_init(void)

{
	return pata_parport_register_driver(&on26);
}

static void __exit on26_exit(void)

{
	pata_parport_unregister_driver(&on26);
}

module_init(on26_init)
module_exit(on26_exit)

Signature · 1 line
Ondrej Zary
#4 lore raw

Re: [PATCH 01/16] pata_parport: add core driver (PARIDE replacement)

Quoted 10 lines · Ondrej Zary
Quoted 9 lines

drivers/ata/pata_parport/pata_parport.c line 20

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+module_param(probe, bool, 0644);
+MODULE_PARM_DESC(probe, "Enable automatic device probing (0=off, 1=on [default])");
+
+static bool verbose;
+module_param(verbose, bool, 0644);
+MODULE_PARM_DESC(verbose, "Enable verbose messages (0=off [default], 1=on)");

Is this really necessary ? pr_debug() and all ata_xxx_debug() functions can be enabled dynamically.

Quoted 2 lines

The verbose messages are for adapter chip detection. That happens before the ata host is registered.

Sure. But you can still use pr_debug(). So instead of

if (verbose)

	dev_info();

simply use:

dev_dbg()

And these calls can be enabled with the standard dynamic debug control.

Quoted 31 lines
Quoted 13 lines

drivers/ata/pata_parport/pata_parport.c line 28

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.c new file +8 -0
+
+#define DISCONNECT_TIMEOUT	(HZ / 10)
+
+static void pi_connect(struct pi_adapter *pi)
+{
+	del_timer_sync(&pi->timer);
+	if (pi->claimed)
+		return;

Nit: I would reverse the condition to avoid the return. Or add a block line to separate the following hunk. Better readability this way, I think.

Quoted 13 lines

drivers/ata/pata_parport/pata_parport.c line 37

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.c new file +9 -0
+	pi->claimed = 1;
+	parport_claim_or_block(pi->pardev);
+	pi->proto->connect(pi);
+}
+
+static void pi_disconnect_later(struct pi_adapter *pi)
+{
+	mod_timer(&pi->timer, jiffies + DISCONNECT_TIMEOUT);
+}

Is this really needed ? Not sure it helps in any way. At least the name should be changed to reflect what this does. May be something like pi_start_disconnect_timeout() ?

Disconnect needs to happen after end of an operation so the parport is freed for device(s) (like a printer) connected to pass-through port of a paride device. There could be even multiple paride devices chained on one parport.

Quoted 6 lines

Disconnecting immediately at the end of each function does not work (probably breaks the protocol?)

The old high-level drivers (pd, pf...) did connect and disconnect manually on each operation (command or data transfer) but it does not seem to be possible with libata.

I am not questioning how you handle the disconnect. I was only commenting that the inline function may not be that usefull and you could simply directly use the mod_timer() calls directly.

or

rename pi_disconnect_later() to something that better explains what the function does.

Quoted 61 lines
Quoted 11 lines

drivers/ata/pata_parport/pata_parport.c line 44

Quoted 8 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+
+static void pi_disconnect_timer(struct timer_list *t)
+{
+	struct pi_adapter *pi = from_timer(pi, t, timer);
+
+	if (!pi->claimed)
+		return;

A blank line here would be nice for readability.

Quoted 9 lines

drivers/ata/pata_parport/pata_parport.c line 51

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+	pi->proto->disconnect(pi);
+	parport_release(pi->pardev);
+	pi->claimed = 0;
+}
+
+/* functions taken from libata-sff.c and converted from direct port I/O */
+static unsigned int pata_parport_devchk(struct ata_port *ap, unsigned int device)

Should this be a bool function ?

I don't know. It's copied from libata-sff.c

Quoted 29 lines
Quoted 29 lines
drivers/ata/pata_parport/pata_parport.c new file +29 -0
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	u8 nsect, lbal;
+
+	ap->ops->sff_dev_select(ap, device);
+
+	pi_connect(pi);
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 0x55);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0xaa);
+
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 0xaa);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0x55);
+
+	pi->proto->write_regr(pi, 0, ATA_REG_NSECT, 055);
+	pi->proto->write_regr(pi, 0, ATA_REG_LBAL, 0xaa);
+
+	nsect = pi->proto->read_regr(pi, 0, ATA_REG_NSECT);
+	lbal = pi->proto->read_regr(pi, 0, ATA_REG_LBAL);
+	pi_disconnect_later(pi);
+
+	if ((nsect == 0x55) && (lbal == 0xaa))
+		return 1;	/* we found a device */
+
+	return 0;		/* nothing found */
+}
+
+static int pata_parport_bus_softreset(struct ata_port *ap, unsigned int devmask,
+				      unsigned long deadline)
+{
Quoted 8 lines

drivers/ata/pata_parport/pata_parport.c line 86

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	/* software reset.  causes dev0 to be selected */
+	pi->proto->write_regr(pi, 1, 6, ap->ctl);
+	udelay(20);	/* FIXME: flush */

Then please fix it.

Quoted 1 line

I don't know what that means. It's copied from libata-sff.c

OK. Will have a look there too.

Quoted 98 lines
Quoted 89 lines

drivers/ata/pata_parport/pata_parport.c line 88

Quoted 3 lines
drivers/ata/pata_parport/pata_parport.c new file +2 -0
+	pi->proto->write_regr(pi, 1, 6, ap->ctl | ATA_SRST);
+	udelay(20);	/* FIXME: flush */

Here too.

Quoted 19 lines
drivers/ata/pata_parport/pata_parport.c new file +19 -0
+	pi->proto->write_regr(pi, 1, 6, ap->ctl);
+	ap->last_ctl = ap->ctl;
+	pi_disconnect_later(pi);
+
+	/* wait the port to become ready */
+	return ata_sff_wait_after_reset(&ap->link, devmask, deadline);
+}
+
+static int pata_parport_softreset(struct ata_link *link, unsigned int *classes,
+				  unsigned long deadline)
+{
+	struct ata_port *ap = link->ap;
+	unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
+	unsigned int devmask = 0;
+	int rc;
+	u8 err;
+
+	/* determine if device 0/1 are present */
+	if (pata_parport_devchk(ap, 0))

drivers/ata/pata_parport/pata_parport.c line 117

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+		devmask |= (1 << 0);
+	if (slave_possible && pata_parport_devchk(ap, 1))
+		devmask |= (1 << 1);
+
+	/* select device 0 again */
+	ap->ops->sff_dev_select(ap, 0);
+
+	/* issue bus reset */
+	rc = pata_parport_bus_softreset(ap, devmask, deadline);
+	/* if link is occupied, -ENODEV too is an error */

Please merge this comment with the one above. That will make the code more readable (I know this is the style used by many drivers, but let's not repeat the weird style :)).

Quoted 49 lines
drivers/ata/pata_parport/pata_parport.c new file +49 -0
+	if (rc && (rc != -ENODEV || sata_scr_valid(link))) {
+		ata_link_err(link, "SRST failed (errno=%d)\n", rc);
+		return rc;
+	}
+
+	/* determine by signature whether we have ATA or ATAPI devices */
+	classes[0] = ata_sff_dev_classify(&link->device[0],
+					  devmask & (1 << 0), &err);
+	if (slave_possible && err != 0x81)
+		classes[1] = ata_sff_dev_classify(&link->device[1],
+						  devmask & (1 << 1), &err);
+
+	return 0;
+}
+
+static u8 pata_parport_check_status(struct ata_port *ap)
+{
+	u8 status;
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	status = pi->proto->read_regr(pi, 0, ATA_REG_STATUS);
+	pi_disconnect_later(pi);
+
+	return status;
+}
+
+static u8 pata_parport_check_altstatus(struct ata_port *ap)
+{
+	u8 altstatus;
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	altstatus = pi->proto->read_regr(pi, 1, 6);
+	pi_disconnect_later(pi);
+
+	return altstatus;
+}
+
+static void pata_parport_dev_select(struct ata_port *ap, unsigned int device)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	u8 tmp;
+
+	pi_connect(pi);
+	if (device == 0)
+		tmp = ATA_DEVICE_OBS;
+	else
+		tmp = ATA_DEVICE_OBS | ATA_DEV1;
Quoted 8 lines

drivers/ata/pata_parport/pata_parport.c line 170

Quoted 4 lines
drivers/ata/pata_parport/pata_parport.c new file +4 -0
+
+	pi->proto->write_regr(pi, 0, ATA_REG_DEVICE, tmp);
+	pi_disconnect_later(pi);
+	ata_sff_pause(ap);	/* needed; also flushes, for mmio */

The comment does not parse... Why is it needed ?
And pleasde move the comment above the call, with a blank line separating it from the previous lines.

Quoted 1 line

I don't know. It's copied from libata-sff.c

Drop the comment then.

Quoted 28 lines
Quoted 28 lines
Quoted 14 lines
drivers/ata/pata_parport/pata_parport.c new file +13 -0
+}
+
+static void pata_parport_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
+
+	pi_connect(pi);
+	if (tf->ctl != ap->last_ctl) {
+		pi->proto->write_regr(pi, 1, 6, tf->ctl);
+		ap->last_ctl = tf->ctl;
+		ata_wait_idle(ap);
+	}

drivers/ata/pata_parport/pata_parport.c line 193

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+
+	if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
+		pi->proto->write_regr(pi, 0, ATA_REG_FEATURE, tf->hob_feature);
+		pi->proto->write_regr(pi, 0, ATA_REG_NSECT, tf->hob_nsect);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAL, tf->hob_lbal);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAM, tf->hob_lbam);
+		pi->proto->write_regr(pi, 0, ATA_REG_LBAH, tf->hob_lbah);
+	}
+
+	if (is_addr) {

Move this if above the previous one. Doing so, you can remove the need for is_addr var and simplify the previous if condition.

Quoted 4 lines
Quoted 2 lines

That said, many pata drivers check that flag but it is always set by libata core. So checking it seems useless. Need to dig into this.

It's copied from libata-sff.c which is almost libata core.

Yes. Saw the same pattern in different drivers. Need to figure out what is going on here. That flag really seem totally useless. Will check. Keep the flag use for now, but at least rewrite as suggested to avoid the need for that is_addr variable.

Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/ata/pata_parport/pata_parport.h new file +20 -0
+	struct timer_list timer;	/* disconnect timer */
+};
+
+/* registers are addressed as (cont,regr)
+ *	cont: 0 for command register file, 1 for control register(s)
+ *	regr: 0-7 for register number.
+ */
+
+/* macros and functions exported to the protocol modules */
+#define delay_p			(pi->delay ? udelay(pi->delay) : (void)0)
+#define out_p(offs, byte)	do { outb(byte, pi->port + offs); delay_p; } while (0)
+#define in_p(offs)		(delay_p, inb(pi->port + offs))
+
+#define w0(byte)		out_p(0, byte)
+#define r0()			(in_p(0) & 0xff)
+#define w1(byte)		out_p(1, byte)
+#define r1()			(in_p(1) & 0xff)
+#define w2(byte)		out_p(2, byte)
+#define r2()			(in_p(2) & 0xff)
+#define w3(byte)		out_p(3, byte)
Quoted 8 lines

drivers/ata/pata_parport/pata_parport.h line 48

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.h new file +6 -0
+#define w4(byte)		out_p(4, byte)
+#define r4()			(in_p(4) & 0xff)
+#define w4w(data)		do { outw(data, pi->port + 4); delay_p; } while (0)
+#define w4l(data)		do { outl(data, pi->port + 4); delay_p; } while (0)
+#define r4w()			(delay_p, inw(pi->port + 4) & 0xffff)
+#define r4l()			(delay_p, inl(pi->port + 4) & 0xffffffff)

Why not align this with the others ?

Quoted 2 lines

It's aligned properly in the file, only looks bad in a diff.

OK.

Quoted 27 lines
Quoted 5 lines
Quoted 5 lines
drivers/ata/pata_parport/pata_parport.h new file +5 -0
+
+/**
+ * module_pata_parport_driver() - Helper macro for registering a pata_parport driver
+ * @__pi_protocol: pi_protocol struct
+ *
Quoted 8 lines

drivers/ata/pata_parport/pata_parport.h line 110

Quoted 6 lines

+ * Helper macro for pata_parport drivers which do not do anything special in module
+ * init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */

drivers/ata/pata_parport/pata_parport.h new file +2 -0
+#define module_pata_parport_driver(__pi_protocol) \
+	module_driver(__pi_protocol, pata_parport_register_driver, pata_parport_unregister_driver)

Make this a static inline ?

It's a macro that expands to other macro (defined in include/linux/device/driver.h) that expands to __init and __exit functions, module_init() and module_exit() so we can use:

module_pata_parport_driver(on26);

instead of:

static int __init on26_init(void)

{
	return pata_parport_register_driver(&on26);
}
Quoted 7 lines

static void __exit on26_exit(void)

{
	pata_parport_unregister_driver(&on26);
}

module_init(on26_init)
module_exit(on26_exit)

OK.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#5 lore raw

Re: [PATCH 01/16] pata_parport: add core driver (PARIDE replacement)

In reply to Ondrej Zary

Hello!

Quoted 10 lines · Ondrej Zary

Add pata_parport (PARIDE replacement) core libata driver.

---
 drivers/ata/Kconfig                     |  25 +
 drivers/ata/Makefile                    |   2 +
 drivers/ata/pata_parport/Kconfig        |  10 +
 drivers/ata/pata_parport/Makefile       |   9 +
 drivers/ata/pata_parport/pata_parport.c | 809 ++++++++++++++++++++++++
 drivers/ata/pata_parport/pata_parport.h | 110 ++++

I'd like to suggest to just name the new subdirectory 'parport'.
And it looks like I'll need to update my MAINTAINBERS entry to include this driver... :-)

[...]

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +0 -0
new file mode 100644
index 000000000000..7f814062cedd
@@ -0,0 +1,809 @@

[...]

Quoted 1 line

+static bool probe = 1;

s/1/true/.

[...]

drivers/ata/pata_parport/pata_parport.c line 51

Quoted 2 lines
drivers/ata/pata_parport/pata_parport.c new file +2 -0
+/* functions taken from libata-sff.c and converted from direct port I/O */
+static unsigned int pata_parport_devchk(struct ata_port *ap, unsigned int device)

Should return bool now, see e.g..:

https://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata.git/commit/?h=for-next&id=1336aa88d8553292604878c53538297fbc65bf0a

drivers/ata/pata_parport/pata_parport.c line 56

Quoted 5 lines
drivers/ata/pata_parport/pata_parport.c new file +5 -0
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	u8 nsect, lbal;
+
+	ap->ops->sff_dev_select(ap, device);

Could call your sff-dev_select() methid directly here?

[...]

drivers/ata/pata_parport/pata_parport.c line 86

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.c new file +9 -0
+static int pata_parport_bus_softreset(struct ata_port *ap, unsigned int devmask,
+				      unsigned long deadline)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	/* software reset.  causes dev0 to be selected */
+	pi->proto->write_regr(pi, 1, 6, ap->ctl);
+	udelay(20);	/* FIXME: flush */

I don't think this FIXME applies to your driver...

[...]

drivers/ata/pata_parport/pata_parport.c line 101

Quoted 5 lines
drivers/ata/pata_parport/pata_parport.c new file +5 -0
+static int pata_parport_softreset(struct ata_link *link, unsigned int *classes,
+				  unsigned long deadline)
+{
+	struct ata_port *ap = link->ap;
+	unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;

Isn't this flag always set in your driver?

drivers/ata/pata_parport/pata_parport.c line 113

Quoted 12 lines
drivers/ata/pata_parport/pata_parport.c new file +12 -0
+	unsigned int devmask = 0;
+	int rc;
+	u8 err;
+
+	/* determine if device 0/1 are present */
+	if (pata_parport_devchk(ap, 0))
+		devmask |= (1 << 0);
+	if (slave_possible && pata_parport_devchk(ap, 1))
+		devmask |= (1 << 1);
+
+	/* select device 0 again */
+	ap->ops->sff_dev_select(ap, 0);

Again, could you call this directly?

drivers/ata/pata_parport/pata_parport.c line 118

Quoted 5 lines
drivers/ata/pata_parport/pata_parport.c new file +5 -0
+
+	/* issue bus reset */
+	rc = pata_parport_bus_softreset(ap, devmask, deadline);
+	/* if link is occupied, -ENODEV too is an error */
+	if (rc && (rc != -ENODEV || sata_scr_valid(link))) {

It's a PATA driver, why call sata_scr_valid() at all?

[...]

drivers/ata/pata_parport/pata_parport.c line 162

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+static void pata_parport_dev_select(struct ata_port *ap, unsigned int device)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+	u8 tmp;
+
+	pi_connect(pi);

Why not call it after this *if*?

drivers/ata/pata_parport/pata_parport.c line 170

Quoted 8 lines
drivers/ata/pata_parport/pata_parport.c new file +8 -0
+	if (device == 0)
+		tmp = ATA_DEVICE_OBS;
+	else
+		tmp = ATA_DEVICE_OBS | ATA_DEV1;
+
+	pi->proto->write_regr(pi, 0, ATA_REG_DEVICE, tmp);
+	pi_disconnect_later(pi);
+	ata_sff_pause(ap);	/* needed; also flushes, for mmio */

Does this comment make sense in your driver?

[...]

drivers/ata/pata_parport/pata_parport.c line 213

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+static void pata_parport_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
+{
+	struct pi_adapter *pi = ap->host->private_data;
+
+	pi_connect(pi);
+	tf->command = pi->proto->read_regr(pi, 0, ATA_REG_STATUS);

Use tf->status please, see:

https://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata.git/commit/?h=for-next&id=efcef265fd83d9a68a68926abecb3e1dd3e260a8

drivers/ata/pata_parport/pata_parport.c line 214

Quoted 1 line
drivers/ata/pata_parport/pata_parport.c new file +1 -0
+	tf->feature = pi->proto->read_regr(pi, 0, ATA_REG_ERR);

Use tf->error as well please.

[...]

Quoted 12 lines
drivers/ata/pata_parport/pata_parport.c new file +12 -0
+static void pata_parport_lost_interrupt(struct ata_port *ap)
+{
+	u8 status;
+	struct ata_queued_cmd *qc;
+
+	/* Only one outstanding command per SFF channel */
+	qc = ata_qc_from_tag(ap, ap->link.active_tag);
+	/* We cannot lose an interrupt on a non-existent or polled command */
+	if (!qc || qc->tf.flags & ATA_TFLAG_POLLING)
+		return;
+	/* See if the controller thinks it is still busy - if so the command
+	   isn't a lost IRQ but is still in progress */

drivers/ata/pata_parport/pata_parport.c line 306

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	status = pata_parport_check_altstatus(ap);
+	if (status & ATA_BUSY)
+		return;
+
+	/* There was a command running, we are no longer busy and we have
+	   no interrupt. */
+	ata_port_warn(ap, "lost interrupt (Status 0x%x)\n", status);
+	/* Run the host interrupt logic as if the interrupt had not been lost */
+	ata_sff_port_intr(ap, qc);
+}

Hm, it looks like ata_sff_lost_interrupt() could be used instead...

drivers/ata/pata_parport/pata_parport.c line 308

Quoted 2 lines
drivers/ata/pata_parport/pata_parport.c new file +2 -0
+
+static struct ata_port_operations pata_parport_port_ops = {

Maybe inherit from ata_sff_port_ops?

[...]

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+static int default_test_proto(struct pi_adapter *pi, char *scratch)
+{
+	int j, k;
+	int e[2] = { 0, 0 };
+
+	pi->proto->connect(pi);
+
+	for (j = 0; j < 2; j++) {
+		pi->proto->write_regr(pi, 0, 6, 0xa0 + j * 0x10);
+		for (k = 0; k < 256; k++) {

drivers/ata/pata_parport/pata_parport.c line 368

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+			pi->proto->write_regr(pi, 0, 2, k ^ 0xaa);
+			pi->proto->write_regr(pi, 0, 3, k ^ 0x55);
+			if (pi->proto->read_regr(pi, 0, 2) != (k ^ 0xaa))
+				e[j]++;
+		}
+	}
+	pi->proto->disconnect(pi);
+
+	if (verbose)
+		dev_info(&pi->dev, "%s: port 0x%x, mode  %d, test=(%d,%d)\n",

Whyu 2 spaces after "mode"?

drivers/ata/pata_parport/pata_parport.c line 372

Quoted 4 lines
drivers/ata/pata_parport/pata_parport.c new file +4 -0
+		       pi->proto->name, pi->port,
+		       pi->mode, e[0], e[1]);
+
+	return (e[0] && e[1]);	/* not here if both > 0 */

No need for parens.

Quoted 1 line

+}

This function kinda duplicates pata_parport_devchk()? :-)

[...]

drivers/ata/pata_parport/pata_parport.c line 399

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +11 -0
+static int pi_probe_mode(struct pi_adapter *pi, int max, char *scratch)
+{
+	int best, range;
+
+	if (pi->mode != -1) {
+		if (pi->mode >= max)
+			return 0;
+		range = 3;
+		if (pi->mode >= pi->proto->epp_first)
+			range = 8;
+		if ((range == 8) && (pi->port % 8))

No need for inner parens...

drivers/ata/pata_parport/pata_parport.c

Quoted 2 lines
drivers/ata/pata_parport/pata_parport.c new file +2 -0
+			return 0;
+		return (!pi_test_proto(pi, scratch));

No need for outer parens, this time... :-)

drivers/ata/pata_parport/pata_parport.c line 408

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.c new file +7 -0
+	}
+	best = -1;
+	for (pi->mode = 0; pi->mode < max; pi->mode++) {
+		range = 3;
+		if (pi->mode >= pi->proto->epp_first)
+			range = 8;
+		if ((range == 8) && (pi->port % 8))

No need for inner parens...

drivers/ata/pata_parport/pata_parport.c line 414

Quoted 6 lines
drivers/ata/pata_parport/pata_parport.c new file +6 -0
+			break;
+		if (!pi_test_proto(pi, scratch))
+			best = pi->mode;
+	}
+	pi->mode = best;
+	return (best > -1);

No need for parens...

drivers/ata/pata_parport/pata_parport.c line 38

Quoted 3 lines
drivers/ata/pata_parport/pata_parport.c new file +3 -0
+}
+
+

Isn't one empty line enough?

Quoted 1 line

+static int pi_probe_unit(struct pi_adapter *pi, int unit, char *scratch)

Looks like it's worth making this function return bool?

[...]

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.c new file +9 -0
+static ssize_t new_device_store(struct bus_type *bus, const char *buf, size_t count)
+{
+	char port[12] = "auto";
+	char protocol[8] = "auto";
+	int mode = -1, unit = -1, delay = -1;
+	struct pi_protocol *pr, *pr_wanted;
+	struct device_driver *drv;
+	struct parport *parport;
+	int port_num, port_wanted, pr_num;

drivers/ata/pata_parport/pata_parport.c line 621

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+	bool ok = false;
+
+	if (sscanf(buf, "%11s %7s %d %d %d",
+			port, protocol, &mode, &unit, &delay) < 1)
+		return -EINVAL;
+
+	if (sscanf(port, "parport%u", &port_wanted) < 1) {
+		if (!strcmp(port, "auto"))
+			port_wanted = -1;
+		else {

Need {} on both branches.

drivers/ata/pata_parport/pata_parport.c line 631

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+			pr_err("invalid port name %s\n", port);
+			return -EINVAL;
+		}
+	}
+
+	drv = driver_find(protocol, &pata_parport_bus_type);
+	if (!drv) {
+		if (!strcmp(protocol, "auto"))
+			pr_wanted = NULL;
+		else {

Same here.

drivers/ata/pata_parport/pata_parport.c line 635

Quoted 4 lines
drivers/ata/pata_parport/pata_parport.c new file +4 -0
+			pr_err("protocol %s not found\n", protocol);
+			return -EINVAL;
+		}
+	} else

And here.

Quoted 1 line
drivers/ata/pata_parport/pata_parport.c new file +1 -0
+		pr_wanted = container_of(drv, struct pi_protocol, driver);

[...]

drivers/ata/pata_parport/pata_parport.c line 685

Quoted 8 lines
drivers/ata/pata_parport/pata_parport.c new file +8 -0
+static ssize_t delete_device_store(struct bus_type *bus, const char *buf, size_t count)
+{
+	struct device *dev;
+	char device_name[32];
+	int fields;
+
+	fields = sscanf(buf, "%31s", device_name);
+	if (fields < 1)

Strange variable name where you expect only one field... And you don't even
use it after this check, so hardly needed at all...

[...]

drivers/ata/pata_parport/pata_parport.h line 3

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.h new file +3 -0
new file mode 100644
index 000000000000..c4201b809b20
@@ -0,0 +1,110 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ *	paride.h	(c) 1997-8  Grant R. Guenther <[email protected]>

Doesn't match the file name anymore...

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.h new file +9 -0
+ *				    Under the terms of the GPL.
+ *
+ * This file defines the interface for adapter chip drivers.
+ */
+
+#include <linux/libata.h>
+
+struct pi_adapter {
+	struct device dev;

drivers/ata/pata_parport/pata_parport.h line 22

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.h new file +10 -0
+	struct pi_protocol *proto;	/* adapter protocol */
+	int port;			/* base address of parallel port */
+	int mode;			/* transfer mode in use */
+	int delay;			/* adapter delay setting */
+	int unit;			/* unit number for chained adapters */
+	int saved_r0;			/* saved port state */
+	int saved_r2;			/* saved port state */
+	unsigned long private;		/* for protocol module */
+	struct pardevice *pardev;	/* pointer to pardevice */
+	int claimed;			/* parport has already been claimed */

Use bool instead?

drivers/ata/pata_parport/pata_parport.h line 34

Quoted 12 lines
drivers/ata/pata_parport/pata_parport.h new file +12 -0
+	struct timer_list timer;	/* disconnect timer */
+};
+
+/* registers are addressed as (cont,regr)
+ *	cont: 0 for command register file, 1 for control register(s)
+ *	regr: 0-7 for register number.
+ */
+
+/* macros and functions exported to the protocol modules */
+#define delay_p			(pi->delay ? udelay(pi->delay) : (void)0)
+#define out_p(offs, byte)	do { outb(byte, pi->port + offs); delay_p; } while (0)
+#define in_p(offs)		(delay_p, inb(pi->port + offs))

Hm, why not pass pi as an extra parameter?

drivers/ata/pata_parport/pata_parport.h line 37

Quoted 3 lines
drivers/ata/pata_parport/pata_parport.h new file +3 -0
+
+#define w0(byte)		out_p(0, byte)
+#define r0()			(in_p(0) & 0xff)

Why mask the result of inb()?

drivers/ata/pata_parport/pata_parport.h line 48

Quoted 11 lines
drivers/ata/pata_parport/pata_parport.h new file +11 -0
+#define w1(byte)		out_p(1, byte)
+#define r1()			(in_p(1) & 0xff)
+#define w2(byte)		out_p(2, byte)
+#define r2()			(in_p(2) & 0xff)
+#define w3(byte)		out_p(3, byte)
+#define w4(byte)		out_p(4, byte)
+#define r4()			(in_p(4) & 0xff)
+#define w4w(data)		do { outw(data, pi->port + 4); delay_p; } while (0)
+#define w4l(data)		do { outl(data, pi->port + 4); delay_p; } while (0)
+#define r4w()			(delay_p, inw(pi->port + 4) & 0xffff)
+#define r4l()			(delay_p, inl(pi->port + 4) & 0xffffffff)

Again, why mask these?

drivers/ata/pata_parport/pata_parport.h line 55

Quoted 7 lines
drivers/ata/pata_parport/pata_parport.h new file +7 -0
+
+static inline u16 pi_swab16(char *b, int k)
+{
+	union { u16 u; char t[2]; } r;
+
+	r.t[0] = b[2 * k + 1]; r.t[1] = b[2 * k];
+	return r.u;

Hm, swab16() instead?

drivers/ata/pata_parport/pata_parport.h line 64

Quoted 9 lines
drivers/ata/pata_parport/pata_parport.h new file +9 -0
+}
+
+static inline u32 pi_swab32(char *b, int k)
+{
+	union { u32 u; char f[4]; } r;
+
+	r.f[0] = b[4 * k + 1]; r.f[1] = b[4 * k];
+	r.f[2] = b[4 * k + 3]; r.f[3] = b[4 * k + 2];
+	return r.u;

And swab32() here instead?

drivers/ata/pata_parport/pata_parport.h line 65

Quoted 1 line
drivers/ata/pata_parport/pata_parport.h new file +1 -0
+}

[...]

MNR, Sergey

#6 lore raw

Re: [PATCH 01/16] pata_parport: add core driver (PARIDE replacement)

In reply to Ondrej Zary
Quoted 11 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+
+static void pata_parport_dev_release(struct device *dev)
+{
+	struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev);
+
+	kfree(pi);
+}
 
+void pata_parport_bus_release(struct device *dev)
+{
+	/* nothing to do here but required to avoid warning on device removal */

drivers/ata/pata_parport/pata_parport.c line 474

Quoted 10 lines
drivers/ata/pata_parport/pata_parport.c new file +10 -0
+}
+
+static struct bus_type pata_parport_bus_type = {
+	.name = DRV_NAME,
+};
+
+static struct device pata_parport_bus = {
+	.init_name = DRV_NAME,
+	.release = pata_parport_bus_release,
+};

Hmm, wouldn't it make sense to let the libata device hang off the device in struct pardevice?

#7 lore raw

Re: [PATCH 01/16] pata_parport: add core driver (PARIDE replacement)

In reply to Ondrej Zary
Thank you for the patch! Perhaps something to improve:

Hi Ondrej,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on hch-configfs/for-next]
[also build test WARNING on linux/master linus/master v5.17-rc7 next-20220308] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ondrej-Zary/pata_parport-add-core-driver-PARIDE-replacement/20220307-142912
base:   git://git.infradead.org/users/hch/configfs.git for-next
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20220309/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/05539e2a04721c2710e7d1f6ae49926474bdf918
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ondrej-Zary/pata_parport-add-core-driver-PARIDE-replacement/20220307-142912 git checkout 05539e2a04721c2710e7d1f6ae49926474bdf918
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=sh SHELL=/bin/bash drivers/ata/pata_parport/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/ata/pata_parport/pata_parport.c:341:6: warning: no previous prototype for 'pi_release' [-Wmissing-prototypes]
     341 | void pi_release(struct pi_adapter *pi)
         |      ^~~~~~~~~~
>> drivers/ata/pata_parport/pata_parport.c:462:6: warning: no previous prototype for 'pata_parport_bus_release' [-Wmissing-prototypes]
     462 | void pata_parport_bus_release(struct device *dev)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/ata/pata_parport/pata_parport.c:476:20: warning: no previous prototype for 'pi_init_one' [-Wmissing-prototypes]

476 | struct pi_adapter *pi_init_one(struct parport *parport, struct pi_protocol *pr,
| ^~~~~~~~~~~

vim +/pi_release +341 drivers/ata/pata_parport/pata_parport.c

340

 > 341	void pi_release(struct pi_adapter *pi)
   342	{
   343		parport_unregister_device(pi->pardev);
   344		if (pi->proto->release_proto)
   345			pi->proto->release_proto(pi);
   346		module_put(pi->proto->owner);
   347	}
   348	
   349	static int default_test_proto(struct pi_adapter *pi, char *scratch)
   350	{
   351		int j, k;
   352		int e[2] = { 0, 0 };
   353	
   354		pi->proto->connect(pi);
   355	
   356		for (j = 0; j < 2; j++) {
   357			pi->proto->write_regr(pi, 0, 6, 0xa0 + j * 0x10);
   358			for (k = 0; k < 256; k++) {
   359				pi->proto->write_regr(pi, 0, 2, k ^ 0xaa);
   360				pi->proto->write_regr(pi, 0, 3, k ^ 0x55);
   361				if (pi->proto->read_regr(pi, 0, 2) != (k ^ 0xaa))
   362					e[j]++;
   363			}
   364		}
   365		pi->proto->disconnect(pi);
   366	
   367		if (verbose)
   368			dev_info(&pi->dev, "%s: port 0x%x, mode  %d, test=(%d,%d)\n",
   369			       pi->proto->name, pi->port,
   370			       pi->mode, e[0], e[1]);
   371	
   372		return (e[0] && e[1]);	/* not here if both > 0 */
   373	}
   374	
   375	static int pi_test_proto(struct pi_adapter *pi, char *scratch)
   376	{
   377		int res;
   378	
   379		parport_claim_or_block(pi->pardev);
   380		if (pi->proto->test_proto)
   381			res = pi->proto->test_proto(pi, scratch, verbose);
   382		else
   383			res = default_test_proto(pi, scratch);
   384		parport_release(pi->pardev);
   385	
   386		return res;
   387	}
   388	
   389	static int pi_probe_mode(struct pi_adapter *pi, int max, char *scratch)
   390	{
   391		int best, range;
   392	
   393		if (pi->mode != -1) {
   394			if (pi->mode >= max)
   395				return 0;
   396			range = 3;
   397			if (pi->mode >= pi->proto->epp_first)
   398				range = 8;
   399			if ((range == 8) && (pi->port % 8))
   400				return 0;
   401			return (!pi_test_proto(pi, scratch));
   402		}
   403		best = -1;
   404		for (pi->mode = 0; pi->mode < max; pi->mode++) {
   405			range = 3;
   406			if (pi->mode >= pi->proto->epp_first)
   407				range = 8;
   408			if ((range == 8) && (pi->port % 8))
   409				break;
   410			if (!pi_test_proto(pi, scratch))
   411				best = pi->mode;
   412		}
   413		pi->mode = best;
   414		return (best > -1);
   415	}
   416	
   417	
   418	static int pi_probe_unit(struct pi_adapter *pi, int unit, char *scratch)
   419	{
   420		int max, s, e;
   421	
   422		s = unit;
   423		e = s + 1;
   424	
   425		if (s == -1) {
   426			s = 0;
   427			e = pi->proto->max_units;
   428		}
   429	
   430		if (pi->proto->test_port) {
   431			parport_claim_or_block(pi->pardev);
   432			max = pi->proto->test_port(pi);
   433			parport_release(pi->pardev);
   434		} else
   435			max = pi->proto->max_mode;
   436	
   437		if (pi->proto->probe_unit) {
   438			parport_claim_or_block(pi->pardev);
   439			for (pi->unit = s; pi->unit < e; pi->unit++)
   440				if (pi->proto->probe_unit(pi)) {
   441					parport_release(pi->pardev);
   442					if (pi_probe_mode(pi, max, scratch))
   443						return 1;
   444					return 0;
   445				}
   446			parport_release(pi->pardev);
   447			return 0;
   448		}
   449	
   450		if (!pi_probe_mode(pi, max, scratch))
   451			return 0;
   452		return 1;
   453	}
   454	
   455	static void pata_parport_dev_release(struct device *dev)
   456	{
   457		struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev);
   458	
   459		kfree(pi);
   460	}
   461	
 > 462	void pata_parport_bus_release(struct device *dev)
   463	{
   464		/* nothing to do here but required to avoid warning on device removal */
   465	}
   466	
   467	static struct bus_type pata_parport_bus_type = {
   468		.name = DRV_NAME,
   469	};
   470	
   471	static struct device pata_parport_bus = {
   472		.init_name = DRV_NAME,
   473		.release = pata_parport_bus_release,
   474	};
   475	
 > 476	struct pi_adapter *pi_init_one(struct parport *parport, struct pi_protocol *pr,

477 int mode, int unit, int delay)
478 {
479 struct pardev_cb par_cb = { };
480 char scratch[512];
481 const struct ata_port_info *ppi[] = { &pata_parport_port_info };
482 struct ata_host *host;
483 struct pi_adapter *pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL);
484
485 if (!pi)
486 return NULL;
487
488 /* set up pi->dev before pi_probe_unit() so it can use dev_printk() */
489 pi->dev.parent = &pata_parport_bus;
490 pi->dev.bus = &pata_parport_bus_type;
491 pi->dev.driver = &pr->driver;
492 pi->dev.release = pata_parport_dev_release;
493 pi->dev.id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
494 if (pi->dev.id < 0)
495 return NULL; /* pata_parport_dev_release will do kfree(pi) */
496 dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);
497 if (device_register(&pi->dev)) {
498 put_device(&pi->dev);
499 goto out_ida_free;
500 }
501
502 pi->proto = pr;
503
504 /* still racy */
505 if (!try_module_get(pi->proto->owner))
506 goto out_unreg_dev;
507 if (pi->proto->init_proto && pi->proto->init_proto(pi) < 0)
508 goto out_module_put;
509
510 pi->delay = (delay == -1) ? pi->proto->default_delay : delay;
511 pi->mode = mode;
512 pi->port = parport->base;
513
514 par_cb.private = pi;
515 pi->pardev = parport_register_dev_model(parport, dev_name(&pi->dev),
516 &par_cb, pi->dev.id);
517 if (!pi->pardev)
518 goto out_module_put;
519
520 if (!pi_probe_unit(pi, unit, scratch)) {
521 dev_info(&pi->dev, "Adapter not found\n");
522 goto out_unreg_parport;
523 }
524
525 pi->proto->log_adapter(pi, scratch, verbose);
526
527 host = ata_host_alloc_pinfo(&pi->dev, ppi, 1);
528 if (!host)
529 goto out_unreg_parport;
530 dev_set_drvdata(&pi->dev, host);
531 host->private_data = pi;
532
533 ata_port_desc(host->ports[0], "port %s", pi->pardev->port->name);
534 ata_port_desc(host->ports[0], "protocol %s", pi->proto->name);
535
536 timer_setup(&pi->timer, pi_disconnect_timer, 0);
537
538 if (ata_host_activate(host, 0, NULL, 0, &pi->proto->sht))
539 goto out_unreg_parport;
540
541 return pi;
542
543 out_unreg_parport:
544 parport_unregister_device(pi->pardev);
545 if (pi->proto->release_proto)
546 pi->proto->release_proto(pi);
547 out_module_put:
548 module_put(pi->proto->owner);
549 out_unreg_dev:
550 device_unregister(&pi->dev);
551 out_ida_free:
552 ida_free(&pata_parport_bus_dev_ids, pi->dev.id);
553 return NULL;
554 }
555

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#8 lore raw

Re: [PATCH 01/16] pata_parport: add core driver (PARIDE replacement)

In reply to Ondrej Zary
Thank you for the patch! Yet something to improve:

Hi Ondrej,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on hch-configfs/for-next]
[also build test ERROR on linux/master linus/master v5.17-rc7 next-20220308] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ondrej-Zary/pata_parport-add-core-driver-PARIDE-replacement/20220307-142912
base:   git://git.infradead.org/users/hch/configfs.git for-next
config: ia64-allyesconfig (https://download.01.org/0day-ci/archive/20220309/[email protected]/config)
compiler: ia64-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/05539e2a04721c2710e7d1f6ae49926474bdf918
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ondrej-Zary/pata_parport-add-core-driver-PARIDE-replacement/20220307-142912 git checkout 05539e2a04721c2710e7d1f6ae49926474bdf918
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=ia64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

ia64-linux-ld: drivers/block/paride/paride.o: in function `pi_release':

>> (.text+0x600): multiple definition of `pi_release'; drivers/ata/pata_parport/pata_parport.o:(.text+0x36c0): first defined here

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#9 lore raw

PATCH 2/16 pata_parport: add aten protocol driver

In reply to Ondrej Zary

Add ATEN EH-100 protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  11 +++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/aten.c   | 139 ++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 drivers/ata/pata_parport/aten.c
drivers/ata/pata_parport/Kconfig +11 -0
index 56dc6b25d5fa..93b0ad65b523 100644
@@ -8,3 +8,14 @@
 
 comment "Parallel IDE protocol modules"
 	depends on PATA_PARPORT
+
+config PATA_PARPORT_ATEN
+	tristate "ATEN EH-100 protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the ATEN EH-100 parallel port IDE
+	  protocol. This protocol is used in some inexpensive low performance
+	  parallel port kits made in Hong Kong. If you chose to build PATA_PARPORT
+	  support into your kernel, you may answer Y here to build in the
+	  protocol driver, otherwise you should answer M to build it as a
+	  loadable module. The module will be called aten.
drivers/ata/pata_parport/Makefile +1 -0
index b105e1cb8dc6..7e821b629c58 100644
@@ -7,3 +7,4 @@
 #
 
 obj-$(CONFIG_PATA_PARPORT)		+= pata_parport.o
+obj-$(CONFIG_PATA_PARPORT_ATEN)		+= aten.o
drivers/ata/pata_parport/aten.c new file +139 -0

139 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#10 lore raw

PATCH 3/16 pata_parport: add bpck protocol driver

In reply to Ondrej Zary

Add MicroSolutions backpack (Series 5) protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  17 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/bpck.c   | 481 ++++++++++++++++++++++++++++++
 3 files changed, 499 insertions(+)
 create mode 100644 drivers/ata/pata_parport/bpck.c
drivers/ata/pata_parport/Kconfig +17 -0
index 93b0ad65b523..ed33a6a5c6fe 100644
@@ -19,3 +19,20 @@ config PATA_PARPORT_ATEN
 	  support into your kernel, you may answer Y here to build in the
 	  protocol driver, otherwise you should answer M to build it as a
 	  loadable module. The module will be called aten.
+
+config PATA_PARPORT_BPCK
+	tristate "MicroSolutions backpack (Series 5) protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the Micro Solutions BACKPACK
+	  parallel port Series 5 IDE protocol.  (Most BACKPACK drives made
+	  before 1999 were Series 5) Series 5 drives will NOT always have the
+	  Series noted on the bottom of the drive. Series 6 drivers will.
+
+	  In other words, if your BACKPACK drive doesn't say "Series 6" on the
+	  bottom, enable this option.
+
+	  If you chose to build PATA_PARPORT support into your kernel, you may
+	  answer Y here to build in the protocol driver, otherwise you should
+	  answer M to build it as a loadable module.  The module will be
+	  called bpck.
drivers/ata/pata_parport/Makefile +1 -0
index 7e821b629c58..1d03e49aa29f 100644
@@ -8,3 +8,4 @@
 
 obj-$(CONFIG_PATA_PARPORT)		+= pata_parport.o
 obj-$(CONFIG_PATA_PARPORT_ATEN)		+= aten.o
+obj-$(CONFIG_PATA_PARPORT_BPCK)		+= bpck.o
drivers/ata/pata_parport/bpck.c new file +481 -0

481 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#11 lore raw

PATCH 4/16 pata_parport: add bpck6 protocol driver

In reply to Ondrej Zary

Add MicroSolutions backpack (Series 6) protocol driver.

---
 drivers/ata/pata_parport/Kconfig   |  18 ++
 drivers/ata/pata_parport/Makefile  |   1 +
 drivers/ata/pata_parport/bpck6.c   | 164 ++++++++++
 drivers/ata/pata_parport/ppc6lnx.c | 486 +++++++++++++++++++++++++++++
 4 files changed, 669 insertions(+)
 create mode 100644 drivers/ata/pata_parport/bpck6.c
 create mode 100644 drivers/ata/pata_parport/ppc6lnx.c
drivers/ata/pata_parport/Kconfig +18 -0
index ed33a6a5c6fe..e88d9c0bedc6 100644
@@ -36,3 +36,21 @@ config PATA_PARPORT_BPCK
 	  answer Y here to build in the protocol driver, otherwise you should
 	  answer M to build it as a loadable module.  The module will be
 	  called bpck.
+
+config PATA_PARPORT_BPCK6
+	tristate "MicroSolutions backpack (Series 6) protocol"
+	depends on PATA_PARPORT && !64BIT
+	help
+	  This option enables support for the Micro Solutions BACKPACK
+	  parallel port Series 6 IDE protocol.  (Most BACKPACK drives made
+	  after 1999 were Series 6) Series 6 drives will have the Series noted
+	  on the bottom of the drive.  Series 5 drivers don't always have it
+	  noted.
+
+	  In other words, if your BACKPACK drive says "Series 6" on the
+	  bottom, enable this option.
+
+	  If you chose to build PATA_PARPORT support into your kernel, you may
+	  answer Y here to build in the protocol driver, otherwise you should
+	  answer M to build it as a loadable module.  The module will be
+	  called bpck6.
drivers/ata/pata_parport/Makefile +1 -0
index 1d03e49aa29f..60522279aa16 100644
@@ -9,3 +9,4 @@
 obj-$(CONFIG_PATA_PARPORT)		+= pata_parport.o
 obj-$(CONFIG_PATA_PARPORT_ATEN)		+= aten.o
 obj-$(CONFIG_PATA_PARPORT_BPCK)		+= bpck.o
+obj-$(CONFIG_PATA_PARPORT_BPCK6)	+= bpck6.o
drivers/ata/pata_parport/bpck6.c new file +164 -0

164 lines not on this page · raw message

drivers/ata/pata_parport/ppc6lnx.c new file +486 -0

486 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#12 lore raw

PATCH 5/16 pata_parport: add comm protocol driver

In reply to Ondrej Zary

Add DataStor Commuter protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  10 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/comm.c   | 198 ++++++++++++++++++++++++++++++
 3 files changed, 209 insertions(+)
 create mode 100644 drivers/ata/pata_parport/comm.c
drivers/ata/pata_parport/Kconfig +10 -0
index e88d9c0bedc6..3cc3d6ae4d45 100644
@@ -54,3 +54,13 @@ config PATA_PARPORT_BPCK6
 	  answer Y here to build in the protocol driver, otherwise you should
 	  answer M to build it as a loadable module.  The module will be
 	  called bpck6.
+
+config PATA_PARPORT_COMM
+	tristate "DataStor Commuter protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the Commuter parallel port IDE
+	  protocol from DataStor. If you chose to build PATA_PARPORT support
+	  into your kernel, you may answer Y here to build in the protocol
+	  driver, otherwise you should answer M to build it as a loadable
+	  module. The module will be called comm.
drivers/ata/pata_parport/Makefile +1 -0
index 60522279aa16..fcb77a855ef6 100644
@@ -10,3 +10,4 @@ obj-$(CONFIG_PATA_PARPORT)		+= pata_parport.o
 obj-$(CONFIG_PATA_PARPORT_ATEN)		+= aten.o
 obj-$(CONFIG_PATA_PARPORT_BPCK)		+= bpck.o
 obj-$(CONFIG_PATA_PARPORT_BPCK6)	+= bpck6.o
+obj-$(CONFIG_PATA_PARPORT_COMM)		+= comm.o
drivers/ata/pata_parport/comm.c new file +198 -0

198 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#13 lore raw

PATCH 6/16 pata_parport: add dstr protocol driver

In reply to Ondrej Zary

Add DataStor EP-2000 protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  10 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/dstr.c   | 226 ++++++++++++++++++++++++++++++
 3 files changed, 237 insertions(+)
 create mode 100644 drivers/ata/pata_parport/dstr.c
drivers/ata/pata_parport/Kconfig +10 -0
index 3cc3d6ae4d45..67f203dfbdca 100644
@@ -64,3 +64,13 @@ config PATA_PARPORT_COMM
 	  into your kernel, you may answer Y here to build in the protocol
 	  driver, otherwise you should answer M to build it as a loadable
 	  module. The module will be called comm.
+
+config PATA_PARPORT_DSTR
+	tristate "DataStor EP-2000 protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the EP-2000 parallel port IDE
+	  protocol from DataStor. If you chose to build PATA_PARPORT support
+	  into your kernel, you may answer Y here to build in the protocol
+	  driver, otherwise you should answer M to build it as a loadable
+	  module. The module will be called dstr.
drivers/ata/pata_parport/Makefile +1 -0
index fcb77a855ef6..bf81c4ca32ab 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_PATA_PARPORT_ATEN)		+= aten.o
 obj-$(CONFIG_PATA_PARPORT_BPCK)		+= bpck.o
 obj-$(CONFIG_PATA_PARPORT_BPCK6)	+= bpck6.o
 obj-$(CONFIG_PATA_PARPORT_COMM)		+= comm.o
+obj-$(CONFIG_PATA_PARPORT_DSTR)		+= dstr.o
drivers/ata/pata_parport/dstr.c new file +226 -0

226 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#14 lore raw

PATCH 7/16 pata_parport: add fit2 protocol driver

In reply to Ondrej Zary

Add FIT TD-2000 protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  11 +++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/fit2.c   | 135 ++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+)
 create mode 100644 drivers/ata/pata_parport/fit2.c
drivers/ata/pata_parport/Kconfig +11 -0
index 67f203dfbdca..db8edb288db4 100644
@@ -74,3 +74,14 @@ config PATA_PARPORT_DSTR
 	  into your kernel, you may answer Y here to build in the protocol
 	  driver, otherwise you should answer M to build it as a loadable
 	  module. The module will be called dstr.
+
+config PATA_PARPORT_FIT2
+	tristate "FIT TD-2000 protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the TD-2000 parallel port IDE
+	  protocol from Fidelity International Technology. This is a simple
+	  (low speed) adapter that is used in some portable hard drives. If
+	  you chose to build PATA_PARPORT support into your kernel, you may answer Y
+	  here to build in the protocol driver, otherwise you should answer M
+	  to build it as a loadable module. The module will be called ktti.
drivers/ata/pata_parport/Makefile +1 -0
index bf81c4ca32ab..27d854f52ad7 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_PATA_PARPORT_BPCK)		+= bpck.o
 obj-$(CONFIG_PATA_PARPORT_BPCK6)	+= bpck6.o
 obj-$(CONFIG_PATA_PARPORT_COMM)		+= comm.o
 obj-$(CONFIG_PATA_PARPORT_DSTR)		+= dstr.o
+obj-$(CONFIG_PATA_PARPORT_FIT2)		+= fit2.o
drivers/ata/pata_parport/fit2.c new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#15 lore raw

PATCH 8/16 pata_parport: add fit3 protocol driver

In reply to Ondrej Zary

Add FIT TD-3000 protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  12 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/fit3.c   | 195 ++++++++++++++++++++++++++++++
 3 files changed, 208 insertions(+)
 create mode 100644 drivers/ata/pata_parport/fit3.c
drivers/ata/pata_parport/Kconfig +12 -0
index db8edb288db4..a03c626e4e6c 100644
@@ -85,3 +85,15 @@ config PATA_PARPORT_FIT2
 	  you chose to build PATA_PARPORT support into your kernel, you may answer Y
 	  here to build in the protocol driver, otherwise you should answer M
 	  to build it as a loadable module. The module will be called ktti.
+
+config PATA_PARPORT_FIT3
+	tristate "FIT TD-3000 protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the TD-3000 parallel port IDE
+	  protocol from Fidelity International Technology. This protocol is
+	  used in newer models of their portable disk, CD-ROM and PD/CD
+	  devices. If you chose to build PATA_PARPORT support into your kernel, you
+	  may answer Y here to build in the protocol driver, otherwise you
+	  should answer M to build it as a loadable module. The module will be
+	  called fit3.
drivers/ata/pata_parport/Makefile +1 -0
index 27d854f52ad7..140f6f142eaa 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_PATA_PARPORT_BPCK6)	+= bpck6.o
 obj-$(CONFIG_PATA_PARPORT_COMM)		+= comm.o
 obj-$(CONFIG_PATA_PARPORT_DSTR)		+= dstr.o
 obj-$(CONFIG_PATA_PARPORT_FIT2)		+= fit2.o
+obj-$(CONFIG_PATA_PARPORT_FIT3)		+= fit3.o
drivers/ata/pata_parport/fit3.c new file +195 -0

195 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#16 lore raw

PATCH 9/16 pata_parport: add epat protocol driver

In reply to Ondrej Zary

Add Shuttle EPAT/EPEZ protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  12 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/epat.c   | 320 ++++++++++++++++++++++++++++++
 3 files changed, 333 insertions(+)
 create mode 100644 drivers/ata/pata_parport/epat.c
drivers/ata/pata_parport/Kconfig +12 -0
index a03c626e4e6c..6c218486c3b8 100644
@@ -97,3 +97,15 @@ config PATA_PARPORT_FIT3
 	  may answer Y here to build in the protocol driver, otherwise you
 	  should answer M to build it as a loadable module. The module will be
 	  called fit3.
+
+config PATA_PARPORT_EPAT
+	tristate "Shuttle EPAT/EPEZ protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the EPAT parallel port IDE protocol.
+	  EPAT is a parallel port IDE adapter manufactured by Shuttle
+	  Technology and widely used in devices from major vendors such as
+	  Hewlett-Packard, SyQuest, Imation and Avatar. If you chose to build
+	  PATA_PARPORT support into your kernel, you may answer Y here to build in
+	  the protocol driver, otherwise you should answer M to build it as a
+	  loadable module. The module will be called epat.
drivers/ata/pata_parport/Makefile +1 -0
index 140f6f142eaa..459307f4a096 100644
@@ -14,3 +14,4 @@ obj-$(CONFIG_PATA_PARPORT_COMM)		+= comm.o
 obj-$(CONFIG_PATA_PARPORT_DSTR)		+= dstr.o
 obj-$(CONFIG_PATA_PARPORT_FIT2)		+= fit2.o
 obj-$(CONFIG_PATA_PARPORT_FIT3)		+= fit3.o
+obj-$(CONFIG_PATA_PARPORT_EPAT)		+= epat.o
drivers/ata/pata_parport/epat.c new file +320 -0

320 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#17 lore raw

PATCH 10/16 pata_parport: add epia protocol driver

In reply to Ondrej Zary

Add Shuttle EPIA protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  11 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/epia.c   | 308 ++++++++++++++++++++++++++++++
 3 files changed, 320 insertions(+)
 create mode 100644 drivers/ata/pata_parport/epia.c
drivers/ata/pata_parport/Kconfig +11 -0
index 6c218486c3b8..832ab8b00511 100644
@@ -109,3 +109,14 @@ config PATA_PARPORT_EPAT
 	  PATA_PARPORT support into your kernel, you may answer Y here to build in
 	  the protocol driver, otherwise you should answer M to build it as a
 	  loadable module. The module will be called epat.
+
+config PATA_PARPORT_EPIA
+	tristate "Shuttle EPIA protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the (obsolete) EPIA parallel port
+	  IDE protocol from Shuttle Technology. This adapter can still be
+	  found in some no-name kits. If you chose to build PATA_PARPORT support
+	  into your kernel, you may answer Y here to build in the protocol
+	  driver, otherwise you should answer M to build it as a loadable
+	  module. The module will be called epia.
drivers/ata/pata_parport/Makefile +1 -0
index 459307f4a096..6e72778f45cb 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_PATA_PARPORT_DSTR)		+= dstr.o
 obj-$(CONFIG_PATA_PARPORT_FIT2)		+= fit2.o
 obj-$(CONFIG_PATA_PARPORT_FIT3)		+= fit3.o
 obj-$(CONFIG_PATA_PARPORT_EPAT)		+= epat.o
+obj-$(CONFIG_PATA_PARPORT_EPIA)		+= epia.o
drivers/ata/pata_parport/epia.c new file +308 -0

308 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#18 lore raw

PATCH 11/16 pata_parport: add friq protocol driver

In reply to Ondrej Zary

Add Freecom IQ ASIC-2 protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  12 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/friq.c   | 263 ++++++++++++++++++++++++++++++
 3 files changed, 276 insertions(+)
 create mode 100644 drivers/ata/pata_parport/friq.c
drivers/ata/pata_parport/Kconfig +12 -0
index 832ab8b00511..8a569ee0bf6a 100644
@@ -120,3 +120,15 @@ config PATA_PARPORT_EPIA
 	  into your kernel, you may answer Y here to build in the protocol
 	  driver, otherwise you should answer M to build it as a loadable
 	  module. The module will be called epia.
+
+config PATA_PARPORT_FRIQ
+	tristate "Freecom IQ ASIC-2 protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for version 2 of the Freecom IQ parallel
+	  port IDE adapter.  This adapter is used by the Maxell Superdisk
+	  drive.  If you chose to build PATA_PARPORT support into your kernel, you
+	  may answer Y here to build in the protocol driver, otherwise you
+	  should answer M to build it as a loadable module. The module will be
+	  called friq. You must also have a high-level driver for the type
+	  of device that you want to support.
drivers/ata/pata_parport/Makefile +1 -0
index 6e72778f45cb..20d05e525c95 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_PATA_PARPORT_FIT2)		+= fit2.o
 obj-$(CONFIG_PATA_PARPORT_FIT3)		+= fit3.o
 obj-$(CONFIG_PATA_PARPORT_EPAT)		+= epat.o
 obj-$(CONFIG_PATA_PARPORT_EPIA)		+= epia.o
+obj-$(CONFIG_PATA_PARPORT_FRIQ)		+= friq.o
drivers/ata/pata_parport/friq.c new file +263 -0

263 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#19 lore raw

PATCH 12/16 pata_parport: add frpw protocol driver

In reply to Ondrej Zary

Add FreeCom power protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  10 +
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/frpw.c   | 292 ++++++++++++++++++++++++++++++
 3 files changed, 303 insertions(+)
 create mode 100644 drivers/ata/pata_parport/frpw.c
drivers/ata/pata_parport/Kconfig +10 -0
index 8a569ee0bf6a..d8e5feaaae7a 100644
@@ -132,3 +132,13 @@ config PATA_PARPORT_FRIQ
 	  should answer M to build it as a loadable module. The module will be
 	  called friq. You must also have a high-level driver for the type
 	  of device that you want to support.
+
+config PATA_PARPORT_FRPW
+	tristate "FreeCom power protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the Freecom power parallel port IDE
+	  protocol. If you chose to build PATA_PARPORT support into your kernel, you
+	  may answer Y here to build in the protocol driver, otherwise you
+	  should answer M to build it as a loadable module. The module will be
+	  called frpw.
drivers/ata/pata_parport/Makefile +1 -0
index 20d05e525c95..136374be9613 100644
@@ -17,3 +17,4 @@ obj-$(CONFIG_PATA_PARPORT_FIT3)		+= fit3.o
 obj-$(CONFIG_PATA_PARPORT_EPAT)		+= epat.o
 obj-$(CONFIG_PATA_PARPORT_EPIA)		+= epia.o
 obj-$(CONFIG_PATA_PARPORT_FRIQ)		+= friq.o
+obj-$(CONFIG_PATA_PARPORT_FRPW)		+= frpw.o
drivers/ata/pata_parport/frpw.c new file +292 -0

292 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#20 lore raw

PATCH 13/16 pata_parport: add kbic protocol driver

In reply to Ondrej Zary

Add KingByte KBIC-951A/971A protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  12 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/kbic.c   | 292 ++++++++++++++++++++++++++++++
 3 files changed, 305 insertions(+)
 create mode 100644 drivers/ata/pata_parport/kbic.c
drivers/ata/pata_parport/Kconfig +12 -0
index d8e5feaaae7a..004e5cf708f1 100644
@@ -142,3 +142,15 @@ config PATA_PARPORT_FRPW
 	  may answer Y here to build in the protocol driver, otherwise you
 	  should answer M to build it as a loadable module. The module will be
 	  called frpw.
+
+config PATA_PARPORT_KBIC
+	tristate "KingByte KBIC-951A/971A protocols"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the KBIC-951A and KBIC-971A parallel
+	  port IDE protocols from KingByte Information Corp. KingByte's
+	  adapters appear in many no-name portable disk and CD-ROM products,
+	  especially in Europe. If you chose to build PATA_PARPORT support into your
+	  kernel, you may answer Y here to build in the protocol driver,
+	  otherwise you should answer M to build it as a loadable module. The
+	  module will be called kbic.
drivers/ata/pata_parport/Makefile +1 -0
index 136374be9613..e82fded22da3 100644
@@ -18,3 +18,4 @@ obj-$(CONFIG_PATA_PARPORT_EPAT)		+= epat.o
 obj-$(CONFIG_PATA_PARPORT_EPIA)		+= epia.o
 obj-$(CONFIG_PATA_PARPORT_FRIQ)		+= friq.o
 obj-$(CONFIG_PATA_PARPORT_FRPW)		+= frpw.o
+obj-$(CONFIG_PATA_PARPORT_KBIC)		+= kbic.o
drivers/ata/pata_parport/kbic.c new file +292 -0

292 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#21 lore raw

PATCH 14/16 pata_parport: add ktti protocol driver

In reply to Ondrej Zary

Add KT PHd protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  11 +++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/ktti.c   | 112 ++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 drivers/ata/pata_parport/ktti.c
drivers/ata/pata_parport/Kconfig +11 -0
index 004e5cf708f1..4505a037591a 100644
@@ -154,3 +154,14 @@ config PATA_PARPORT_KBIC
 	  kernel, you may answer Y here to build in the protocol driver,
 	  otherwise you should answer M to build it as a loadable module. The
 	  module will be called kbic.
+
+config PATA_PARPORT_KTTI
+	tristate "KT PHd protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the "PHd" parallel port IDE protocol
+	  from KT Technology. This is a simple (low speed) adapter that is
+	  used in some 2.5" portable hard drives. If you chose to build PATA_PARPORT
+	  support into your kernel, you may answer Y here to build in the
+	  protocol driver, otherwise you should answer M to build it as a
+	  loadable module. The module will be called ktti.
drivers/ata/pata_parport/Makefile +1 -0
index e82fded22da3..0c31cf55c96b 100644
@@ -19,3 +19,4 @@ obj-$(CONFIG_PATA_PARPORT_EPIA)		+= epia.o
 obj-$(CONFIG_PATA_PARPORT_FRIQ)		+= friq.o
 obj-$(CONFIG_PATA_PARPORT_FRPW)		+= frpw.o
 obj-$(CONFIG_PATA_PARPORT_KBIC)		+= kbic.o
+obj-$(CONFIG_PATA_PARPORT_KTTI)		+= ktti.o
drivers/ata/pata_parport/ktti.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#22 lore raw

PATCH 15/16 pata_parport: add on20 protocol driver

In reply to Ondrej Zary

Add OnSpec 90c20 protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  11 +++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/on20.c   | 136 ++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 drivers/ata/pata_parport/on20.c
drivers/ata/pata_parport/Kconfig +11 -0
index 4505a037591a..c18757464b1d 100644
@@ -165,3 +165,14 @@ config PATA_PARPORT_KTTI
 	  support into your kernel, you may answer Y here to build in the
 	  protocol driver, otherwise you should answer M to build it as a
 	  loadable module. The module will be called ktti.
+
+config PATA_PARPORT_ON20
+	tristate "OnSpec 90c20 protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the (obsolete) 90c20 parallel port
+	  IDE protocol from OnSpec (often marketed under the ValuStore brand
+	  name). If you chose to build PATA_PARPORT support into your kernel, you
+	  may answer Y here to build in the protocol driver, otherwise you
+	  should answer M to build it as a loadable module.The module will
+	  be called on20.
drivers/ata/pata_parport/Makefile +1 -0
index 0c31cf55c96b..4358d1d946cb 100644
@@ -20,3 +20,4 @@ obj-$(CONFIG_PATA_PARPORT_FRIQ)		+= friq.o
 obj-$(CONFIG_PATA_PARPORT_FRPW)		+= frpw.o
 obj-$(CONFIG_PATA_PARPORT_KBIC)		+= kbic.o
 obj-$(CONFIG_PATA_PARPORT_KTTI)		+= ktti.o
+obj-$(CONFIG_PATA_PARPORT_ON20)		+= on20.o
drivers/ata/pata_parport/on20.c new file +136 -0

136 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#23 lore raw

PATCH 16/16 pata_parport: add on26 protocol driver

In reply to Ondrej Zary

Add OnSpec 90c26 protocol driver.

---
 drivers/ata/pata_parport/Kconfig  |  11 ++
 drivers/ata/pata_parport/Makefile |   1 +
 drivers/ata/pata_parport/on26.c   | 302 ++++++++++++++++++++++++++++++
 3 files changed, 314 insertions(+)
 create mode 100644 drivers/ata/pata_parport/on26.c
drivers/ata/pata_parport/Kconfig +11 -0
index c18757464b1d..5d3440f372fc 100644
@@ -176,3 +176,14 @@ config PATA_PARPORT_ON20
 	  may answer Y here to build in the protocol driver, otherwise you
 	  should answer M to build it as a loadable module.The module will
 	  be called on20.
+
+config PATA_PARPORT_ON26
+	tristate "OnSpec 90c26 protocol"
+	depends on PATA_PARPORT
+	help
+	  This option enables support for the 90c26 parallel port IDE protocol
+	  from OnSpec Electronics (often marketed under the ValuStore brand
+	  name). If you chose to build PATA_PARPORT support into your kernel, you
+	  may answer Y here to build in the protocol driver, otherwise you
+	  should answer M to build it as a loadable module. The module will be
+	  called on26.
drivers/ata/pata_parport/Makefile +1 -0
index 4358d1d946cb..2b03a5a9131a 100644
@@ -21,3 +21,4 @@ obj-$(CONFIG_PATA_PARPORT_FRPW)		+= frpw.o
 obj-$(CONFIG_PATA_PARPORT_KBIC)		+= kbic.o
 obj-$(CONFIG_PATA_PARPORT_KTTI)		+= ktti.o
 obj-$(CONFIG_PATA_PARPORT_ON20)		+= on20.o
+obj-$(CONFIG_PATA_PARPORT_ON26)		+= on26.o
drivers/ata/pata_parport/on26.c new file +302 -0

302 lines not on this page · raw message

Signature · 1 line
Ondrej Zary
#24 lore raw
In reply to Ondrej Zary

Hi Ondrej,

I just took a quick glance and it seems like the actual protocol modules still are basically almost exactly the same ones as the paride ones. Is there a way to just keep the existing modules?

The only big thing I noticed is the host template, but at least for the transitional periode we could probably allocate that dynamically in the core. I think would reduce the amount of code churn nicely and make review much easier.

#25 lore raw
Quoted 10 lines · On Sunday 06 March 2022 09:58:25 Christoph Hellwig wrote:

Hi Ondrej,

I just took a quick glance and it seems like the actual protocol modules still are basically almost exactly the same ones as the paride ones. Is there a way to just keep the existing modules?

The only big thing I noticed is the host template, but at least for the transitional periode we could probably allocate that dynamically in the core. I think would reduce the amount of code churn nicely and make review much easier.

Yes, only small changes in the protocol modules regarding (un)registration.

Getting the original modules work with pata_parport (like in 1st preview) required some hacks that break paride (disabling EXPORT_SYMBOLs in paride).

Maybe the protocol modules can be moved (git mv) from paride and then patched? A copy would be better but there's no "git cp".

Signature · 1 line
Ondrej Zary
#26 lore raw
Quoted 12 lines · Ondrej Zary
Quoted 10 lines · On Sunday 06 March 2022 09:58:25 Christoph Hellwig wrote:

Hi Ondrej,

I just took a quick glance and it seems like the actual protocol modules still are basically almost exactly the same ones as the paride ones. Is there a way to just keep the existing modules?

The only big thing I noticed is the host template, but at least for the transitional periode we could probably allocate that dynamically in the core. I think would reduce the amount of code churn nicely and make review much easier.

Quoted 5 lines

Yes, only small changes in the protocol modules regarding (un)registration.

Getting the original modules work with pata_parport (like in 1st preview) required some hacks that break paride (disabling EXPORT_SYMBOLs in paride).

Maybe the protocol modules can be moved (git mv) from paride and then patched? A copy would be better but there's no "git cp".

Hmm, how would be break the old PARIDE code? You'd need the new libata support exlusive to the old PARIDE code so that only one of them can export the registration symbols at a time. The git-mv can happen once the old paride code is removed after a release or two.

Quoted 3 lines
Signature · 2 lines
-- 
Ondrej Zary

---end quoted text---