Search Linux Wireless

Re: [PATCH V2] wlcore: sdio: Fixup power on/off sequence

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 18 Jan 2019 at 16:09, Ulf Hansson <ulf.hansson@xxxxxxxxxx> wrote:
>
> On Fri, 18 Jan 2019 at 13:09, Jan Kiszka <jan.kiszka@xxxxxx> wrote:
> >
> > On 17.01.19 10:54, Ulf Hansson wrote:
> > > On Wed, 16 Jan 2019 at 21:26, Jan Kiszka <jan.kiszka@xxxxxx> wrote:
> > >>
> > >> On 16.01.19 12:37, Ulf Hansson wrote:
> > >>> During "wlan-up", we are programming the FW into the WiFi-chip. However,
> > >>> re-programming the FW doesn't work, unless a power cycle of the WiFi-chip
> > >>> is made in-between the programmings.
> > >>>
> > >>> To conform to this requirement and to fix the regression in a simple way,
> > >>> let's start by allowing that the SDIO card (WiFi-chip) may stay powered on
> > >>> (runtime resumed) when wl12xx_sdio_power_off() returns. The intent with the
> > >>> current code is to treat this scenario as an error, but unfortunate this
> > >>> doesn't work as expected, so let's fix this.
> > >>>
> > >>> The other part is to guarantee that a power cycle of the SDIO card has been
> > >>> completed when wl12xx_sdio_power_on() returns, as to allow the FW
> > >>> programming to succeed. However, relying solely on runtime PM to deal with
> > >>> this isn't sufficient. For example, userspace may prevent runtime suspend
> > >>> via sysfs for the device that represents the SDIO card, leading to that the
> > >>> mmc core also keeps it powered on. For this reason, let's instead do a
> > >>> brute force power cycle in wl12xx_sdio_power_on().
> > >>>
> > >>> Fixes: 728a9dc61f13 ("wlcore: sdio: Fix flakey SDIO runtime PM handling")
> > >>> Signed-off-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
> > >>> ---
> > >>>
> > >>> Changes in v2:
> > >>>        - Keep the SDIO host claimed when calling mmc_hw_reset().
> > >>>        - Add a fixes tag.
> > >>> ---
> > >>>    drivers/net/wireless/ti/wlcore/sdio.c | 15 +++++++--------
> > >>>    1 file changed, 7 insertions(+), 8 deletions(-)
> > >>>
> > >>> diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c
> > >>> index bd10165d7eec..4d4b07701149 100644
> > >>> --- a/drivers/net/wireless/ti/wlcore/sdio.c
> > >>> +++ b/drivers/net/wireless/ti/wlcore/sdio.c
> > >>> @@ -164,6 +164,12 @@ static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
> > >>>        }
> > >>>
> > >>>        sdio_claim_host(func);
> > >>> +     /*
> > >>> +      * To guarantee that the SDIO card is power cycled, as required to make
> > >>> +      * the FW programming to succeed, let's do a brute force HW reset.
> > >>> +      */
> > >>> +     mmc_hw_reset(card->host);
> > >>> +
> > >>>        sdio_enable_func(func);
> > >>>        sdio_release_host(func);
> > >>>
> > >>> @@ -174,20 +180,13 @@ static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
> > >>>    {
> > >>>        struct sdio_func *func = dev_to_sdio_func(glue->dev);
> > >>>        struct mmc_card *card = func->card;
> > >>> -     int error;
> > >>>
> > >>>        sdio_claim_host(func);
> > >>>        sdio_disable_func(func);
> > >>>        sdio_release_host(func);
> > >>>
> > >>>        /* Let runtime PM know the card is powered off */
> > >>> -     error = pm_runtime_put(&card->dev);
> > >>> -     if (error < 0 && error != -EBUSY) {
> > >>> -             dev_err(&card->dev, "%s failed: %i\n", __func__, error);
> > >>> -
> > >>> -             return error;
> > >>> -     }
> > >>> -
> > >>> +     pm_runtime_put(&card->dev);
> > >>>        return 0;
> > >>>    }
> > >>>
> > >>>
> > >>
> > >> Just tested on both HiKey (620) and Ultra96 but it fails to fix the issue on
> > >> both. I'm getting
> > >>
> > >> wl1271_sdio: probe of mmc2:0001:1 failed with error -16
> > >>
> > >> during boot again, and the interface is not available.
> > >
> > > Okay, sounds like this may be a different problem then. Can you share
> > > the complete log and the kernel config?
> >
> > You can find the config here [1], log from the HiKey boot attached.
> >
> > > I can prepare a debug patch as well, if you are willing to re-run the test?
> >
> > Sure, send it over, I can run it.
>
> Alright, sounds great. However, I need to defer that to Monday/Tuesday
> next week.
>
> >
> > >
> > > Adding a post-power-on-delay-ms of 1 ms as you suggested [1], doesn't
> > > sounds like the correct solution to me, unless I am overlooking some
> > > things. The point is, since the mmc core succeeds to detect and
> > > initialize the SDIO card, the power sequence seems to be correct.
> >
> > Yeah, I'm not claiming at all I know what I'm doing there, just that it happens
> > to work.
>
> I see. Good to know, thanks!
>
> >
> > Jan
> >
> > [1]
> > https://github.com/siemens/jailhouse-images/blob/next/recipes-kernel/linux/files/arm64_defconfig_4.19
>
> I have looked through the log and the defconfig. No obvious things
> found at this point. Thanks for sharing them!
>

