linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Michael Schmitz <schmitzmic@gmail.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Christoph Hellwig <hch@lst.de>,
	linux-ide@vger.kernel.org, linux-m68k@lists.linux-m68k.org,
	linux-kernel@vger.kernel.org, b.zolnierkie@samsung.com
Subject: [PATCH v3 20/27] ata: move sata_link_hardreset() to libata-sata.c
Date: Thu, 27 Feb 2020 19:22:19 +0100	[thread overview]
Message-ID: <20200227182226.19188-21-b.zolnierkie@samsung.com> (raw)
In-Reply-To: <20200227182226.19188-1-b.zolnierkie@samsung.com>

* move sata_link_hardreset() to libata-sata.c

* add static inline for CONFIG_SATA_HOST=n case

* make sata_set_spd_needed() static

Code size savings on m68k arch using (modified) atari_defconfig:

   text    data     bss     dec     hex filename
before:
  32724     572      40   33336    8238 drivers/ata/libata-core.o
after:
  32559     572      40   33171    8193 drivers/ata/libata-core.o

Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
---
 drivers/ata/libata-core.c | 113 -------------------------------------
 drivers/ata/libata-sata.c | 115 +++++++++++++++++++++++++++++++++++++-
 drivers/ata/libata.h      |   7 ---
 include/linux/libata.h    |  16 +++++-
 4 files changed, 127 insertions(+), 124 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 4ca81ef7c8bd..19624d056d92 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -3531,119 +3531,6 @@ int ata_std_prereset(struct ata_link *link, unsigned long deadline)
 }
 EXPORT_SYMBOL_GPL(ata_std_prereset);
 
-/**
- *	sata_link_hardreset - reset link via SATA phy reset
- *	@link: link to reset
- *	@timing: timing parameters { interval, duration, timeout } in msec
- *	@deadline: deadline jiffies for the operation
- *	@online: optional out parameter indicating link onlineness
- *	@check_ready: optional callback to check link readiness
- *
- *	SATA phy-reset @link using DET bits of SControl register.
- *	After hardreset, link readiness is waited upon using
- *	ata_wait_ready() if @check_ready is specified.  LLDs are
- *	allowed to not specify @check_ready and wait itself after this
- *	function returns.  Device classification is LLD's
- *	responsibility.
- *
- *	*@online is set to one iff reset succeeded and @link is online
- *	after reset.
- *
- *	LOCKING:
- *	Kernel thread context (may sleep)
- *
- *	RETURNS:
- *	0 on success, -errno otherwise.
- */
-int sata_link_hardreset(struct ata_link *link, const unsigned long *timing,
-			unsigned long deadline,
-			bool *online, int (*check_ready)(struct ata_link *))
-{
-	u32 scontrol;
-	int rc;
-
-	DPRINTK("ENTER\n");
-
-	if (online)
-		*online = false;
-
-	if (sata_set_spd_needed(link)) {
-		/* SATA spec says nothing about how to reconfigure
-		 * spd.  To be on the safe side, turn off phy during
-		 * reconfiguration.  This works for at least ICH7 AHCI
-		 * and Sil3124.
-		 */
-		if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
-			goto out;
-
-		scontrol = (scontrol & 0x0f0) | 0x304;
-
-		if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
-			goto out;
-
-		sata_set_spd(link);
-	}
-
-	/* issue phy wake/reset */
-	if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
-		goto out;
-
-	scontrol = (scontrol & 0x0f0) | 0x301;
-
-	if ((rc = sata_scr_write_flush(link, SCR_CONTROL, scontrol)))
-		goto out;
-
-	/* Couldn't find anything in SATA I/II specs, but AHCI-1.1
-	 * 10.4.2 says at least 1 ms.
-	 */
-	ata_msleep(link->ap, 1);
-
-	/* bring link back */
-	rc = sata_link_resume(link, timing, deadline);
-	if (rc)
-		goto out;
-	/* if link is offline nothing more to do */
-	if (ata_phys_link_offline(link))
-		goto out;
-
-	/* Link is online.  From this point, -ENODEV too is an error. */
-	if (online)
-		*online = true;
-
-	if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) {
-		/* If PMP is supported, we have to do follow-up SRST.
-		 * Some PMPs don't send D2H Reg FIS after hardreset if
-		 * the first port is empty.  Wait only for
-		 * ATA_TMOUT_PMP_SRST_WAIT.
-		 */
-		if (check_ready) {
-			unsigned long pmp_deadline;
-
-			pmp_deadline = ata_deadline(jiffies,
-						    ATA_TMOUT_PMP_SRST_WAIT);
-			if (time_after(pmp_deadline, deadline))
-				pmp_deadline = deadline;
-			ata_wait_ready(link, pmp_deadline, check_ready);
-		}
-		rc = -EAGAIN;
-		goto out;
-	}
-
-	rc = 0;
-	if (check_ready)
-		rc = ata_wait_ready(link, deadline, check_ready);
- out:
-	if (rc && rc != -EAGAIN) {
-		/* online is set iff link is online && reset succeeded */
-		if (online)
-			*online = false;
-		ata_link_err(link, "COMRESET failed (errno=%d)\n", rc);
-	}
-	DPRINTK("EXIT, rc=%d\n", rc);
-	return rc;
-}
-EXPORT_SYMBOL_GPL(sata_link_hardreset);
-
 /**
  *	sata_std_hardreset - COMRESET w/o waiting or classification
  *	@link: link to reset
diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index 34852fced999..05a1872ba329 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -449,7 +449,7 @@ static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol)
  *	RETURNS:
  *	1 if SATA spd configuration is needed, 0 otherwise.
  */
