Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp514273ybg; Fri, 18 Oct 2019 03:20:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaatIut9vtY5buniANSU3YaLgRWmBtsJEXUcflNIFWkkb/VsHKQTMyg1l2XN+LM0NhgPOG X-Received: by 2002:a50:f384:: with SMTP id g4mr8567318edm.282.1571394033921; Fri, 18 Oct 2019 03:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571394033; cv=none; d=google.com; s=arc-20160816; b=M+it8ufRtyjKTAzdMnnvb4GOQdepfV1hZglng9LvOQM/sQD2dHd/8UAAs1su9gnYyD gZb0QuHMk5TTf3Ta4XJjIH3Q+08vMyo200MuTQaiqG74t61RXMgbWKtD4mN1M2y5BQXc x0PjHFENO5nQzD6d03liivjHCeNry0XVD3mU6LklRH983Gd0Z4m6l0fTzP9kKcOS/ndT WkW5QtuHl444NEgOJRP4wYZvqcOKyy691Q+svik04+5qBGbczw/ycZSjNL07AUDuWX6o eK7NCZPibbNAfoN2stDaRug3n5rOr05XNa90vwDYEH2vBBGJnWB3RvsFE7K7Ob5o3upR 38+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=04hgzc9qmWLKJ4qr0kQdZsxTdQTI10306q/6E8gxvtc=; b=spxDZaA+MJbxQdGSjXedMdhv30kXFn3ZC5bEMDMZkb7BytgJh4Jm00QrG3wWPDCzAq DATvgPiO2nXZfXbSi+VZKPbEFiMWOzCRneuZSetqkUIxWnw+y3uafa1GZSzMFDxLF8T/ aCvyDGvPuhO1ZhIej68CzV7AoeOT2des9KnajW9fUhCzoEiH1+ptW6P0ueDpysODXeam BM2cxU962YDXPhDQGDuIq3JLFT/BZcgTe2n9QwlsWa5vaEzT/AdmycHVC28nnEofGAZz y0wyPs+Fqcy2gjdI0zJmsVe+GrQYAqWnab3PzToAMhBjbuHzH9r3dEsgXgF2LSLJ7c7q onhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="AqiK/AqA"; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l15si3091399ejz.74.2019.10.18.03.19.57; Fri, 18 Oct 2019 03:20:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="AqiK/AqA"; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408449AbfJQJK7 (ORCPT + 99 others); Thu, 17 Oct 2019 05:10:59 -0400 Received: from mail-vk1-f195.google.com ([209.85.221.195]:33506 "EHLO mail-vk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408407AbfJQJK7 (ORCPT ); Thu, 17 Oct 2019 05:10:59 -0400 Received: by mail-vk1-f195.google.com with SMTP id s21so351484vkm.0 for ; Thu, 17 Oct 2019 02:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=04hgzc9qmWLKJ4qr0kQdZsxTdQTI10306q/6E8gxvtc=; b=AqiK/AqAzagnlRkDP5D7TqpB+zWnEWzzdcE1+ogvr7ovwCaWkS1E6dkGJIs2VYkna0 HA4p49iuZmap9bwrWQDRVBDRirGN4C+C2Zd7u80MbHPDi5LXzDcZodamYr8fGpxOJG9+ cQZnATF4Ea0ykf2DI2LFkN6+oO+au47cMBmY/ah6FOd0Yu8NwLdx2gXP6PK0zgfk/FVl d5XrEkNmgDNqjUJTKWvbkMQHDg5i7+QZcSxqmZGGzma5dZtwr+ebc4iw4oBBUKILyGwe 5vi75QlYGSAmHTq0wmbKn0zm/loaA1/zPSK2vMr5cX+3JCAUa64xiho02j7x4kDXzF9s eq/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=04hgzc9qmWLKJ4qr0kQdZsxTdQTI10306q/6E8gxvtc=; b=jiL7NltEFo+hhy9Z26tAw1aEURJyuF985kmelIIq/et4Sen20MahRv1eT3FyHW1dK5 zPQDWa9pXOp3UfuAmQ1bresbkecLZnO69XXcEMnESq2OaG/IUIuKjKUH6FEugobSMI6V jzT9RDuBGJHKEVnCTjNKb6MLHXrLm9JYQfmBK7xHWooVGqxLTjOTDMeDZRL5yJFwjIjn 5k4vwE23B+KKcxhlzS2KcYREm51pHf9mH+2qNFqv2mXV5kB/CMO8VLQF05Zz6fz0oWBm CQXU2y9Trv6wxQnoqAFFtYQxiehVKOCvdhLkl7w1ZnnqBFNG4a7UiGHkvk9KiXhnWrN3 VqHg== X-Gm-Message-State: APjAAAWpVD7V7eIh6+nbdprxEXfo3lGYHMx+7piwMgVjYgLI/a2O9WQi A4yTEQmJnKvoL0gnW11hxcx7xetHn/rxJI0iGgqtvg== X-Received: by 2002:a1f:2f51:: with SMTP id v78mr1342917vkv.101.1571303457218; Thu, 17 Oct 2019 02:10:57 -0700 (PDT) MIME-Version: 1.0 References: <20190722193939.125578-1-dianders@chromium.org> <20190722193939.125578-2-dianders@chromium.org> In-Reply-To: From: Ulf Hansson Date: Thu, 17 Oct 2019 11:10:21 +0200 Message-ID: Subject: Re: [PATCH v2 1/2] mmc: core: Add sdio_trigger_replug() API To: Doug Anderson Cc: Kalle Valo , Adrian Hunter , Ganapathi Bhat , linux-wireless , Andreas Fenkart , Brian Norris , Amitkumar Karwar , "open list:ARM/Rockchip SoC..." , Wolfram Sang , Nishant Sarmukadam , netdev , Avri Altman , "linux-mmc@vger.kernel.org" , "David S. Miller" , Xinming Hu , Matthias Kaehlcke , Linux Kernel Mailing List , Thomas Gleixner , Kate Stewart Content-Type: text/plain; charset="UTF-8" Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Thu, 17 Oct 2019 at 02:22, Doug Anderson wrote: > > Hi, > > On Thu, Oct 10, 2019 at 7:11 AM Ulf Hansson wrote: > > > > On Mon, 22 Jul 2019 at 21:41, Douglas Anderson wrote: > > > > > > When using Marvell WiFi SDIO cards, it is not uncommon for Linux WiFi > > > driver to fully lose the communication channel to the firmware running > > > on the card. Presumably the firmware on the card has a bug or two in > > > it and occasionally crashes. > > > > > > The Marvell WiFi driver attempts to recover from this problem. > > > Specifically the driver has the function mwifiex_sdio_card_reset() > > > which is called when communcation problems are found. That function > > > attempts to reset the state of things by utilizing the mmc_hw_reset() > > > function. > > > > > > The current solution is a bit complex because the Marvell WiFi driver > > > needs to manually deinit and reinit the WiFi driver around the reset > > > call. This means it's going through a bunch of code paths that aren't > > > normally tested. However, complexity isn't our only problem. The > > > other (bigger) problem is that Marvell WiFi cards are often combo > > > WiFi/Bluetooth cards and Bluetooth runs on a second SDIO func. While > > > the WiFi driver knows that it should re-init its own state around the > > > mmc_hw_reset() call there is no good way to inform the Bluetooth > > > driver. That means that in Linux today when you reset the Marvell > > > WiFi driver you lose all Bluetooth communication. Doh! > > > > Thanks for a nice description to the problem! > > > > In principle it makes mmc_hw_reset() quite questionable to use for > > SDIO func drivers, at all. However, let's consider that for later. > > Yeah, unless you somehow knew that your card would only have one function. > > > > > One way to fix the above problems is to leverage a more standard way > > > to reset the Marvell WiFi card where we go through the same code paths > > > as card unplug and the card plug. In this patch we introduce a new > > > API call for doing just that: sdio_trigger_replug(). This API call > > > will trigger an unplug of the SDIO card followed by a plug of the > > > card. As part of this the card will be nicely reset. > > > > I have been thinking back and forth on this, exploring various > > options, perhaps adding some callbacks that the core could invoke to > > inform the SDIO func drivers of what is going on. > > > > Although, in the end this boils done to complexity and I think your > > approach is simply the most superior in regards to this. However, I > > think there is a few things that we can do to even further simply your > > approach, let me comment on the code below. > > Right. Unplugging / re-plugging is sorta gross / inelegant, but it is > definitely simpler and nice that it doesn't add so many new code > paths. For cases where you're just trying to re-init things with a > hammer it works pretty well. > > > > > Signed-off-by: Douglas Anderson > > > Reviewed-by: Matthias Kaehlcke > > > --- > > > > > > Changes in v2: > > > - s/routnine/routine (Brian Norris, Matthias Kaehlcke). > > > - s/contining/containing (Matthias Kaehlcke). > > > - Add Matthias Reviewed-by tag. > > > > > > drivers/mmc/core/core.c | 28 ++++++++++++++++++++++++++-- > > > drivers/mmc/core/sdio_io.c | 20 ++++++++++++++++++++ > > > include/linux/mmc/host.h | 15 ++++++++++++++- > > > include/linux/mmc/sdio_func.h | 2 ++ > > > 4 files changed, 62 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > > > index 221127324709..5da365b1fdb4 100644 > > > --- a/drivers/mmc/core/core.c > > > +++ b/drivers/mmc/core/core.c > > > @@ -2161,6 +2161,12 @@ int mmc_sw_reset(struct mmc_host *host) > > > } > > > EXPORT_SYMBOL(mmc_sw_reset); > > > > > > +void mmc_trigger_replug(struct mmc_host *host) > > > +{ > > > + host->trigger_replug_state = MMC_REPLUG_STATE_UNPLUG; > > > + _mmc_detect_change(host, 0, false); > > > +} > > > + > > > static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) > > > { > > > host->f_init = freq; > > > @@ -2214,6 +2220,11 @@ int _mmc_detect_card_removed(struct mmc_host *host) > > > if (!host->card || mmc_card_removed(host->card)) > > > return 1; > > > > > > + if (host->trigger_replug_state == MMC_REPLUG_STATE_UNPLUG) { > > > + mmc_card_set_removed(host->card); > > > + return 1; > > > > Do you really need to set state of the card to "removed"? > > > > If I understand correctly, what you need is to allow mmc_rescan() to > > run a second time, in particular for non removable cards. > > > > In that path, mmc_rescan should find the card being non-functional, > > thus it should remove it and then try to re-initialize it again. Etc. > > > > Do you want me to send a patch to show you what I mean!? > > If you don't mind, that would probably be easiest. I've totally > swapped out all of the implementation details of this from my brain > now, but if I saw a patch from you it would be easy for me to analyze > it and test it. Alright, I think I owe you that because of my slow review pase. :-) Patches are coming soon! Kind regards Uffe