So, I have put together a debug patch, mostly to verify that things
seems to be correct in regards to runtime PM. It should produce some
prints to the log, particular during power on/off of the SDIO card and
during probe of the wifi driver. Please re-run the test on top of the
v2 version of the $subject patch.

Kind regards
Uffe
From ef7890463ae9bec8fab7d16448681923736706e3 Mon Sep 17 00:00:00 2001
From: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
Date: Mon, 21 Jan 2019 15:31:57 +0100
Subject: [PATCH] wlcore/sdio/mmc: Debug for runtime PM and power on/off of
 SDIO

Signed-off-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
---
 drivers/mmc/core/pwrseq_simple.c      |  2 ++
 drivers/mmc/core/sdio.c               | 19 +++++++++++++++++--
 drivers/mmc/core/sdio_bus.c           | 26 +++++++++++++++++++++++---
 drivers/net/wireless/ti/wlcore/sdio.c | 27 ++++++++++++++++++++++++++-
 4 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c
index ece34c734693..b9b1fc73a5a0 100644
--- a/drivers/mmc/core/pwrseq_simple.c
+++ b/drivers/mmc/core/pwrseq_simple.c
@@ -66,6 +66,7 @@ static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host)
 	if (!IS_ERR(pwrseq->ext_clk) && !pwrseq->clk_enabled) {
 		clk_prepare_enable(pwrseq->ext_clk);
 		pwrseq->clk_enabled = true;
+		dev_info(mmc_dev(host), "%s clk_prepare_enable()\n", __func__);
 	}
 
 	mmc_pwrseq_simple_set_gpios_value(pwrseq, 1);
@@ -94,6 +95,7 @@ static void mmc_pwrseq_simple_power_off(struct mmc_host *host)
 	if (!IS_ERR(pwrseq->ext_clk) && pwrseq->clk_enabled) {
 		clk_disable_unprepare(pwrseq->ext_clk);
 		pwrseq->clk_enabled = false;
+		dev_info(mmc_dev(host), "%s clk_disable_unprepare()\n", __func__);
 	}
 }
 
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index d8e17ea6126d..ce7d29ad2651 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -1029,11 +1029,13 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
 
 static int mmc_sdio_runtime_suspend(struct mmc_host *host)
 {
+	dev_info(&host->card->dev, "%s\n", __func__);
 	/* No references to the card, cut the power to it. */
 	mmc_claim_host(host);
 	mmc_power_off(host);
 	mmc_release_host(host);
 
+	dev_info(&host->card->dev, "%s - DONE\n", __func__);
 	return 0;
 }
 
