diff mbox series

[13/28] ata: move ata_do_link_spd_horkage() to libata-core-sata.c

Message ID 20200128133343.29905-14-b.zolnierkie@samsung.com
State Not Applicable
Delegated to: David Miller
Headers show
Series ata: optimize core code size on PATA only setups | expand

Commit Message

Bartlomiej Zolnierkiewicz Jan. 28, 2020, 1:33 p.m. UTC
* move ata_do_link_spd_horkage() to libata-core-sata.c

* add static inline for CONFIG_SATA_HOST=n case

Code size savings on m68k arch using atari_defconfig:

   text    data     bss     dec     hex filename
before:
  36762     572      40   37374    91fe drivers/ata/libata-core.o
after:
  36627     572      40   37239    9177 drivers/ata/libata-core.o

Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
---
 drivers/ata/libata-core-sata.c | 33 +++++++++++++++++++++++++++++++++
 drivers/ata/libata-core.c      | 33 ---------------------------------
 drivers/ata/libata.h           |  7 +++++++
 3 files changed, 40 insertions(+), 33 deletions(-)

Comments

Christoph Hellwig Jan. 29, 2020, 5:28 p.m. UTC | #1
On Tue, Jan 28, 2020 at 02:33:28PM +0100, Bartlomiej Zolnierkiewicz wrote:
> * move ata_do_link_spd_horkage() to libata-core-sata.c
> 
> * add static inline for CONFIG_SATA_HOST=n case

Wouldn't it make more sense to stub out sata_scr_valid for the !SATA
case and just let the compiler optimize the function away now that it
can't be called in that case?
Bartlomiej Zolnierkiewicz Feb. 7, 2020, 2:23 p.m. UTC | #2
On 1/29/20 6:28 PM, Christoph Hellwig wrote:
> On Tue, Jan 28, 2020 at 02:33:28PM +0100, Bartlomiej Zolnierkiewicz wrote:
>> * move ata_do_link_spd_horkage() to libata-core-sata.c
>>
>> * add static inline for CONFIG_SATA_HOST=n case
> 
> Wouldn't it make more sense to stub out sata_scr_valid for the !SATA
> case and just let the compiler optimize the function away now that it
> can't be called in that case?

I've reworked the code to use this approach in v2 of the patchset.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
diff mbox series

Patch

diff --git a/drivers/ata/libata-core-sata.c b/drivers/ata/libata-core-sata.c
index 8b939d2db0a6..fed8009981c0 100644
--- a/drivers/ata/libata-core-sata.c
+++ b/drivers/ata/libata-core-sata.c
@@ -87,6 +87,39 @@  void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf)
 }
 EXPORT_SYMBOL_GPL(ata_tf_from_fis);
 
+int ata_do_link_spd_horkage(struct ata_device *dev)
+{
+	struct ata_link *plink = ata_dev_phys_link(dev);
+	u32 target, target_limit;
+
+	if (!sata_scr_valid(plink))
+		return 0;
+
+	if (dev->horkage & ATA_HORKAGE_1_5_GBPS)
+		target = 1;
+	else
+		return 0;
+
+	target_limit = (1 << target) - 1;
+
+	/* if already on stricter limit, no need to push further */
+	if (plink->sata_spd_limit <= target_limit)
+		return 0;
+
+	plink->sata_spd_limit = target_limit;
+
+	/* Request another EH round by returning -EAGAIN if link is
+	 * going faster than the target speed.  Forward progress is
+	 * guaranteed by setting sata_spd_limit to target_limit above.
+	 */
+	if (plink->sata_spd > target) {
+		ata_dev_info(dev, "applying link speed limit horkage to %s\n",
+			     sata_spd_string(target));
+		return -EAGAIN;
+	}
+	return 0;
+}
+
 /**
  *	sata_link_scr_lpm - manipulate SControl IPM and SPM fields
  *	@link: ATA link to manipulate SControl for
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 24b8ee668e6f..52bd81bad484 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2074,39 +2074,6 @@  static bool ata_identify_page_supported(struct ata_device *dev, u8 page)
 	return false;
 }
 
-static int ata_do_link_spd_horkage(struct ata_device *dev)
-{
-	struct ata_link *plink = ata_dev_phys_link(dev);
-	u32 target, target_limit;
-
-	if (!sata_scr_valid(plink))
-		return 0;
-
-	if (dev->horkage & ATA_HORKAGE_1_5_GBPS)
-		target = 1;
-	else
-		return 0;
-
-	target_limit = (1 << target) - 1;
-
-	/* if already on stricter limit, no need to push further */
-	if (plink->sata_spd_limit <= target_limit)
-		return 0;
-
-	plink->sata_spd_limit = target_limit;
-
-	/* Request another EH round by returning -EAGAIN if link is
-	 * going faster than the target speed.  Forward progress is
-	 * guaranteed by setting sata_spd_limit to target_limit above.
-	 */
-	if (plink->sata_spd > target) {
-		ata_dev_info(dev, "applying link speed limit horkage to %s\n",
-			     sata_spd_string(target));
-		return -EAGAIN;
-	}
-	return 0;
-}
-
 static inline u8 ata_dev_knobble(struct ata_device *dev)
 {
 	struct ata_port *ap = dev->link->ap;
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index cd8090ad43e5..9eebe4e0be39 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -87,6 +87,13 @@  extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
 
 #define to_ata_port(d) container_of(d, struct ata_port, tdev)
 
+/* libata-core-sata.c */
+#ifdef CONFIG_SATA_HOST
+int ata_do_link_spd_horkage(struct ata_device *dev);
+#else
+static inline int ata_do_link_spd_horkage(struct ata_device *dev) { return 0; }
+#endif
+
 /* libata-acpi.c */
 #ifdef CONFIG_ATA_ACPI
 extern unsigned int ata_acpi_gtf_filter;