diff mbox series

[RFC,01/10] mmc: core: improve API to make clear mmc_hw_reset is for cards

Message ID 20220321115059.21803-2-wsa+renesas@sang-engineering.com (mailing list archive)
State New, archived
Headers show
Series mmc: improve API to make clear {h|s}w_reset is for cards | expand

Commit Message

Wolfram Sang March 21, 2022, 11:50 a.m. UTC
To make it unambiguous that mmc_hw_reset() is for cards and not for
controllers, we a) add 'card' to the function name and b) make the
function argument mmc_card instead of mmc_host. A fallback is provided
until all users are converted.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/mmc/core/block.c    |  2 +-
 drivers/mmc/core/core.c     | 18 +++++++++++++-----
 drivers/mmc/core/mmc_test.c |  3 +--
 include/linux/mmc/core.h    |  1 +
 4 files changed, 16 insertions(+), 8 deletions(-)

Comments

Ulf Hansson April 4, 2022, 12:05 p.m. UTC | #1
On Mon, 21 Mar 2022 at 12:51, Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
>
> To make it unambiguous that mmc_hw_reset() is for cards and not for
> controllers, we a) add 'card' to the function name and b) make the
> function argument mmc_card instead of mmc_host. A fallback is provided
> until all users are converted.

In my opinion, I think b) is sufficient and would be a nice improvement.

In this regard, I suggest we make one big cross-subsystem patch (the
smallest change as possible) then I can pick it up and send it for the
v5.18-rc2.

Br
Uffe

>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  drivers/mmc/core/block.c    |  2 +-
>  drivers/mmc/core/core.c     | 18 +++++++++++++-----
>  drivers/mmc/core/mmc_test.c |  3 +--
>  include/linux/mmc/core.h    |  1 +
>  4 files changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 4e67c1403cc9..74674a4650b0 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -993,7 +993,7 @@ static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
>                 return -EEXIST;
>
>         md->reset_done |= type;
> -       err = mmc_hw_reset(host);
> +       err = mmc_card_hw_reset(host->card);
>         /* Ensure we switch back to the correct partition */
>         if (err) {
>                 struct mmc_blk_data *main_md =
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 368f10405e13..71e75196bc53 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -1984,7 +1984,8 @@ int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen)
>  }
>  EXPORT_SYMBOL(mmc_set_blocklen);
>
> -static void mmc_hw_reset_for_init(struct mmc_host *host)
> +/* we can't use mmc_card as a parameter, it is not populated yet */

Please drop this. The function is internal/static and at least to me,
rather self-explanatory.

[...]

Kind regards
Uffe
Wolfram Sang April 6, 2022, 7:58 a.m. UTC | #2
Hi Ulf,

> > To make it unambiguous that mmc_hw_reset() is for cards and not for
> > controllers, we a) add 'card' to the function name and b) make the
> > function argument mmc_card instead of mmc_host. A fallback is provided
> > until all users are converted.
> 
> In my opinion, I think b) is sufficient and would be a nice improvement.

If you say so... but I do wonder why we can't be super clear with the
function name alone without the function argument as an additional
source of information? Kernel hacking is complicated enough.

> In this regard, I suggest we make one big cross-subsystem patch (the
> smallest change as possible) then I can pick it up and send it for the
> v5.18-rc2.

Ok, I can prepare this.

> > -static void mmc_hw_reset_for_init(struct mmc_host *host)
> > +/* we can't use mmc_card as a parameter, it is not populated yet */
> 
> Please drop this. The function is internal/static and at least to me,
> rather self-explanatory.

All other ?w_reset() functions have a card as a parameter. For people
trying to get into the MMC core, this comment might be helpful to
understand the anomaly? I know that you as the maintainer do know this
by heart, this comment is meant for people learning the stuff.

All the best,

   Wolfram
Ulf Hansson April 6, 2022, 1:53 p.m. UTC | #3
On Wed, 6 Apr 2022 at 09:58, Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
>
> Hi Ulf,
>
> > > To make it unambiguous that mmc_hw_reset() is for cards and not for
> > > controllers, we a) add 'card' to the function name and b) make the
> > > function argument mmc_card instead of mmc_host. A fallback is provided
> > > until all users are converted.
> >
> > In my opinion, I think b) is sufficient and would be a nice improvement.
>
> If you say so... but I do wonder why we can't be super clear with the
> function name alone without the function argument as an additional
> source of information? Kernel hacking is complicated enough.
>
> > In this regard, I suggest we make one big cross-subsystem patch (the
> > smallest change as possible) then I can pick it up and send it for the
> > v5.18-rc2.
>
> Ok, I can prepare this.

Great!

