Skip to contentSkip to conversation

ata: pata_buddha: pata_gayle: consolidate .sff_data_xfer around libata::ata_sff_data_xfer()

PATCH In review Paolo Pisati 3 participants 3 messages Jun 4, 2024 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ata: pata_buddha: pata_gayle: consolidate .sff_data_xfer around libata::ata_sff_data_xfer()

pata_buddha_data_xfer(), pata_gayle_data_xfer() and ata_sff_data_xfer() are the same function, consolidate around libata::ata_sff_data_xfer().

---
 drivers/ata/pata_buddha.c | 40 ++-------------------------------------
 drivers/ata/pata_gayle.c  | 40 ++-------------------------------------
 2 files changed, 4 insertions(+), 76 deletions(-)
drivers/ata/pata_buddha.c +2 -38
index c36ee991d5e5..234278eb26e1 100644
@@ -60,42 +60,6 @@ static const struct scsi_host_template pata_buddha_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
 
-/* FIXME: is this needed? */
-static unsigned int pata_buddha_data_xfer(struct ata_queued_cmd *qc,
-					 unsigned char *buf,
-					 unsigned int buflen, int rw)
-{
-	struct ata_device *dev = qc->dev;
-	struct ata_port *ap = dev->link->ap;
-	void __iomem *data_addr = ap->ioaddr.data_addr;
-	unsigned int words = buflen >> 1;
-
-	/* Transfer multiple of 2 bytes */
-	if (rw == READ)
-		raw_insw((u16 *)data_addr, (u16 *)buf, words);
-	else
-		raw_outsw((u16 *)data_addr, (u16 *)buf, words);
-
-	/* Transfer trailing byte, if any. */
-	if (unlikely(buflen & 0x01)) {
-		unsigned char pad[2] = { };
-
-		/* Point buf to the tail of buffer */
-		buf += buflen - 1;
-
-		if (rw == READ) {
-			raw_insw((u16 *)data_addr, (u16 *)pad, 1);
-			*buf = pad[0];
-		} else {
-			pad[0] = *buf;
-			raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
-		}
-		words++;
-	}
-
-	return words << 1;
-}
-
 /*
  * Provide our own set_mode() as we don't want to change anything that has
  * already been configured..
@@ -131,7 +95,7 @@ static void pata_xsurf_irq_clear(struct ata_port *ap)
 
 static struct ata_port_operations pata_buddha_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_buddha_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,
 	.sff_irq_check	= pata_buddha_irq_check,
 	.cable_detect	= ata_cable_unknown,
 	.set_mode	= pata_buddha_set_mode,
@@ -139,7 +103,7 @@ static struct ata_port_operations pata_buddha_ops = {
 
 static struct ata_port_operations pata_xsurf_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_buddha_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,
 	.sff_irq_check	= pata_buddha_irq_check,
 	.sff_irq_clear	= pata_xsurf_irq_clear,
 	.cable_detect	= ata_cable_unknown,
drivers/ata/pata_gayle.c +2 -38
index 3bdbe2b65a2b..febffc36a18f 100644
@@ -38,42 +38,6 @@ static const struct scsi_host_template pata_gayle_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
 
-/* FIXME: is this needed? */
-static unsigned int pata_gayle_data_xfer(struct ata_queued_cmd *qc,
-					 unsigned char *buf,
-					 unsigned int buflen, int rw)
-{
-	struct ata_device *dev = qc->dev;
-	struct ata_port *ap = dev->link->ap;
-	void __iomem *data_addr = ap->ioaddr.data_addr;
-	unsigned int words = buflen >> 1;
-
-	/* Transfer multiple of 2 bytes */
-	if (rw == READ)
-		raw_insw((u16 *)data_addr, (u16 *)buf, words);
-	else
-		raw_outsw((u16 *)data_addr, (u16 *)buf, words);
-
-	/* Transfer trailing byte, if any. */
-	if (unlikely(buflen & 0x01)) {
-		unsigned char pad[2] = { };
-
-		/* Point buf to the tail of buffer */
-		buf += buflen - 1;
-
-		if (rw == READ) {
-			raw_insw((u16 *)data_addr, (u16 *)pad, 1);
-			*buf = pad[0];
-		} else {
-			pad[0] = *buf;
-			raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
-		}
-		words++;
-	}
-
-	return words << 1;
-}
-
 /*
  * Provide our own set_mode() as we don't want to change anything that has
  * already been configured..
@@ -110,7 +74,7 @@ static void pata_gayle_irq_clear(struct ata_port *ap)
 
 static struct ata_port_operations pata_gayle_a1200_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_gayle_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,
 	.sff_irq_check	= pata_gayle_irq_check,
 	.sff_irq_clear	= pata_gayle_irq_clear,
 	.cable_detect	= ata_cable_unknown,
@@ -119,7 +83,7 @@ static struct ata_port_operations pata_gayle_a1200_ops = {
 
 static struct ata_port_operations pata_gayle_a4000_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_gayle_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,
 	.cable_detect	= ata_cable_unknown,
 	.set_mode	= pata_gayle_set_mode,
 };
Signature · 1 line
2.34.1
#1 lore raw

Hello!

Please do 2 separate patches (for each driver), or at last name the
patch s/th like "ata: pata_{buddha,gayle}: consolidate .sff_data_xfer around libata-sff.c::ata_sff_data_xfer()"...

Quoted 22 lines · Paolo Pisati

pata_buddha_data_xfer(), pata_gayle_data_xfer() and ata_sff_data_xfer() are the same function, consolidate around libata::ata_sff_data_xfer().

---
 drivers/ata/pata_buddha.c | 40 ++-------------------------------------
 drivers/ata/pata_gayle.c  | 40 ++-------------------------------------
 2 files changed, 4 insertions(+), 76 deletions(-)
drivers/ata/pata_buddha.c +0 -5
index c36ee991d5e5..234278eb26e1 100644
@@ -60,42 +60,6 @@ static const struct scsi_host_template pata_buddha_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
 
-/* FIXME: is this needed? */
-static unsigned int pata_buddha_data_xfer(struct ata_queued_cmd *qc,
-					 unsigned char *buf,
-					 unsigned int buflen, int rw)
-{

drivers/ata/pata_buddha.c static const struct scsi_host_template pata_buddha_sht = { · line 77

Quoted 10 lines
drivers/ata/pata_buddha.c +0 -10
-	struct ata_device *dev = qc->dev;
-	struct ata_port *ap = dev->link->ap;
-	void __iomem *data_addr = ap->ioaddr.data_addr;
-	unsigned int words = buflen >> 1;
-
-	/* Transfer multiple of 2 bytes */
-	if (rw == READ)
-		raw_insw((u16 *)data_addr, (u16 *)buf, words);
-	else
-		raw_outsw((u16 *)data_addr, (u16 *)buf, words);

Hm, are you sure these calls are equivalent to io{read,write}16_rep()?

Quoted 25 lines
drivers/ata/pata_buddha.c +0 -21
-
-	/* Transfer trailing byte, if any. */
-	if (unlikely(buflen & 0x01)) {
-		unsigned char pad[2] = { };
-
-		/* Point buf to the tail of buffer */
-		buf += buflen - 1;
-
-		if (rw == READ) {
-			raw_insw((u16 *)data_addr, (u16 *)pad, 1);
-			*buf = pad[0];
-		} else {
-			pad[0] = *buf;
-			raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
-		}
-		words++;
-	}
-
-	return words << 1;
-}
-
 /*
  * Provide our own set_mode() as we don't want to change anything that has
  * already been configured..

drivers/ata/pata_buddha.c static void pata_xsurf_irq_clear(struct ata_port *ap) · line 98

Quoted 5 lines
drivers/ata/pata_buddha.c +1 -1
@@ -131,7 +95,7 @@ static void pata_xsurf_irq_clear(struct ata_port *ap)
 
 static struct ata_port_operations pata_buddha_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_buddha_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,

There should be no need -- this method is preperly init'ed in ata_sff_port_ops...

drivers/ata/pata_buddha.c static struct ata_port_operations pata_buddha_ops = { · line 106

Quoted 9 lines
drivers/ata/pata_buddha.c +1 -1
 	.sff_irq_check	= pata_buddha_irq_check,
 	.cable_detect	= ata_cable_unknown,
 	.set_mode	= pata_buddha_set_mode,
@@ -139,7 +103,7 @@ static struct ata_port_operations pata_buddha_ops = {
 
 static struct ata_port_operations pata_xsurf_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_buddha_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,

Here as well...

Quoted 37 lines
drivers/ata/pata_buddha.c +0 -0
 	.sff_irq_check	= pata_buddha_irq_check,
 	.sff_irq_clear	= pata_xsurf_irq_clear,
 	.cable_detect	= ata_cable_unknown,
drivers/ata/pata_gayle.c +0 -26
index 3bdbe2b65a2b..febffc36a18f 100644
@@ -38,42 +38,6 @@ static const struct scsi_host_template pata_gayle_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
 
-/* FIXME: is this needed? */
-static unsigned int pata_gayle_data_xfer(struct ata_queued_cmd *qc,
-					 unsigned char *buf,
-					 unsigned int buflen, int rw)
-{
-	struct ata_device *dev = qc->dev;
-	struct ata_port *ap = dev->link->ap;
-	void __iomem *data_addr = ap->ioaddr.data_addr;
-	unsigned int words = buflen >> 1;
-
-	/* Transfer multiple of 2 bytes */
-	if (rw == READ)
-		raw_insw((u16 *)data_addr, (u16 *)buf, words);
-	else
-		raw_outsw((u16 *)data_addr, (u16 *)buf, words);
-
-	/* Transfer trailing byte, if any. */
-	if (unlikely(buflen & 0x01)) {
-		unsigned char pad[2] = { };
-
-		/* Point buf to the tail of buffer */
-		buf += buflen - 1;
-
-		if (rw == READ) {
-			raw_insw((u16 *)data_addr, (u16 *)pad, 1);
-			*buf = pad[0];

drivers/ata/pata_gayle.c static const struct scsi_host_template pata_gayle_sht = { · line 76

Quoted 10 lines
drivers/ata/pata_gayle.c +0 -10
-		} else {
-			pad[0] = *buf;
-			raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
-		}
-		words++;
-	}
-
-	return words << 1;
-}
-

Same question as above here...

Quoted 14 lines
drivers/ata/pata_gayle.c +1 -1
 /*
  * Provide our own set_mode() as we don't want to change anything that has
  * already been configured..
@@ -110,7 +74,7 @@ static void pata_gayle_irq_clear(struct ata_port *ap)
 
 static struct ata_port_operations pata_gayle_a1200_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_gayle_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,
 	.sff_irq_check	= pata_gayle_irq_check,
 	.sff_irq_clear	= pata_gayle_irq_clear,
 	.cable_detect	= ata_cable_unknown,

drivers/ata/pata_gayle.c static struct ata_port_operations pata_gayle_a1200_ops = { · line 89

Quoted 8 lines
drivers/ata/pata_gayle.c +1 -1
@@ -119,7 +83,7 @@ static struct ata_port_operations pata_gayle_a1200_ops = {
 
 static struct ata_port_operations pata_gayle_a4000_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_gayle_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,
 	.cable_detect	= ata_cable_unknown,
 	.set_mode	= pata_gayle_set_mode,
 };

Same comments as to pata_buddha.c here...

MBR, Sergey

maintainer
#2 lore raw
In reply to Paolo Pisati

Hello Paolo,

Quoted 2 lines · Paolo Pisati

pata_buddha_data_xfer(), pata_gayle_data_xfer() and ata_sff_data_xfer() are the same function, consolidate around libata::ata_sff_data_xfer().

Please avoid the C++ namespace operator,
just drop "libata::" here and in the subject.

Also please just split this into two patches, one per driver.

Quoted 55 lines
---
 drivers/ata/pata_buddha.c | 40 ++-------------------------------------
 drivers/ata/pata_gayle.c  | 40 ++-------------------------------------
 2 files changed, 4 insertions(+), 76 deletions(-)
drivers/ata/pata_buddha.c +0 -36
index c36ee991d5e5..234278eb26e1 100644
@@ -60,42 +60,6 @@ static const struct scsi_host_template pata_buddha_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
 
-/* FIXME: is this needed? */
-static unsigned int pata_buddha_data_xfer(struct ata_queued_cmd *qc,
-					 unsigned char *buf,
-					 unsigned int buflen, int rw)
-{
-	struct ata_device *dev = qc->dev;
-	struct ata_port *ap = dev->link->ap;
-	void __iomem *data_addr = ap->ioaddr.data_addr;
-	unsigned int words = buflen >> 1;
-
-	/* Transfer multiple of 2 bytes */
-	if (rw == READ)
-		raw_insw((u16 *)data_addr, (u16 *)buf, words);
-	else
-		raw_outsw((u16 *)data_addr, (u16 *)buf, words);
-
-	/* Transfer trailing byte, if any. */
-	if (unlikely(buflen & 0x01)) {
-		unsigned char pad[2] = { };
-
-		/* Point buf to the tail of buffer */
-		buf += buflen - 1;
-
-		if (rw == READ) {
-			raw_insw((u16 *)data_addr, (u16 *)pad, 1);
-			*buf = pad[0];
-		} else {
-			pad[0] = *buf;
-			raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
-		}
-		words++;
-	}
-
-	return words << 1;
-}
-
 /*
  * Provide our own set_mode() as we don't want to change anything that has
  * already been configured..

drivers/ata/pata_buddha.c static void pata_xsurf_irq_clear(struct ata_port *ap) · line 98

Quoted 5 lines
drivers/ata/pata_buddha.c +1 -1
@@ -131,7 +95,7 @@ static void pata_xsurf_irq_clear(struct ata_port *ap)
 
 static struct ata_port_operations pata_buddha_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_buddha_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,

Since this driver inherits ata_sff_port_ops,
which sets .sff_data_xfer to ata_sff_data_xfer:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/ata/libata-sff.c?h=v6.10-rc2#n46

this line should not be needed.

Quoted 60 lines
drivers/ata/pata_buddha.c +1 -1
 	.sff_irq_check	= pata_buddha_irq_check,
 	.cable_detect	= ata_cable_unknown,
 	.set_mode	= pata_buddha_set_mode,
@@ -139,7 +103,7 @@ static struct ata_port_operations pata_buddha_ops = {
 
 static struct ata_port_operations pata_xsurf_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_buddha_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,
 	.sff_irq_check	= pata_buddha_irq_check,
 	.sff_irq_clear	= pata_xsurf_irq_clear,
 	.cable_detect	= ata_cable_unknown,
drivers/ata/pata_gayle.c +0 -36
index 3bdbe2b65a2b..febffc36a18f 100644
@@ -38,42 +38,6 @@ static const struct scsi_host_template pata_gayle_sht = {
 	ATA_PIO_SHT(DRV_NAME),
 };
 
-/* FIXME: is this needed? */
-static unsigned int pata_gayle_data_xfer(struct ata_queued_cmd *qc,
-					 unsigned char *buf,
-					 unsigned int buflen, int rw)
-{
-	struct ata_device *dev = qc->dev;
-	struct ata_port *ap = dev->link->ap;
-	void __iomem *data_addr = ap->ioaddr.data_addr;
-	unsigned int words = buflen >> 1;
-
-	/* Transfer multiple of 2 bytes */
-	if (rw == READ)
-		raw_insw((u16 *)data_addr, (u16 *)buf, words);
-	else
-		raw_outsw((u16 *)data_addr, (u16 *)buf, words);
-
-	/* Transfer trailing byte, if any. */
-	if (unlikely(buflen & 0x01)) {
-		unsigned char pad[2] = { };
-
-		/* Point buf to the tail of buffer */
-		buf += buflen - 1;
-
-		if (rw == READ) {
-			raw_insw((u16 *)data_addr, (u16 *)pad, 1);
-			*buf = pad[0];
-		} else {
-			pad[0] = *buf;
-			raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
-		}
-		words++;
-	}
-
-	return words << 1;
-}
-
 /*
  * Provide our own set_mode() as we don't want to change anything that has
  * already been configured..

drivers/ata/pata_gayle.c static void pata_gayle_irq_clear(struct ata_port *ap) · line 77

Quoted 5 lines
drivers/ata/pata_gayle.c +1 -1
@@ -110,7 +74,7 @@ static void pata_gayle_irq_clear(struct ata_port *ap)
 
 static struct ata_port_operations pata_gayle_a1200_ops = {
 	.inherits	= &ata_sff_port_ops,
-	.sff_data_xfer	= pata_gayle_data_xfer,
+	.sff_data_xfer	= ata_sff_data_xfer,

Same comment as for the other driver.

Kind regards,
Niklas