-int sata_set_spd_needed(struct ata_link *link)
+static int sata_set_spd_needed(struct ata_link *link)
 {
 	u32 scontrol;
 
@@ -490,6 +490,119 @@ int sata_set_spd(struct ata_link *link)
 }
 EXPORT_SYMBOL_GPL(sata_set_spd);
 
+/**
+ *	sata_link_hardreset - reset link via SATA phy reset
+ *	@link: link to reset
+ *	@timing: timing parameters { interval, duration, timeout } in msec
+ *	@deadline: deadline jiffies for the operation
+ *	@online: optional out parameter indicating link onlineness
+ *	@check_ready: optional callback to check link readiness
+ *
+ *	SATA phy-reset @link using DET bits of SControl register.
+ *	After hardreset, link readiness is waited upon using
+ *	ata_wait_ready() if @check_ready is specified.  LLDs are
+ *	allowed to not specify @check_ready and wait itself after this
+ *	function returns.  Device classification is LLD's
+ *	responsibility.
+ *
+ *	*@online is set to one iff reset succeeded and @link is online
+ *	after reset.
+ *
+ *	LOCKING:
+ *	Kernel thread context (may sleep)
+ *
+ *	RETURNS:
+ *	0 on success, -errno otherwise.
+ */
+int sata_link_hardreset(struct ata_link *link, const unsigned long *timing,
+			unsigned long deadline,
+			bool *online, int (*check_ready)(struct ata_link *))
+{
+	u32 scontrol;
+	int rc;
+
+	DPRINTK("ENTER\n");
+
+	if (online)
+		*online = false;
+
+	if (sata_set_spd_needed(link)) {
+		/* SATA spec says nothing about how to reconfigure
+		 * spd.  To be on the safe side, turn off phy during
+		 * reconfiguration.  This works for at least ICH7 AHCI
+		 * and Sil3124.
+		 */
+		if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
+			goto out;
+
+		scontrol = (scontrol & 0x0f0) | 0x304;
+
+		if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
+			goto out;
+
+		sata_set_spd(link);
+	}
+
+	/* issue phy wake/reset */
+	if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
+		goto out;
+
+	scontrol = (scontrol & 0x0f0) | 0x301;
+
+	if ((rc = sata_scr_write_flush(link, SCR_CONTROL, scontrol)))
+		goto out;
+
+	/* Couldn't find anything in SATA I/II specs, but AHCI-1.1
+	 * 10.4.2 says at least 1 ms.
+	 */
+	ata_msleep(link->ap, 1);
+
+	/* bring link back */
+	rc = sata_link_resume(link, timing, deadline);
+	if (rc)
+		goto out;
+	/* if link is offline nothing more to do */
+	if (ata_phys_link_offline(link))
+		goto out;
+
+	/* Link is online.  From this point, -ENODEV too is an error. */
+	if (online)
+		*online = true;
+
+	if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) {
+		/* If PMP is supported, we have to do follow-up SRST.
+		 * Some PMPs don't send D2H Reg FIS after hardreset if
+		 * the first port is empty.  Wait only for
+		 * ATA_TMOUT_PMP_SRST_WAIT.
+		 */
+		if (check_ready) {
+			unsigned long pmp_deadline;
+
+			pmp_deadline = ata_deadline(jiffies,
+						    ATA_TMOUT_PMP_SRST_WAIT);
+			if (time_after(pmp_deadline, deadline))
+				pmp_deadline = deadline;
+			ata_wait_ready(link, pmp_deadline, check_ready);
+		}
+		rc = -EAGAIN;
+		goto out;
+	}
+
+	rc = 0;
+	if (check_ready)
+		rc = ata_wait_ready(link, deadline, check_ready);
+ out:
+	if (rc && rc != -EAGAIN) {
+		/* online is set iff link is online && reset succeeded */
+		if (online)
+			*online = false;
+		ata_link_err(link, "COMRESET failed (errno=%d)\n", rc);
+	}
+	DPRINTK("EXIT, rc=%d\n", rc);
+	return rc;
+}
+EXPORT_SYMBOL_GPL(sata_link_hardreset);
+
 /**
  *	ata_slave_link_init - initialize slave link
  *	@ap: port to initialize slave link for
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 53b45ebe3d55..cd8090ad43e5 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -87,13 +87,6 @@ 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-sata.c */
-#ifdef CONFIG_SATA_HOST
-int sata_set_spd_needed(struct ata_link *link);
-#else
-static inline int sata_set_spd_needed(struct ata_link *link) { return 1; }
-#endif
-
 /* libata-acpi.c */
 #ifdef CONFIG_ATA_ACPI
 extern unsigned int ata_acpi_gtf_filter;
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 3981e413f582..bf13af0c47ae 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1079,9 +1079,6 @@ static inline int ata_port_is_dummy(struct ata_port *ap)
 extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
 extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
 				int (*check_ready)(struct ata_link *link));