@@ -1041,19 +1043,27 @@ static int mmc_sdio_runtime_resume(struct mmc_host *host)
 {
 	int ret;
 
+	dev_info(&host->card->dev, "%s\n", __func__);
 	/* Restore power and re-initialize. */
 	mmc_claim_host(host);
 	mmc_power_up(host, host->card->ocr);
 	ret = mmc_sdio_power_restore(host);
 	mmc_release_host(host);
 
+	dev_info(&host->card->dev, "%s - ret=%d DONE\n", __func__, ret);
 	return ret;
 }
 
 static int mmc_sdio_hw_reset(struct mmc_host *host)
 {
+	int ret;
+
+	dev_info(&host->card->dev, "%s\n", __func__);
 	mmc_power_cycle(host, host->card->ocr);
-	return mmc_sdio_power_restore(host);
+	ret = mmc_sdio_power_restore(host);
+
+	dev_info(&host->card->dev, "%s - ret=%d DONE\n", __func__, ret);
+	return ret;
 }
 
 static int mmc_sdio_sw_reset(struct mmc_host *host)
@@ -1142,6 +1152,8 @@ int mmc_attach_sdio(struct mmc_host *host)
 		 * Enable runtime PM for this card
 		 */
 		pm_runtime_enable(&card->dev);
+
+		dev_info(&card->dev, "%s Enabled runtime PM()\n", __func__);
 	}
 
 	/*
@@ -1183,8 +1195,11 @@ int mmc_attach_sdio(struct mmc_host *host)
 			goto remove_added;
 	}
 
-	if (host->caps & MMC_CAP_POWER_OFF_CARD)
+
+	if (host->caps & MMC_CAP_POWER_OFF_CARD) {
+		dev_info(&card->dev, "%s pm_runtime_put()\n", __func__);
 		pm_runtime_put(&card->dev);
+	}
 
 	mmc_claim_host(host);
 	return 0;
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index b6d8203e46eb..e4357ce188ef 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -134,6 +134,8 @@ static int sdio_bus_probe(struct device *dev)
 	const struct sdio_device_id *id;
 	int ret;
 
+	dev_info(dev, "%s\n", __func__);
+
 	id = sdio_match_device(func, drv);
 	if (!id)
 		return -ENODEV;
@@ -149,6 +151,7 @@ static int sdio_bus_probe(struct device *dev)
 	 * pm_runtime_get_noresume() in its remove routine.
 	 */
 	if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD) {
+		dev_info(dev, "%s - pm_runtime_get_sync()\n", __func__);
 		ret = pm_runtime_get_sync(dev);
 		if (ret < 0)
 			goto disable_runtimepm;
@@ -166,11 +169,14 @@ static int sdio_bus_probe(struct device *dev)
 	if (ret)
 		goto disable_runtimepm;
 
+	dev_info(dev, "%s - probe OK\n", __func__);
 	return 0;
 
 disable_runtimepm:
-	if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD)
+	if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD) {
+		dev_info(dev, "%s - ERR call pm_runtime_put_noidle()\n", __func__);
 		pm_runtime_put_noidle(dev);
+	}
 	dev_pm_domain_detach(dev, false);
 	return ret;
 }
@@ -208,11 +214,25 @@ static int sdio_bus_remove(struct device *dev)
 	return ret;
 }
 
