Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: keith.busch@intel.com (Keith Busch)
Subject: A small concern on driver loading and unloading
Date: Sun, 18 May 2014 12:08:19 -0600 (MDT)	[thread overview]
Message-ID: <alpine.LRH.2.03.1405181200590.5666@AMR> (raw)
In-Reply-To: <CAOu78O3CJPyyzZECbbHYZtfLR8Qc99y=byMj6qg2KOp7xLj4gg@mail.gmail.com>

On Fri, 16 May 2014, Xuehua Chen wrote:
> Noticed something strange about the driver unloading and loading and
> would like to ask a question here.
>
> when driver is unloaded, nvme_shutdown_ctrl is called by nvme_remove.
>
> cc = (readl(&dev->bar->cc) & ~NVME_CC_SHN_MASK) | NVME_CC_SHN_NORMAL;
>       writel(cc, &dev->bar->cc);
>
> This set NVME_CC_SHN_NORMAL in CC.
>
> Then during driver loading,  nvme_disable_ctrl is called, which does this.
>
> u32 cc = readl(&dev->bar->cc);
>
> if (cc & NVME_CC_ENABLE)
>        writel(cc & ~NVME_CC_ENABLE, &dev->bar->cc);
>
>
> Checked the NVME spec 1.a  and didn't find it mention anywhere that
> controller will reset Shutdown Notification field after shutdown
> complete(please correct if this is incorrect). So the bits stay there.

That should be okay: we are about to clear the shutdown bits right after
controller reset completes and the CSTS.RDY bit is cleared.

> When loading the driver, the NVME_CC_SHN_NORMAL is written when
> disabling controller. This can be confusing. Why disabling the
> controller and do a shutdown at the same time.

We write whatever the previous CC values were but without CC.EN, so it
should not trigger another shutdown on the device.

> Maybe changing
> writel(cc & ~NVME_CC_ENABLE, &dev->bar->cc);
> to
> writel(cc & ~NVME_CC_ENABLE & ~NVME_CC_SHN_MASK , &dev->bar->cc);
> is safer.
>
> Also it seems that
> writel(0 , &dev->bar->cc);

I'm not sure we want to do either of those. The comment in the driver
above "nvme_disable_ctrl" indicates that changing the shutdown bits
might cause undesired behavior when the controller is "enabled" and in
a ready state.

> can be simpler and the effects are the same. Disabling controller
> reset controller registers including CC to default values. All fields
> of the CC will be gone any way.

  reply	other threads:[~2014-05-18 18:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-16 23:34 A small concern on driver loading and unloading Xuehua Chen
2014-05-18 18:08 ` Keith Busch [this message]
2014-05-18 20:59   ` Xuehua Chen
2014-05-18 23:58     ` Xuehua Chen
2014-05-19 22:38       ` Keith Busch

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=alpine.LRH.2.03.1405181200590.5666@AMR \
    --to=keith.busch@intel.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