-extern int sata_link_hardreset(struct ata_link *link,
-			const unsigned long *timing, unsigned long deadline,
-			bool *online, int (*check_ready)(struct ata_link *));
 extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
 			      unsigned long deadline);
 extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
@@ -1192,6 +1189,9 @@ extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
 extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
 extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
 extern int sata_set_spd(struct ata_link *link);
+extern int sata_link_hardreset(struct ata_link *link,
+			const unsigned long *timing, unsigned long deadline,
+			bool *online, int (*check_ready)(struct ata_link *));
 extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
 			    unsigned long deadline);
 #else
@@ -1209,6 +1209,16 @@ static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
 	return -EOPNOTSUPP;
 }
 static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
+static inline int sata_link_hardreset(struct ata_link *link,
+				      const unsigned long *timing,
+				      unsigned long deadline,
+				      bool *online,
+				      int (*check_ready)(struct ata_link *))
+{
+	if (online)
+		*online = false;
+	return -EOPNOTSUPP;
+}
 static inline int sata_link_resume(struct ata_link *link,
 				   const unsigned long *params,
 				   unsigned long deadline)
-- 
2.24.1


  parent reply	other threads:[~2020-02-27 18:23 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200227182238eucas1p1a4a5546e46b2385057f41528bd759aea@eucas1p1.samsung.com>
2020-02-27 18:21 ` [PATCH v3 00/27] ata: optimize core code size on PATA only setups Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182239eucas1p1166cd4b92fc84479634d6bcf67a672cf@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 01/27] ata: remove stale maintainership information from core code Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182239eucas1p2fe76dcb686bea8f0a527461807b9292e@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 02/27] ata: expose ncq_enable_prio sysfs attribute only on NCQ capable hosts Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182240eucas1p1035546a1fb97cfb9920542af289bf5ca@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 03/27] ata: make SATA_PMP option selectable only if any SATA host driver is enabled Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182240eucas1p272bac5df6668bbb7fee7638b4022a7b1@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 04/27] sata_promise: use ata_cable_sata() Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182241eucas1p10cf24570346137befa34c6fd800db058@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 05/27] ata: simplify ata_scsiop_inq_89() Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182241eucas1p12ef86c45356afb2230871d84dab04431@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 06/27] ata: use COMMAND_LINE_SIZE for ata_force_param_buf[] size Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182242eucas1p16f2af7ee2771f11f21f35c7f80636723@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 07/27] ata: optimize struct ata_force_param size Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182242eucas1p1c1de818156ec670f4744725618375303@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 08/27] ata: optimize ata_scsi_rbuf[] size Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182243eucas1p138c6ac2b516bf318680498caf05ed8df@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 09/27] ata: move EXPORT_SYMBOL_GPL()s close to exported code Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182243eucas1p2d95b61a6a3941ffd3bbead3a6ff4a813@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 10/27] ata: remove EXPORT_SYMBOL_GPL()s not used by modules Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182244eucas1p1e8e9e9567acda2a8cd02844685b6b12a@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 11/27] ata: fix CodingStyle issues in PATA timings code Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182244eucas1p200b1a33d037208b1998a2c9c659ae6f6@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 12/27] ata: separate PATA timings code from libata-core.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182245eucas1p219dee00956358ee0018caf2a07a8d602@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 13/27] ata: add CONFIG_SATA_HOST=n version of ata_ncq_enabled() Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182245eucas1p22d7a52d7786fc8cdfa4dc898662ef087@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 14/27] ata: let compiler optimize out ata_dev_config_ncq() on non-SATA hosts Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182246eucas1p2b20cf3379bb774d236e53301e2180252@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 15/27] ata: let compiler optimize out ata_eh_set_lpm() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182246eucas1p1d189bdc4d74efcd0c08193ce81b7acd7@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 16/27] ata: start separating SATA specific code from libata-core.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182247eucas1p2d83a212c200832402cc17817fab4f650@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 17/27] ata: move sata_scr_*() to libata-sata.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182247eucas1p1e9042300d9ad7dd56a1319afb980bdfe@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 18/27] ata: move *sata_set_spd*() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182248eucas1p12ce0e7ce8d0653085591eea64604c656@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 19/27] ata: move sata_link_{debounce,resume}() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182248eucas1p296773cdb2ab7ae9f4114f7052ff08414@eucas1p2.samsung.com>
2020-02-27 18:22     ` Bartlomiej Zolnierkiewicz [this message]
     [not found]   ` <CGME20200227182248eucas1p12149429eae76c2a869d7323ab9abff1e@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 21/27] ata: move ata_qc_complete_multiple() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182249eucas1p14e64b8693929cd84a289909bbdb4506e@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 22/27] ata: move sata_deb_timing_*() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182249eucas1p19b8af9cc8b7e8fac33cf400702322c7d@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 23/27] ata: start separating SATA specific code from libata-scsi.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182250eucas1p1885e8264beb19b9d6eba638748fd1ff0@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 24/27] ata: move ata_sas_*() to libata-sata.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182250eucas1p2140d4ae6f3f65f2b712027dab63de3bd@eucas1p2.samsung.com>
2020-02-27 18:22     ` [PATCH v3 25/27] ata: start separating SATA specific code from libata-eh.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182251eucas1p1857e44a8f0860829e821748464bb936d@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 26/27] ata: move ata_eh_analyze_ncq_error() & co. to libata-sata.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200227182251eucas1p1f8f29d3df1a07a6997e3b7c3a3176cb3@eucas1p1.samsung.com>
2020-02-27 18:22     ` [PATCH v3 27/27] ata: make "libata.force" kernel parameter optional Bartlomiej Zolnierkiewicz
2020-03-12 14:09   ` [PATCH v3 00/27] ata: optimize core code size on PATA only setups Jens Axboe

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20200227182226.19188-21-b.zolnierkie@samsung.com \
    --to=b.zolnierkie@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=geert@linux-m68k.org \
    --cc=hch@lst.de \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=schmitzmic@gmail.com \
    /path/to/YOUR_REPLY

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

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