Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2423484ybp; Thu, 10 Oct 2019 07:13:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQ4P7Emj2pQ4+SFTojLu/2aCSdjwxFzc6zcSm1u27k1GTTYjgSc/hrYvkY6Wm/vR9Nakw/ X-Received: by 2002:a50:9f66:: with SMTP id b93mr7921391edf.236.1570716837468; Thu, 10 Oct 2019 07:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570716837; cv=none; d=google.com; s=arc-20160816; b=iaK3DScoOILccxpt/Yw1Gc8sZh5pwbfSlcXUT+9rvjOLyYULRmFc64+XUFNB27EGEs YrticiJv5dz/AgHxxcm5TEkE5eoLhGa3ZaJQtPqOqENn4MVutNw3jdqVMZP0I+jB3w7P nwTInAiKy4TYRZV078ghi8TG1iV63WSMY6P2GoGUrQ4utUqixOHwts3n+kTP/QXeZvqC jQ9WWM+LEMvsUyTZQfYvHin2bUeEUoRZ44qV6bGwIgSp/4m+z4Y20+KskZt75His52cH vX8fU6mRQNt39bdFaIpOwyYVdS/G9aXiXBjRxoXCkk7qyl22nJOgFMF+9pFNN6ReJUxs Wm2w== 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=gA5F+RboE/pq+skSstsxaptbKJRogDAxspae1hZdrlw=; b=CNTe3NjemlO4jVQ3c1rJnsnG24qcke+GMrlFPw+gEUGESE2Ro0Jd8OxuljftRu9/D0 D3z8bhU85UwgfmbXa15aCiAw2E8ragQD4udeqNI/qns5zE8i21sZL4Hvsv53OzdpJkCm 3619nkR9cJ+rLN4OvBf/36pY8gHrQsV+vJGeTddi2j5KJkO0daCUrUehcVqealVRw6hQ mlMNPrkjWPeVpwujr1gydiRHxyLKB3pHvJJ0ZxR/0R9hSDpApnJDADM5LtnpQzJOGvQ7 TZJUEVKtb9o/JpAgYQ5Fliq5let1w/19SOcYH8JVX1QllA3JZ0uYccSZQNLn/Hy5qNYN A9fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="r/LIxHSW"; 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 c31si3395020edb.309.2019.10.10.07.13.21; Thu, 10 Oct 2019 07:13:57 -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="r/LIxHSW"; 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 S1726267AbfJJOLK (ORCPT + 99 others); Thu, 10 Oct 2019 10:11:10 -0400 Received: from mail-vs1-f68.google.com ([209.85.217.68]:39682 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbfJJOLK (ORCPT ); Thu, 10 Oct 2019 10:11:10 -0400 Received: by mail-vs1-f68.google.com with SMTP id y129so3987994vsc.6 for ; Thu, 10 Oct 2019 07:11:09 -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=gA5F+RboE/pq+skSstsxaptbKJRogDAxspae1hZdrlw=; b=r/LIxHSW9Hdinc+D0Q6ii6IgfODtEPA7DG+J3nI5G4dmTYbg0AE8kFbjz4uCjpx4tF QrLKKae+TVAOXVIm8ul1al4xJKrRBf4PHxbHxvzkzylS2dlImR5Ta9ZS8C8LOnIvCi8Z YT/DpA5D0z2tTsdrfvUKjoUGjElPqlkPMxF7J3/BaBDUsUQ+JXlh/jdLQqKjZ2y0T/SN LWPgem2QK0RVDs3oPjUFSY0OULoh/0Qonhqby6SdaZMcuFtH7hOoyOSaj2qJWVhkmJEq J6EH4NlsThcmjNlAM7KIo+XcHU1nBOjHN8nNi0cFMsvnIW5b1HABIkXZX3x+z3765HHV S6LQ== 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=gA5F+RboE/pq+skSstsxaptbKJRogDAxspae1hZdrlw=; b=GP6RTzj6fVpLahtl/qit5bUefJicoeDOPr1XBohLkOtRy3R7ykwiQ1q+YBY7KHF5ih ru7R4wrcTHB2gkOqMlb9h3vsJO0lbMPB4BkC9vMTrhvsJEYvd5Xz/cnvih51Hi80r8bA p1lWzaixQtglEu8jbV7d29wsKhws+eqeAxOPz7nSt61fZbhEXcEbJ3vIa1AUt8Gfs8JY PDs7Wl+f+w+czrHZVDv5Z3hOEfgGKdPlza3Bk5PRLlDq4bV6SehrqrQaXDPW+lzu6Pr9 x95MpGhxoNEmtcMUnekvcjLF+14UW/rhCi8hjhzm1Yj96S7bGTjp1u61utjMZNrpxbEv IqRA== X-Gm-Message-State: APjAAAWp+GGCtZIe2fn0Keur0AFoWCX9nyxkMFluokVAGOpJVfxp15QZ LFYEov4Onsyzh3SRxrXokkLyeWGeCFPJeNK87BSNKA== X-Received: by 2002:a67:ef89:: with SMTP id r9mr5830898vsp.200.1570716668861; Thu, 10 Oct 2019 07:11:08 -0700 (PDT) MIME-Version: 1.0 References: <20190722193939.125578-1-dianders@chromium.org> <20190722193939.125578-2-dianders@chromium.org> In-Reply-To: <20190722193939.125578-2-dianders@chromium.org> From: Ulf Hansson Date: Thu, 10 Oct 2019 16:10:32 +0200 Message-ID: Subject: Re: [PATCH v2 1/2] mmc: core: Add sdio_trigger_replug() API To: Douglas 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 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. > > 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. > > 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!? [...] Kind regards Uffe