>
> > > -static void mmc_hw_reset_for_init(struct mmc_host *host)
> > > +/* we can't use mmc_card as a parameter, it is not populated yet */
> >
> > Please drop this. The function is internal/static and at least to me,
> > rather self-explanatory.
>
> All other ?w_reset() functions have a card as a parameter. For people
> trying to get into the MMC core, this comment might be helpful to
> understand the anomaly? I know that you as the maintainer do know this
> by heart, this comment is meant for people learning the stuff.

I understand your point, however I don't think it makes much sense to
try to clarify the names on mmc_hw|sw_reset() alone. There are simply
lots of other functions that then would need to be changed too.
Otherwise we would just end up with having even more in-consistency in
function namings. To me, that's even worse.

>
> All the best,
>
>    Wolfram

Kind regards
Uffe
Wolfram Sang April 7, 2022, 8:24 p.m. UTC | #4
> I understand your point, however I don't think it makes much sense to
> try to clarify the names on mmc_hw|sw_reset() alone. There are simply
> lots of other functions that then would need to be changed too.
> Otherwise we would just end up with having even more in-consistency in
> function namings. To me, that's even worse.

OK, I will follow your suggestions.
diff mbox series

Patch

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 4e67c1403cc9..74674a4650b0 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -993,7 +993,7 @@  static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
 		return -EEXIST;
 
 	md->reset_done |= type;
-	err = mmc_hw_reset(host);
+	err = mmc_card_hw_reset(host->card);
 	/* Ensure we switch back to the correct partition */
 	if (err) {
 		struct mmc_blk_data *main_md =
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 368f10405e13..71e75196bc53 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1984,7 +1984,8 @@  int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen)
 }
 EXPORT_SYMBOL(mmc_set_blocklen);
 
-static void mmc_hw_reset_for_init(struct mmc_host *host)
+/* we can't use mmc_card as a parameter, it is not populated yet */
+static void mmc_card_hw_reset_for_init(struct mmc_host *host)
 {
 	mmc_pwrseq_reset(host);
 
@@ -1994,8 +1995,8 @@  static void mmc_hw_reset_for_init(struct mmc_host *host)
 }
 
 /**
- * mmc_hw_reset - reset the card in hardware
- * @host: MMC host to which the card is attached
+ * mmc_card_hw_reset - reset the card in hardware
+ * @card: card to be reset
  *
  * Hard reset the card. This function is only for upper layers, like the
  * block layer or card drivers. You cannot use it in host drivers (struct
@@ -2003,8 +2004,9 @@  static void mmc_hw_reset_for_init(struct mmc_host *host)
  *
  * Return: 0 on success, -errno on failure
  */
-int mmc_hw_reset(struct mmc_host *host)
+int mmc_card_hw_reset(struct mmc_card *card)
 {
+	struct mmc_host *host = card->host;
 	int ret;
 
 	ret = host->bus_ops->hw_reset(host);
@@ -2014,6 +2016,12 @@  int mmc_hw_reset(struct mmc_host *host)
 
 	return ret;
 }
+EXPORT_SYMBOL(mmc_card_hw_reset);
+
+int mmc_hw_reset(struct mmc_host *host)
+{
+	return mmc_card_hw_reset(host->card);
+}
 EXPORT_SYMBOL(mmc_hw_reset);
 
 int mmc_sw_reset(struct mmc_host *host)
@@ -2045,7 +2053,7 @@  static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
 	 * Some eMMCs (with VCCQ always on) may not be reset after power up, so
 	 * do a hardware reset if possible.
 	 */
-	mmc_hw_reset_for_init(host);
+	mmc_card_hw_reset_for_init(host);
 
 	/*
 	 * sdio_reset sends CMD52 to reset card.  Since we do not know
diff --git a/drivers/mmc/core/mmc_test.c b/drivers/mmc/core/mmc_test.c
index e6a2fd2c6d5c..bfcae8f79cbd 100644
--- a/drivers/mmc/core/mmc_test.c
+++ b/drivers/mmc/core/mmc_test.c
@@ -2325,10 +2325,9 @@  static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
 static int mmc_test_reset(struct mmc_test_card *test)
 {
 	struct mmc_card *card = test->card;
-	struct mmc_host *host = card->host;
 	int err;
 
-	err = mmc_hw_reset(host);
+	err = mmc_card_hw_reset(card);
 	if (!err) {
 		/*
 		 * Reset will re-enable the card's command queue, but tests
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 71101d1ec825..25a7cf69d919 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -176,6 +176,7 @@  int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd,
 		int retries);
 
 int mmc_hw_reset(struct mmc_host *host);
+int mmc_card_hw_reset(struct mmc_card *card);
 int mmc_sw_reset(struct mmc_host *host);
 void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card);