+#ifdef CONFIG_PM
+static int sdio_bus_runtime_suspend(struct device *dev)
+{
+	dev_info(dev, "%s\n", __func__);
+	return pm_generic_runtime_suspend(dev);
+}
+
+static int sdio_bus_runtime_resume(struct device *dev)
+{
+	dev_info(dev, "%s\n", __func__);
+	return pm_generic_runtime_resume(dev);
+}
+#endif
+
 static const struct dev_pm_ops sdio_bus_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_generic_suspend, pm_generic_resume)
 	SET_RUNTIME_PM_OPS(
-		pm_generic_runtime_suspend,
-		pm_generic_runtime_resume,
+		sdio_bus_runtime_suspend,
+		sdio_bus_runtime_resume,
 		NULL
 	)
 };
diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c
index 4d4b07701149..0a82a11cae97 100644
--- a/drivers/net/wireless/ti/wlcore/sdio.c
+++ b/drivers/net/wireless/ti/wlcore/sdio.c
@@ -154,6 +154,8 @@ static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
 	struct sdio_func *func = dev_to_sdio_func(glue->dev);
 	struct mmc_card *card = func->card;
 
+	dev_info(glue->dev, "%s: STEP1\n", __func__);
+
 	ret = pm_runtime_get_sync(&card->dev);
 	if (ret < 0) {
 		pm_runtime_put_noidle(&card->dev);
@@ -163,7 +165,12 @@ static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
 		return ret;
 	}
 
+	dev_info(glue->dev, "%s: STEP2\n", __func__);
+
 	sdio_claim_host(func);
+
+	dev_info(glue->dev, "%s: STEP3\n", __func__);
+
 	/*
 	 * To guarantee that the SDIO card is power cycled, as required to make
 	 * the FW programming to succeed, let's do a brute force HW reset.
@@ -171,8 +178,12 @@ static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
 	mmc_hw_reset(card->host);
 
 	sdio_enable_func(func);
+
+	dev_info(glue->dev, "%s: STEP4\n", __func__);
+
 	sdio_release_host(func);
 
+	dev_info(glue->dev, "%s: STEP5\n", __func__);
 	return 0;
 }
 
@@ -181,12 +192,20 @@ static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
 	struct sdio_func *func = dev_to_sdio_func(glue->dev);
 	struct mmc_card *card = func->card;
 
+	dev_info(glue->dev, "%s: STEP1\n", __func__);
+
 	sdio_claim_host(func);
 	sdio_disable_func(func);
+
+	dev_info(glue->dev, "%s: STEP2\n", __func__);
 	sdio_release_host(func);
 
+
+	dev_info(glue->dev, "%s: STEP3\n", __func__);
 	/* Let runtime PM know the card is powered off */
 	pm_runtime_put(&card->dev);
+
+	dev_info(glue->dev, "%s: STEP4\n", __func__);
 	return 0;
 }
 
@@ -315,7 +334,7 @@ static int wl1271_probe(struct sdio_func *func,
 
 	/* if sdio can keep power while host is suspended, enable wow */
 	mmcflags = sdio_get_host_pm_caps(func);
-	dev_dbg(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
+	dev_info(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
 
 	if (mmcflags & MMC_PM_KEEP_POWER)
 		pdev_data->pwr_in_suspend = true;
@@ -336,6 +355,8 @@ static int wl1271_probe(struct sdio_func *func,
 	else
 		chip_family = "wl12xx";
 
+	dev_info(glue->dev, "chip_family is %s\n", chip_family);
+
 	glue->core = platform_device_alloc(chip_family, PLATFORM_DEVID_AUTO);
 	if (!glue->core) {
 		dev_err(glue->dev, "can't allocate platform_device");
@@ -375,11 +396,15 @@ static int wl1271_probe(struct sdio_func *func,
 		goto out_dev_put;
 	}
 
+	dev_info(glue->dev, "About to add core dev (child)...\n");
+
 	ret = platform_device_add(glue->core);
 	if (ret) {
 		dev_err(glue->dev, "can't add platform device\n");
 		goto out_dev_put;
 	}
+
+	dev_info(glue->dev, "...added core dev (child) - probe complete!\n");
 	return 0;
 
 out_dev_put:
-- 
2.17.1


[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux